Attribute Default Value vs (Actual) Value

Attribute Default Value vs (Actual) Value

Anonymous
Not applicable
693 Views
3 Replies
Message 1 of 4

Attribute Default Value vs (Actual) Value

Anonymous
Not applicable

I am unable to display an Attribute Definition Value. My code always returns the Default Value, but I need to display the actual value. What am I doing wrong? (See code snippet in the Attachment)

Thanks,

Joe.

 

 

0 Likes
Accepted solutions (1)
694 Views
3 Replies
Replies (3)
Message 2 of 4

_gile
Consultant
Consultant

Hi,

 

First these lines are useless:

attRef.Position = attDef.Position.TransformBy(blockRef.BlockTransform);
attRef.TextString = attDef.TextString;
attRef.Tag = attDef.Tag;

because this one already does all this:

attRef.SetAttributeFromBlock(attDef, blockRef.BlockTransform);

Now, about your question, I do not understand what you expect because the AttributeDefinition.TextString value is the default value.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thank you @_gile . This image shows what I am looking for:

TitleBlockAttributeValues.PNG

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

I found a solution to my problem here: https://forums.autodesk.com/t5/net/attributereference-textstring-problem/td-p/2267646

 

This code is returning the correct TextString values. I will adjust my code accordingly. Thanks.

        public void TestAttributeReference()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForWrite);
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt["TITLE_BLOCK_B"], OpenMode.ForRead);
                foreach (ObjectId oid in btr.GetBlockReferenceIds(true, false))
                {
                    BlockReference titleBlock = trans.GetObject(oid, OpenMode.ForRead) as BlockReference;
                    if (titleBlock == null) continue;
                    foreach (ObjectId attOid in titleBlock.AttributeCollection)
                    {
                        AttributeReference ar = (AttributeReference)trans.GetObject(attOid, OpenMode.ForWrite);
                        ed.WriteMessage(String.Format("{0} = {1}\n", ar.Tag, ar.TextString));
                        // ...
                    }
                }
                // trans.Commit();
            }
        }

 

0 Likes