Dynamic Block Array Spacing Property

Dynamic Block Array Spacing Property

knewsomeN8P59
Explorer Explorer
664 Views
9 Replies
Message 1 of 10

Dynamic Block Array Spacing Property

knewsomeN8P59
Explorer
Explorer

Hey guys,

I'm working in a dynamic block I'm controlling with a .NET script. I need to be able to adjust the column offset of my array action using this script. Is there a way to do this outside of the block editor, for instance by linking a user parameter in the quickcalc or something like that? I'm having issues accessing the array action properties with my code. Thanks

0 Likes
665 Views
9 Replies
Replies (9)
Message 2 of 10

norman.yuan
Mentor
Mentor

Depending on which parameter type the array action is based (i.e.  Linear/Polar/XY parameter), the DynamicProperty to be manipulated in the dynamic block reference is the parameter's name (if the parameter is XY, then there are 2 DynamicProperties default to "X Distaince1" and "Y Distance1"). Of course you may rename the parameter to a more meaningful name. To change the value of the parameter (thus the array's row/column count would change accordingly), you simply do:

using (var tran = TheDatabase.TransactionManager.StartTransaction())
{
    var blk=(BlockReference)tran.GetObject(theblkreferenceId, OpenMode.ForRead);
    foreach (DynamicBlockReferenceProperty prop in 
        blk.DynamicBlockReferencePropertyCollection)
    {
        if (prop.PropertyName.Equals("TheParameterName"))
        {
            prop.Value=100; // whatever distance it should be
            break; // If there is only one property to change (one dimension array)
        }
    }
    tran.Commit()
}

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 10

knewsomeN8P59
Explorer
Explorer

Sorry, I already have that functionality working; perhaps I wasn't clear in my description. I have it associated with a linear parameter, and I can edit the parameter so it creates 3 wheels or whatever. I need to be able to edit the spacing of the array. Right now, it is always set at 50", in the Array Action properties for "Column Offset" when you are within the block editor. I need to edit that column offset property, which changes that spacing from 50" to 60" or whatever, depending on user input. Hopefully that illustrates the issue better.

0 Likes
Message 4 of 10

ActivistInvestor
Mentor
Mentor

If you post your code then someone might be able to give you some advice on how to get it to work. 

0 Likes
Message 5 of 10

knewsomeN8P59
Explorer
Explorer

here's my code (yes it is written by Claude):

// ================================================================
//  Set array column offset (spacing between array elements)
// ================================================================
private static void SetArrayColumnOffset(BlockReference blockRef, Transaction tr, 
                                         string paramName, double offset)
{
    try
    {
        var blockDef = (BlockTableRecord)tr.GetObject(blockRef.DynamicBlockTableRecord, OpenMode.ForRead);
        var extDict = blockDef.ExtensionDictionary;

        if (extDict.IsNull) return;

        var extDictObj = (DBDictionary)tr.GetObject(extDict, OpenMode.ForRead);
        if (!extDictObj.Contains("ACAD_ENHANCEDBLOCK")) return;

        var enhancedBlockId = extDictObj.GetAt("ACAD_ENHANCEDBLOCK");
        var enhancedBlock = (DBObject)tr.GetObject(enhancedBlockId, OpenMode.ForRead);

        var enhancedDict = enhancedBlock.ExtensionDictionary;
        if (enhancedDict.IsNull) return;

        var enhancedDictObj = (DBDictionary)tr.GetObject(enhancedDict, OpenMode.ForRead);
        if (!enhancedDictObj.Contains("ACAD_BLOCKACTIONPARAM")) return;

        var blockActionParamId = enhancedDictObj.GetAt("ACAD_BLOCKACTIONPARAM");
        var blockActionParamDict = (DBDictionary)tr.GetObject(blockActionParamId, OpenMode.ForRead);

        foreach (var entry in blockActionParamDict)
        {
            var actionId = entry.Value;
            var action = tr.GetObject(actionId, OpenMode.ForRead) as DBObject;
            
            if (action == null) continue;

            // Try to find matching array action by iterating through properties
            var actionType = action.GetType();
            var nameProperty = actionType.GetProperty("Name", 
                System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public);
            
            if (nameProperty == null) continue;

            var actionName = nameProperty.GetValue(action) as string;
            if (string.Equals(actionName, paramName, StringComparison.OrdinalIgnoreCase))
            {
                // Found matching action — attempt to set ColumnOffset
                var offsetProperty = actionType.GetProperty("ColumnOffset",
                    System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Public);
                
                if (offsetProperty != null && offsetProperty.CanWrite)
                {
                    action.UpgradeOpen();
                    offsetProperty.SetValue(action, offset);
                    return;
                }
            }
        }
    }
    catch
    {
        // Silently fail — column offset modification is not critical
    }
}

 and here's how it is called:

SetArrayColumnOffset(blockRef, tr, "main_axles", ws);
SetArrayColumnOffset(blockRef, tr, "j_axles", wsJ);
SetArrayColumnOffset(blockRef, tr, "st_axles", wsSt);


Since it's written by Claude, I honestly don't know much of how it works. I'm a beginner in C# but don't know anything about integration with AutoCAD.

Here's a screenshot of what I need edited by this code:
Screenshot 2026-03-10 111559.png

Worst case I can just make it a manual edit with instructions for the user, as you are able to just edit it from the properties menu in the screenshot. But obviously if there's a way to do it with code, I'd like to include it in my trailer configurator program.



0 Likes
Message 6 of 10

_gile
Consultant
Consultant

Hi,

It looks like you (as Claude) are confusing block reference (BlockReference) and block definition (BlockTableRecord).

The column spacing of a dynamic array is defined in the block definition and cannot be set from a block reference and it cannot be edited by code because there's no API to create dynamic blocks.

Only the 'distance' parameter which the array is linked to is available from the block reference and accessible by code.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 10

knewsomeN8P59
Explorer
Explorer

so its not possible to edit the column offset? just want to make sure I'm reading this correctly.

0 Likes
Message 8 of 10

_gile
Consultant
Consultant

@knewsomeN8P59  a écrit :

so its not possible to edit the column offset? just want to make sure I'm reading this correctly.


No, it is not possible to edit the column offset with .NET



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 10

knewsomeN8P59
Explorer
Explorer

Is it possible with LISP?

0 Likes
Message 10 of 10

ActivistInvestor
Mentor
Mentor

It's not possible with LISP or .NET. It may be possible using the associative framework. It would involve creating an associative action that modifies the array column or row spacing when a dynamic property of the dynamic block reference changes. The Dynamic Property would effectively specify the row or column spacing. However, this solution is most definitely non-trivial and I've never attempted it. It may also be possible using a dimensional constraint rather than a dynamic property, but that is something that would require some investigation.

0 Likes