How to Insert a Dynamic Block and set Parameters (not Attributes) from C#

How to Insert a Dynamic Block and set Parameters (not Attributes) from C#

sanger779DZ
Enthusiast Enthusiast
473 Views
1 Reply
Message 1 of 2

How to Insert a Dynamic Block and set Parameters (not Attributes) from C#

sanger779DZ
Enthusiast
Enthusiast

If I have a dynamic block that contains several Point Parameters (see simplified example attached). How can I insert the block then set the values of the Point parameters in code (C# preferred not not mandatory). 

 

I have been able to determine how to set Attributes in code, but so far I have been unable to determine how to set Parameter values programmatically.

 

0 Likes
474 Views
1 Reply
Reply (1)
Message 2 of 2

sanger779DZ
Enthusiast
Enthusiast

Update: I was able to get a test program working to modify the block parameters, however, if I inspect the block after the code is run the Point Parameters will contain the modified values but the positions of the points in the drawing will not have moved. I tried executing REGEN and ATTSYNC afterwards but no change.

 

var doc = Application.DocumentManager.MdiActiveDocument;

var editor = doc.Editor;

using (var trans = doc.TransactionManager.StartTransaction())
{
    var allObjects = editor.SelectAll().Value;

    foreach (SelectedObject obj in allObjects)
    {
        var blockReference = trans.GetObject(obj.ObjectId, OpenMode.ForWrite) as BlockReference;

        if (blockReference == null)
            continue;

        if (!blockReference.IsDynamicBlock)
            continue;

        foreach (DynamicBlockReferenceProperty property in blockReference.DynamicBlockReferencePropertyCollection)
        {
            if (property.PropertyName == "START_POINT X")
            {
                property.Value = 1.0;
            }

            if (property.PropertyName == "START_POINT Y")
            {
                property.Value = 2.0;
            }
        }
    }

    trans.Commit();
}

 

0 Likes