I have a block table record that has a collection of attribute definitions on it, some of which are set up as constants. When I create a block reference based off of this block table record and go to create the attribute references corresponding to the attribute definitions, I cannot figure out how to specify the attribute references as constant. SetPropertiesFrom doesn't seem to do it. Any ideas?
Transaction trans = doc.TransactionManager.StartTransaction();
ObjectId idResult = ObjectId.Null;
try
{
// Get the model space block table
BlockTable bt = trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
BlockTableRecord btrInsert = trans.GetObject(idBlock, OpenMode.ForRead) as BlockTableRecord;
// Create the new block reference
BlockReference br = new BlockReference(pt3DPos, idBlock);
btr.AppendEntity(br);
trans.AddNewlyCreatedDBObject(br, true);
// Update the attributes on the block
foreach (ObjectId id in btr)
{
Entity ent = trans.GetObject(id, OpenMode.ForRead, false) as Entity;
if (ent is AttributeDefinition)
{
AttributeReference attRef = new AttributeReference();
AttributeDefinition attDef = ent as AttributeDefinition;
attRef.SetPropertiesFrom(attDef);
attRef.Position = new Point3d(attDef.Position.X + br.Position.X,
attDef.Position.Y + br.Position.Y,
attDef.Position.Z + br.Position.Z);
attRef.Height = attDef.Height;
attRef.Rotation = attDef.Rotation;
attRef.Tag = attDef.Tag;
attRef.Invisible = attDef.Invisible;
br.AttributeCollection.AppendAttribute(attRef);
trans.AddNewlyCreatedDBObject(attRef, true);
}
}
idResult = br.ObjectId;
trans.Commit();
}
finally {trans.Dispose(); }