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(attRef); trans.AddNewlyCreatedDBObject(attRef, true); } }
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
Maybe you can explain in detail what does it do?
It seems to me that this is not the best practice each time to change the number AttributeDefinition in the block.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
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.
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;
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Fantastic!!!! That's exactly what i was looking for!!!! Thank you!
***Edited for spelling
@Anonymous wrote:
Fatnastic!!!! That's exactly what i was looking for!!!! Thank you!
This is not fantasy - it is a minimal knowledge of the AutoCAD capabilities .
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
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
Would be good as well to add one line in your code
AttributeReference attRef = newAttributeReference();
attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);
blockRef.AttributeCollection.AppendAttribute(attRef);
// additional line:
attRef.AdjustAlignment(db);
trans.AddNewlyCreatedDBObject(attRef,
true);
~'J'~
Can't find what you're looking for? Ask the community or share your knowledge.