Cannot highlight attribute of block when select range using acedGetPoint and acedGetCorner in c++?
Assistant
In AutoCAD C++, when you use acedGetPoint or acedGetCorner to select a range of objects, you cannot directly access the attributes of individual objects within the selection set. These functions return a selection set, which is a collection of objects or blocks.
To access the attributes of a block within the selection set, you need to iterate through the objects in the selection set and check their object types. If an object is a block reference, you can cast it to AcDbBlockReference and then access its attributes.
User
how to highlight a subentity by using subentity path c++?
Assistant
In AutoCAD C++, you can highlight a subentity by using the subentity path. The subentity path specifies the entity and its subentity in the format of {entityHandle, subentityIndex}. Here's an example of how you can highlight a specific subentity:
In the above code, entityId is the ID of the parent entity that contains the subentity you want to highlight, and subentityIndex is the zero-based index of the subentity in the parent entity's subentity list.
The acedHighlight function is used to highlight an object or a subentity using its subentity path. The first argument of acedHighlight specifies the number of subentities to highlight (in this case, 1), and the second argument is a pointer to the array that contains the subentity path.
User
how to get the subentity path of the attribute subentity from id of attribute?
Assistant
To get the subentity path of an attribute subentity from the ID of the attribute in AutoCAD C++, you can use the getSubentPathsAtGsMarker function. Here's an example:
void getAttributeSubentityPath(AcDbObjectId attributeId)
{
AcDbEntity* pAttribute;
acdbOpenObject(pAttribute, attributeId, AcDb::kForRead);
AcDbAttribute* pAttributeObj = AcDbAttribute::cast(pAttribute);
if (pAttributeObj)
{
AcGePoint3d position = pAttributeObj->position();
AcDbObjectIdArray attributeSubentities;
acdbEntGetSubentPathsAtGsMarker(
pAttributeObj,
AcDb::kNullSubentType,
position,
asDblArray(pAttributeObj->normal()),
attributeSubentities
);
if (!attributeSubentities.isEmpty())
{
AcGeIntArray subentityPath = attributeSubentities[0].objectIds();
// subentityPath contains the subentity path of the attribute subentity
// The format of subentityPath is {entityHandle, subentityIndex}
}
}
pAttribute->close();
}
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here is an example of how you can iterate through the selection set and access the attributes of block references:
void accessBlockAttributes()
{
ads_name selectionSet;
if (acedSSGet(NULL, NULL, NULL, NULL, selectionSet) != RTNORM)
{
acutPrintf(_T("\nNo objects selected."));
return;
}
int numObjs;
if (acedSSLength(selectionSet, &numObjs) != RTNORM)
{
acutPrintf(_T("\nUnable to get selection set length."));
return;
}
for (int i = 0; i < numObjs; i++)
{
ads_name ent;
if (acedSSName(selectionSet, i, ent) != RTNORM)
{
acutPrintf(_T("\nUnable to get object with index %d."), i);
continue;
}
AcDbObjectId objId;
acdbGetObjectId(objId, ent);
AcDbEntity* pEntity;
acdbOpenObject(pEntity, objId, AcDb::kForRead);
if (pEntity->isA() == AcDbBlockReference::desc())
{
AcDbBlockReference* pBlockRef = AcDbBlockReference::cast(pEntity);
// Now you can access the attributes of the block reference
// using pBlockRef object.
// For example, you can use pBlockRef->setPosition() to set the position of the block reference.
}
pEntity->close();
}
}
Remember to include the necessary header files, such as "acedads.h" and "acdb.h", to use the required functions and objects.
Note that this code assumes you have already defined your own functions for working with selection sets, such as acedSSGet and acedSSLength, to get the selection set.
Remember to include the necessary header files, such as "acedads.h" and "acdb.h", to use the required functions and objects.
After highlighting the subentity, you might want to clear the highlight using acedHighlight(0, nullptr); when you no longer need it to be highlighted.
Note that the acedHighlight function works only when a viewport is active and the visual style supports highlighting. If you are using a custom visual style, you may need to override the highlight display logic to support subentity highlighting.
In the code above, attributeId is the ID of the attribute whose subentity path you want to obtain. We first open the attribute object using acdbOpenObject. Then we use acdbEntGetSubentPathsAtGsMarker to get the subentity paths at the attribute's position. Since an attribute has only one subentity, we can access it at index 0 of the attributeSubentities array. We can then extract the subentity path from attributeSubentities[0].objectIds().
Remember to include the necessary header files, such as "acdb.h" and "acestext.h", to use the required functions and objects.
Note that acdbEntGetSubentPathsAtGsMarker is only available in certain versions of AutoCAD (starting from AutoCAD 2013). If you are using an older version, you may need to find an alternative method to obtain the subentity path of the attribute.