如何访问 AutoCad 元素/从 Autocad 获取 xyz 坐标

How to access AutoCad elements / get xyz coordinates from Autocad

我正在寻找一种使用 Revit API 访问链接的 Autocad 文件的方法。我已经安装了 SnoopDB,这是一个巨大的帮助。

我发现 this 这也是向前迈出的又一步,但是我无法获取文件的点或行。

我进行了一些探索,发现我能够访问文件名,然后获取 cadlink 的哈希码,但在那之后,我不知道如何获取其中的 goemetry。

感谢任何帮助。

这是我目前的情况:

 UIApplication uiapp = commandData.Application;
 UIDocument uidoc = uiapp.ActiveUIDocument;
 Application app = uiapp.Application;
 Document doc = uidoc.Document;

Selection sel = uidoc.Selection;

            using (Transaction tx = new Transaction(doc))
            {
                try
                {
                    tx.Start("Tracing Cad");


                    Reference refer = sel.PickObject(ObjectType.Element, "Select a CAD Link");



                    Element elem = doc.GetElement(refer);
                    GeometryElement geoElem = elem.get_Geometry(new Options());

                    Debug.WriteLine("elem.Category.Name: " + elem.Category.Name); // can grab title of CAD


                    foreach (GeometryObject geoObj in geoElem)
                        {
                            GeometryInstance instance = geoObj as GeometryInstance;


                            foreach (GeometryObject instObj in instance.SymbolGeometry)
                            {

                                Debug.WriteLine("geoObj.GraphicsStyleId: " + geoObj.GraphicsStyleId);
                                Debug.WriteLine("geoObj.GetHashCode(): " + geoObj.GetHashCode()); // gets hashcode of selected cad link

                                if (instObj.GetType().Name == "PolyLine")
                                // if (instObj.GetType().Name == "GeometryInstance")
                                {


                                }
                                else
                                {
                                    Debug.WriteLine("there are no blocks found in this CAD File");
                                }
                            }
                        }

                    tx.Commit();
                } catch (Exception e )
                {

                    Debug.WriteLine(e.StackTrace);
                }

Revit API 不提供对链接的 CAD 文件内部结构的任何访问。

您所能做的就是执行一些 AutoCAD.NET 代码来读取 DWG 文件本身,前提是您可以访问 DWG 并且安装了 AutoCAD。

Building Coder 分享了一些示例,展示了如何 launch AutoCAD within a Revit add-in