Block Attribute value

Block Attribute value

cihanbaki2147
Contributor Contributor
1,116 Views
4 Replies
Message 1 of 5

Block Attribute value

cihanbaki2147
Contributor
Contributor

I want to put the data in the block inside the block into a variable and use it in mathematical operations.

0 Likes
Accepted solutions (1)
1,117 Views
4 Replies
Replies (4)
Message 2 of 5

fieldguy
Advisor
Advisor

What have you tried so far?  There are several examples in this forum

https://forums.autodesk.com/t5/net/change-block-attribute/m-p/2996912#M23313

 

 

0 Likes
Message 3 of 5

cihanbaki2147
Contributor
Contributor
You could share the c # code.

 

0 Likes
Message 4 of 5

fieldguy
Advisor
Advisor

You could convert it yourself and learn something along the way?

http://converter.telerik.com/

0 Likes
Message 5 of 5

stefan.hofer
Advocate
Advocate
Accepted solution

Read Attributes...

//using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
private void GetAttributeValues()
{
    Document doc = acApp.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    TypedValue[] acTypValAr = new TypedValue[1];
    acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0);
    SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);

    using (Transaction acTrans = db.TransactionManager.StartTransaction())
    {
        PromptSelectionResult acSSPrompt;

        acSSPrompt = ed.SelectAll(acSelFtr);

        if (acSSPrompt.Status == PromptStatus.OK)
        {
            SelectionSet acSSet = acSSPrompt.Value;
            foreach (SelectedObject acSSObj in acSSet)
            {
                if (acSSObj != null)
                {
                    BlockReference br = (BlockReference)acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead);
                    if (br != null)
                    {
                        AttributeCollection attCol = br.AttributeCollection;
                        foreach (ObjectId attId in attCol)
                        {
                            AttributeReference attRef = (AttributeReference)acTrans.GetObject(attId, OpenMode.ForRead);
                            ed.WriteMessage("Attribute Tag: " + attRef.Tag + "   |   Attribute Text: " + attRef.TextString + "\n");
                        }
                    }
                }
            }
        }
        acTrans.Commit();
    }
}

 

For dynamic blocks properties...

            SelectionSet acSSet = acSSPrompt.Value;
            foreach (SelectedObject acSSObj in acSSet)
            {
                if (acSSObj != null)
                {
                    BlockReference br = (BlockReference)acTrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead);
                    if (br != null && br.IsDynamicBlock)
                    {
                        DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection;
                        foreach (DynamicBlockReferenceProperty prop in pc)
                        {
                            ed.WriteMessage("Property name: " + prop.PropertyName + "   |   Property value: " + prop.Value + "\n");
                        }
                    }
                }
            }
0 Likes