WPF应用程序读取acad3d

本文关键字:acad3d 读取 应用程序 WPF | 更新日期: 2023-09-27 18:07:13

我正在制作一个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 solid = (Acad3DSolid)entity;这给了我3DSolid,但我找不到任何类似solid的东西。宽度之类的

有人知道吗?

谢谢。

WPF应用程序读取acad3d

我想你需要GetBoundingBox函数