Message 1 of 3
How to Preserve Constat Attributes on BlockReference

Not applicable
02-17-2010
01:21 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am creating a new blockreference object based on the block definition already present in the BlockTable.
BlockReference br = new BlockReference(pt, bdId); //where bdId is the objectId of the block
I am then cycling through the ObjectIds in the BlockTableRecord and if they are AttributeDefinitions then I attach them to the new blockreference:
BlockTableRecord bd = (BlockTableRecord)tr.GetObject(bdId, OpenMode.ForRead);
foreach (ObjectId attId in bd)
{
//Open the Object for reading
Entity ent = (Entity)tr.GetObject(attId, OpenMode.ForRead);
//Check whether it is an Attribute or not
if (ent is AttributeDefinition)
{
//Get the Definition
AttributeDefinition ad = (AttributeDefinition)ent;
//Set up a new attribute reference
AttributeReference ar = new AttributeReference();
//Add the attribute definition to the attribute reference
ar.SetAttributeFromBlock(ad, br.BlockTransform);
//Add the Attribute reference to the new block
br.AttributeCollection.AppendAttribute(ar);
//Use the transaction to commit the changes
tr.AddNewlyCreatedDBObject(ar, true);
} //End If ent
} //End For Loop
Question is: Each of the blocks has 2 attributes that are defined as Constants on the original BlockTableRecord, but when I use the code above to copy them over to the new blockreference they are no longer Constants. How do I copy them over and retain the original status?
BlockReference br = new BlockReference(pt, bdId); //where bdId is the objectId of the block
I am then cycling through the ObjectIds in the BlockTableRecord and if they are AttributeDefinitions then I attach them to the new blockreference:
BlockTableRecord bd = (BlockTableRecord)tr.GetObject(bdId, OpenMode.ForRead);
foreach (ObjectId attId in bd)
{
//Open the Object for reading
Entity ent = (Entity)tr.GetObject(attId, OpenMode.ForRead);
//Check whether it is an Attribute or not
if (ent is AttributeDefinition)
{
//Get the Definition
AttributeDefinition ad = (AttributeDefinition)ent;
//Set up a new attribute reference
AttributeReference ar = new AttributeReference();
//Add the attribute definition to the attribute reference
ar.SetAttributeFromBlock(ad, br.BlockTransform);
//Add the Attribute reference to the new block
br.AttributeCollection.AppendAttribute(ar);
//Use the transaction to commit the changes
tr.AddNewlyCreatedDBObject(ar, true);
} //End If ent
} //End For Loop
Question is: Each of the blocks has 2 attributes that are defined as Constants on the original BlockTableRecord, but when I use the code above to copy them over to the new blockreference they are no longer Constants. How do I copy them over and retain the original status?