通过C#Com互操作性访问AutoCad动态块'块属性表'
问题描述:
我正在使用AutoCAD 2017 Professional与ObjectARX_2017_Win_64。我试图查询&使用COM Interoperability修改动态块的“块属性表”属性,但没有成功。该表包含名称为Columns和包含数据的多行。数据的类型是String和Integer。 任何帮助将受到欢迎在“做东西”部分。通过C#Com互操作性访问AutoCad动态块'块属性表'
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
}
}
}
答
据我所知,你只能得到或设置属性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
}
}
感谢gileCAD。这太遗憾了。块属性表似乎是存储自定义表格数据的理想之地。看起来我必须恢复解析一个多行属性,而不是500个参数。我会离开这个线程以防万一有人能把兔子从帽子里拿出来。 – Mark