0

I'm making a WPF application where I wanna open Autocad files and get the dimentions (width, hight, etc) of the 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.

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; This gives me the 3DSolid, but I can't find anything like solid.Width or something.

Does anyone have any idea?

Thank you.

1 Answers1

0

I think you want the function GetBoundingBox.

Joel Lucsy
  • 8,520
  • 1
  • 29
  • 35
  • like Acad3DSolid solid = (Acad3DSolid)entity; object x; object y; solid.GetBoundingBox(out x, out y); MessageBox.Show(x.ToString());? – Pellerossa Apr 03 '13 at 20:53
  • You can cast those X and Y to double[] (they are 3 dimensional points representing the minimum and maximum corners of the bounding box) – Daniel Möller Apr 04 '13 at 11:31