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

How to Preserve Constat Attributes on BlockReference

2 REPLIES 2
Reply
Message 1 of 3
LialAtArnold
295 Views, 2 Replies

How to Preserve Constat Attributes on BlockReference

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?
2 REPLIES 2
Message 2 of 3
Anonymous
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?
Message 3 of 3
LialAtArnold
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

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