Community
Dynamic Blocks Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
Reply
Message 1 of 2
sanger779DZ
142 Views, 1 Reply

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

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.

 

1 REPLY 1
Message 2 of 2
sanger779DZ
in reply to: sanger779DZ

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();
}

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


”Boost