Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

layer attributes for block references

Anonymous

layer attributes for block references

Anonymous
Not applicable

I create blocks / references with my plugins. all blocks have the same layer, for example "layer for block". But if I open the block, I would like to have another layer for the polylines.

 

How do I set a layer for a created line in block reference? can someone send me a code example?

 

basicaly i want to know how the layer is set in property panel after double click (open block reference) on polyline

 

0 Likes
Reply
Accepted solutions (1)
904 Views
1 Reply
Reply (1)

ambrosl
Autodesk
Autodesk
Accepted solution

Objects in a block reference inherit most of their properties from the way they are defined in a block table record, with the exception of certain types of attribute definitions/references.  So for example, if a polyline is assigned layer "123" when the block is created, the line will be drawn using the properties of layer "123" for all instances of a specific block when inserted into a drawing.  It is possible to have objects within a block inherit the general properties of the block reference, this is done by assigning the objects within a block the value of ByBlock for a particular object property or drawing objects on Layer 0 before adding them to a block.

BlkRef_ByBlock_ByLayer.png


If you want to change the layer in which a polyline is drawn on for all instances of a block inserted into a drawing, you would open that particular block table record for reach and then iterate to find the polyline object and then modify that object.

The following is a basic code sample that should get you started with how to change the layer of a entity in a block definition using ObjectARX:

 

// Get the current database
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();

// Open the Block Table for read-only
AcDbBlockTable *pBlockTable;
pDb->getSymbolTable(pBlockTable, AcDb::kForRead);

// Get the Model Space block
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt("MyBlockDef", pBlockTableRecord, AcDb::kForWrite);
pBlockTable->close();

// Create a new block iterator that will be used to
// step through each object in the current space
AcDbBlockTableRecordIterator *pItr;
pBlockTableRecord->newIterator(pItr);
	
// Create a variable AcDbEntity type which is a generic 
// object to represent a Line, Circle, Arc, among other objects
AcDbEntity *pEnt;

// Step through each object in the block
for (pItr->start(); !pItr->done(); pItr->step())
{
    // Use pEnt->isA()->name() to look for a specific object type

    // Get the entity and open it for write
    pItr->getEntity(pEnt, AcDb::kForWrite);

    // Display the class name for the entity before
    pEnt->setLayer("123");
    pEnt->close();
}
	
// Close the current space object
pBlockTableRecord->close();

// Remove the block iterator object from memory
delete pItr;

 



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation