.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hey everyone,
I'm trying to add an attribute to an entity, however it seems that the AttributeDefinition requires a Point3d and as such appear in my modelspace. I don't want this, i just wanted it to appear as an attribute with a value when i click on my entity, is there any way of making it so that i does not add into modelspace?
Cheers
Vince
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
for (int i = 0; i < prSelectionResult.Value.Count; i++)
{
// Get the entity the user had selected
Entity ent = (Entity)trans.GetObject(prSelectionResult.Value[i] .ObjectId, OpenMode.ForWrite);
if (ent.GetType() == typeof(BlockReference))
{
// Add attribute to layer
BlockReference blockRef = (BlockReference)ent;
AttributeDefinition attDef = new AttributeDefinition(new Point3d(0d, 0d, 0d), "World, I'm an attribute!", "Hello", "", db.Textstyle);
// Add the attribute to to the BlockTrableRecord of the blockdefinition of the selected block
ObjectId btrId = blockRef.BlockTableRecord;
BlockTableRecord btrBlock = (BlockTableRecord)trans.GetObject(btrId, OpenMode.ForWrite);
btrBlock.AppendEntity(attDef);
trans.AddNewlyCreatedDBObject(attDef, true);
// Add the AttributeReference to the BlockReference
AttributeReference attRef = new AttributeReference();
attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);
blockRef.AttributeCollection.AppendAttribute(attRe f);
trans.AddNewlyCreatedDBObject(attRef, true);
}
}
Solved! Go to Solution.
Re: Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hello,
I was searching through other posts and examples in the forums and came across this. What it does is add an attribute to an entity, in this case:
Hello: World, I'm an Attribute!
As you can see in the attached photo however, the attribute is also placed into modelspace as per the lines:
BlockReference blockRef = (BlockReference)ent;
AttributeDefinition attDef = new AttributeDefinition(new Point3d(0d, 0d, 0d), "World, I'm an Attribute!", "Hello", "", db.Textstyle);What i'm trying to do is avoid having the attribute placed in my modelspace, just in the entity.
Re: Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Do I understand correctly that you do not want to attributes were visible on the screen (model space)?
Then it is sufficient to set their property Invisible to true or property Visible to false.
Property Visible is common entity property, but Invisible is only AttributeReference (and AttributeDefinition) property.
attdef.Invisible = true;
attref.Invisible = true;
Re: Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Fantastic!!!! That's exactly what i was looking for!!!! Thank you!
***Edited for spelling
Re: Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I've just begun working with attributes and am very new to the AutoCAD API in general so I was not aware of this property. Although it may seem like minimal knowledge to some, to me it's quite new and something I will definetly remember as I continue ![]()
Cheers
Vince
Re: Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Would be good as well to add one line in your code
AttributeReference attRef = newAttributeReference();
attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);
blockRef.AttributeCollection.AppendAttribute(attRe
// additional line:
attRef.AdjustAlignment(db);
trans.AddNewlyCreatedDBObject(attRef,
true);
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: Issues adding an Attribute to an Entity
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks Hallex, will do!



