
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all,
I'm back so soon with more problems! 😛
I change a block's attributes programmatically using this helper function I created:
private void UpdateAttributes(Database database, Detail det) { using (Transaction tr = database.TransactionManager.StartTransaction()) { //Grab the BlockReference the detail refers to. BlockReference block = (BlockReference)tr.GetObject(det.ObjectId, OpenMode.ForRead); //Iterate over the Attribute ids. foreach (ObjectId attributeId in block.AttributeCollection) { //Get the current AttributeReference. AttributeReference acAttribute = (AttributeReference)tr.GetObject(attributeId, OpenMode.ForWrite); //Find the matching attribute. foreach (DetailAttribute tmpAttr in det.Attributes) { if (tmpAttr.TagString.Equals(acAttribute.Tag, StringComparison.OrdinalIgnoreCase)) { //The attributes match, copy the value of the detail. Editor ed = AcAp::Application.DocumentManager.MdiActiveDocument.Editor; acAttribute.TextString = tmpAttr.TextString; } } } tr.Commit(); //Faster than commiting, no changes were made. } }
You can ignore the Detail and DetailAttribute objects as they are also user-defined. Also note that this function expects the database to be currently open for working on.
Everything in this function works fine, but there is a strange quirk that becomes noticeable only when I use this function to edit an attribute that has its "Invisible" property set to "No".
Below, is the original block that is edited via this function:
As you can see, the block has a number with 4 digits (for our purposes, call this the Block Number). |
Next, is the block after it is the function executes, and the attribute is changes:
In this picture, the Block Number was changed so that it did not include the leading zero. However, notice that the the Block Number attribute remained in the same exact position! The position is measured from the bottom-left corner of the text, and the attribute is justified to "Middle" |
In addition to the attribute's text being justified to middle, the "Lock Position" property is set to "No"
The text will auto-correct its position, however, if I move the block to a new location. Or if I manually type in the Block Number (changing it to something else, then changing to "210").
Also, this is not a REGEN issue, as this command will not fix the location.
So, in short, I do not believe this is an error with the block's settings. It appears something internal is happening or perhaps I need to do more inside my code.
Also, I did attempt to use one of AttributeReference's 2 methods:
AttributeReference.UpdateMTextAttribute
However, this resulted in an exception (my assumption is because my drawing is being modified in-memory and not in the AutoCAD editor.
If you've got any advice, I'm up for it!
Thanks much,
-Nicholas
Solved! Go to Solution.