.NET

Reply
Valued Contributor
LialAtArnold
Posts: 82
Registered: ‎11-29-2006
Message 1 of 3 (175 Views)

How to Preserve Constat Attributes on BlockReference

175 Views, 2 Replies
02-17-2010 01:21 PM
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?
*Tony Tanzillo
Message 2 of 3 (175 Views)

Re: How to Preserve Constat Attributes on BlockReference

02-17-2010 02:35 PM in reply to: LialAtArnold
You just skip the constant attributes.

They aren't attached to the insertion, they're stored in the block's definition.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message
news:6339139@discussion.autodesk.com...
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?
Valued Contributor
LialAtArnold
Posts: 82
Registered: ‎11-29-2006
Message 3 of 3 (175 Views)

Re: How to Preserve Constat Attributes on BlockReference

02-17-2010 02:51 PM in reply to: LialAtArnold
Tony,
I see the "Constant" method on the AttributeDefinition and can filter them out now.
(I was looking at the AttributeReference and it's IsConstant method).

But what I really want to do is set the new BlockReference up the same way the original is.
That is, copy the two Constant attributes onto the new block reference and then set them as Constant too.

I don't see a method that allows me to do that.


Wait!
It's starting to come clear now. You mean -
The Constants are on the definition by default so by creating an instance of them and attaching them I am actually ending up with two versions of the same attribute. One is Constant and the one I created is not.

Therefore, if I skip the Constants in the code, I still end up with them! Edited by: lial.williams@arnold.af.mil on Feb 17, 2010 4:52 PM

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community