我正在制作一个 WPF 应用程序,我想在其中打开 Autocad 文件并获取 3Dsolids 的尺寸(宽度、高度等)。
经过几天的麻烦,我终于设法打开文件并阅读它,现在唯一的问题是我无法获得 3D 实体的尺寸。
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private static IAcadApplication oAcadApp = null;
private static string sAcadID = "AutoCAD.Application.18";
AcadDocument doc;
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
try //get a running AutoCAD instance if avaialbale
{
oAcadApp = (IAcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject(sAcadID);
doc = oAcadApp.Documents.Open(@"C:\Users\Bernard\Desktop\Drawing2.dwg", false);
oAcadApp.Visible = true;
}
catch (System.Exception) //none found so start a new instance
{
System.Type AcadProg = System.Type.GetTypeFromProgID(sAcadID);
oAcadApp = (IAcadApplication)System.Activator.CreateInstance(AcadProg);
if (this.IsLoaded)
{
doc = oAcadApp.Documents.Open(@"C:\Users\Bernard\Desktop\Drawing2.dwg", false);
oAcadApp.Visible = true;
}
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
AcadModelSpace modelspace = doc.ModelSpace;
MessageBox.Show("aantal objecten = " + modelspace.Count + "");
for (int i = 0; i < modelspace.Count; i++)
{
AcadEntity entity = modelspace.Item(i);
MessageBox.Show("objecttype = " + entity.EntityType);
if (entity.EntityType == 3)
{
Acad3DSolid solid = (Acad3DSolid)entity;
}
}
}
}
}
Acad3DSolid 实体 = (Acad3DSolid) 实体;这给了我 3DSolid,但我找不到像 solid.Width 之类的东西。
有谁有想法吗?
谢谢你。