简体   繁体   English

WPF应用程序阅读ACAD 3D

[英]WPF application reading ACAD 3D

I'm making a WPF application where I wanna open Autocad files and get the dimentions (width, hight, etc) of the 3Dsolids. 我正在制作WPF应用程序,我想在其中打开Autocad文件并获取3Dsolids的尺寸(宽度,高度等)。

After a few days of trouble I finaly managed to open the file and read it, the only problem now is that I can't get the dimentions of the 3D Solids. 经过几天的麻烦,我最终设法打开文件并读取了文件,现在唯一的问题是我无法获得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; Acad3DSolid实体=(Acad3DSolid)实体; This gives me the 3DSolid, but I can't find anything like solid.Width or something. 这给了我3DSolid,但是我找不到诸如solid.Width之类的东西。

Does anyone have any idea? 有人有什么主意吗?

Thank you. 谢谢。

我认为您需要功能GetBoundingBox。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM