Set AttributeReference as Constant?

Set AttributeReference as Constant?

Anonymous
Not applicable
644 Views
2 Replies
Message 1 of 3

Set AttributeReference as Constant?

Anonymous
Not applicable
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(); }
0 Likes
645 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
There are no attribute references for constant
attribute definitions. Constant attributes are
essentially like text in the block's definition.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com

wrote in message news:4956361@discussion.autodesk.com...
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(); }
0 Likes
Message 3 of 3

Anonymous
Not applicable
Ok, but It is not possible to set the visible attribute to hide the text.
0 Likes