.NET

Reply
Active Member
brianroth
Posts: 10
Registered: ‎05-31-2005
Message 1 of 3 (175 Views)

Set AttributeReference as Constant?

175 Views, 2 Replies
09-14-2005 10:51 AM
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(); }
*Tony Tanzillo
Message 2 of 3 (175 Views)

Re: Set AttributeReference as Constant?

09-14-2005 08:15 PM in reply to: brianroth
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(); }
Contributor
mabe2k11
Posts: 24
Registered: ‎03-14-2006
Message 3 of 3 (175 Views)

Re: Set AttributeReference as Constant?

05-22-2006 06:55 AM in reply to: brianroth
Ok, but It is not possible to set the visible attribute to hide the text.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.