.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Set AttributeReference as Constant?

2 REPLIES 2
Reply
Message 1 of 3
brianroth
358 Views, 2 Replies

Set AttributeReference as Constant?

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(); }
2 REPLIES 2
Message 2 of 3
Anonymous
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(); }
Message 3 of 3
mabe2k11
in reply to: brianroth

Ok, but It is not possible to set the visible attribute to hide the text.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost