访问AutoCad动态块'块属性表'通过C#Com互操作性

时间:2017-03-01 01:18:53

标签: c# .net com interop autocad

我正在使用带有ObjectARX_2017_Win_64的AutoCAD 2017 Professional。我正在尝试查询&修改"块属性表"使用COM互操作性的动态块的属性没有成功。该表包含名称标题列和包含数据的多行。数据的类型为String和Integer。 任何帮助都会受到欢迎,并且会在#34; Do Stuff"部分。

    using Autodesk.AutoCAD.Interop;
    using Autodesk.AutoCAD.Interop.Common;
    using System.Runtime.InteropServices;
    .
    .
    .
    public void DrawLayout(boards board, FormAutocad frmAutoCad)
    {
        double[] insertpoint = new double[] { 0, IP_CONNECTOR_Y, 0 };
        if (AcadLinkStart(frmAutoCad))
        {
            destdwg = acadApp.ActiveDocument;
            // Get all the standard blocks from BLOCK_REF and place in destination drawing
            CopyStandardBlocksToDrawing();
            AcadBlockReference o = destdwg.ModelSpace.InsertBlock(insertpoint, "041_CHASSIS", 1.0, 1.0, 1.0, 0.0); // Ensure blocks are loaded in CopyStandardBlocksToDrawing

            Object[] attribs = o.GetAttributes() as object[];
            Object[] props = o.GetDynamicBlockProperties() as object[];
            foreach (var prop in props.OfType<AcadDynamicBlockReferenceProperty>())
            {
            if (prop.PropertyName == "My_Table")
            {
                 // Do Stuff
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

据我所知,您只能获取或设置与表中行索引相对应的属性Value。

    Object[] props = o.GetDynamicBlockProperties();
    foreach (var prop in props.OfType<AcadDynamicBlockReferenceProperty>())
    {
        if (prop.PropertyName == "My_Table")
        {
            if (prop.Value != 0)
                prop.Value = (short)0; // <- reset to the first row
        }
    }