.NET 与 AutoCAD 的接口 - SetXData 错误
我尝试在 AutoCAD 2007 COM 对象上使用 SetXData 方法,但它抛出错误。
<代码> 示例测试:
public AcadEntity getAcadEntity()
{
/// ... Basic code to return a single AutoCAD entity...
}
private void btnTagItem_Click(object sender, EventArgs e)
{
AcadEntity ent = getAcadEntity();
short[] xDataType;
string[] xDataStrings;
DrawingXData xData = new DrawingXData();
xData.field1 = "Some Text Goes here";
xData.field2 = 1;
xData.field3 = 100;
xData.field4 = 1509.2;
xData.field5 = "More Text";
BuildXData("AutoCad_App_Name", xData, out xDataType, out xDataStrings);
ent.SetXData(xDataType, xDataStrings); // This line crashes.
}
private void BuildXData(string applicationName, DrawingXData xData,
out short[] xDataType, out string[] xDataStrings)
{
List<short> dataTypes = new List<short>();
List<string> dataStrings = new List<string>();
/// Code types...
/// 1000 == String up to 255 bytes
/// 1001 == Application Name
// Set Applicaiton Name
dataTypes.Add(1001); dataStrings.Add(applicationName);
// Set Application Data
dataTypes.Add(1000); dataStrings.Add(xData.field1.ToString());
dataTypes.Add(1000); dataStrings.Add(xData.field2.ToString());
dataTypes.Add(1000); dataStrings.Add(xData.field3.ToString());
dataTypes.Add(1000); dataStrings.Add(xData.field4.ToString());
dataTypes.Add(1000); dataStrings.Add(xData.field5.ToString());
// ... etc.
xDataType = dataTypes.ToArray();
xDataStrings = dataStrings.ToArray();
}
我得到的错误是“SetXData 方法中的参数数据无效”。
错误代码(如果这对任何人有帮助的话)是-2145320939。
我发布此帖子的主要原因是,相同的代码在非常旧的 VB6 应用程序中运行得很好。我很困惑。
I am trying to use the SetXData method on the AutoCAD 2007 COM object, but it is throwing errors.
Example Test:
public AcadEntity getAcadEntity()
{
/// ... Basic code to return a single AutoCAD entity...
}
private void btnTagItem_Click(object sender, EventArgs e)
{
AcadEntity ent = getAcadEntity();
short[] xDataType;
string[] xDataStrings;
DrawingXData xData = new DrawingXData();
xData.field1 = "Some Text Goes here";
xData.field2 = 1;
xData.field3 = 100;
xData.field4 = 1509.2;
xData.field5 = "More Text";
BuildXData("AutoCad_App_Name", xData, out xDataType, out xDataStrings);
ent.SetXData(xDataType, xDataStrings); // This line crashes.
}
private void BuildXData(string applicationName, DrawingXData xData,
out short[] xDataType, out string[] xDataStrings)
{
List<short> dataTypes = new List<short>();
List<string> dataStrings = new List<string>();
/// Code types...
/// 1000 == String up to 255 bytes
/// 1001 == Application Name
// Set Applicaiton Name
dataTypes.Add(1001); dataStrings.Add(applicationName);
// Set Application Data
dataTypes.Add(1000); dataStrings.Add(xData.field1.ToString());
dataTypes.Add(1000); dataStrings.Add(xData.field2.ToString());
dataTypes.Add(1000); dataStrings.Add(xData.field3.ToString());
dataTypes.Add(1000); dataStrings.Add(xData.field4.ToString());
dataTypes.Add(1000); dataStrings.Add(xData.field5.ToString());
// ... etc.
xDataType = dataTypes.ToArray();
xDataStrings = dataStrings.ToArray();
}
The error I get is "Invalid argument data in SetXData method".
The error code (if this helps anyone) is -2145320939.
The main reason I'm posting is because the same code in a very old VB6 application works just fine. I'm stumped.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误消息告诉您对方法 SetXData 的调用中的一种或两种数据类型不正确。
我对您想要做的事情没有个人经验,但我建议将 xDataStrings 的数据类型更改为对象数组:
查看 autodesk 论坛上的此帖子。示例 .NET 代码已发布,可能会对您有所帮助。
The error message is telling you one or both the data types in your call to method SetXData is not correct.
I don't have personal experience with what you're trying to do but I suggest changing the data type of xDataStrings to an array of objects:
Check out this thread on the autodesk forums. Sample .NET code is posted which may help you.