Retrieve DWG polyline failed. turn out to be lines, arcs, and even solids

Hi fellows!
I’m trying to retrieve polyline from a dwg file and my question is I can only retrieve polyline constructed by “lines”, the arcs are missed. Besides, sometimes I even retrieved solids and I didn’t know where did the solids came from. Is there something wrong with my polyline? Does anyone encountered same question before? Thanks a lot.

Hard to see exactly what the issue is without one of the DWGs in question; perhaps build a similarly constructed polyline to the one you want to work with in a new dwg, import that into a new RVT and post the result you’re seeing along with the rvt and the .dyn you’re using but getting bad results with.

@jacob.small
Here is the PolyLine I draw for test:


Here is what I retrieved in Dynamo, I don’t know why there are solids and why my dwg PolyLine is splited to three arc and one polyline?:

I finally get “part” PolyLine:

Here is my Zero-Touch code:

public static PolyCurve GetRailSection()
        {
            UIDocument uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
            Document doc = uidoc.Document;
            TransactionManager.Instance.EnsureInTransaction(doc);
            SubTransaction getRailPC = new SubTransaction(doc);
            getRailPC.Start();
            IList<ViewFamilyType> types = null;
            using (var collector = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)))
            {
                types = collector.Cast<ViewFamilyType>().ToList();
            }
            var viewFamilyType = types.FirstOrDefault(x => x.ViewFamily == ViewFamily.ThreeDimensional);
            View3D view3D = View3D.CreateIsometric(doc, viewFamilyType.Id);
            ElementId id = null;
            try
            {
                doc.Link(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\test.dwg", new DWGImportOptions(), view3D, out id);
            }
            catch (ArgumentException)
            {
                MessageBox.Show("test.dwg losted");
                return null;
            }
            GeometryObject gb = GetGeometryObject(uidoc.Document.GetElement(id).get_Geometry(new Options()), null, null);
            getRailPC.RollBack();
            TransactionManager.Instance.TransactionTaskDone();
            return gb.Convert() as PolyCurve;
        }

private static GeometryObject GetGeometryObject(GeometryElement geometryElement, XYZ ntrans, XYZ nurbStart)
        {
            foreach (var geob in geometryElement)
            {
                var geomInstance = geob as GeometryInstance;
                var geomElement = geob as GeometryElement;

                if (geomInstance != null)
                {
                    var innergeomem = geomInstance.GetInstanceGeometry();
                    return GetGeometryObject(innergeomem, ntrans, nurbStart);
                }
                else if (geomElement != null)
                {
                    return GetGeometryObject(geometryElement, ntrans, nurbStart);
                }
                else
                {
                    PolyLine pl = geob as PolyLine;
                    if (pl != null)
                        return pl;
                }
            }
            return null;
        }

My purpose is to retrieve the PolyLine as a whole, return only one PolyCurve

To get polyline fron dwg. You can use “BriMohareb_2023” pakege. It has node to get geometry from dwg file. That if you need to het the geometry from open file. If the cad file is linked to revit file you can use bimorph pakege. It has node to get geometry from link cad file.

Looks like bimorph can only import “segments”, I want to import the PolyLine as a whole.
1

Hi @805164062

you can use “BriMohareb_2023” to get polyline

here you need to open Autocad at the same time you run the revit dynamo

1 Like

I’m restricted to Revit 2018 :rofl:

:astonished: :astonished:

Thank you again :handshake:

1 Like

How?! It’s outside the 4 year apart rule so anyone on subscription should be in at least revit 2020.

Yarrr matie.

3 Likes

Sir, help please~

Someone gave you a solution already, but you’re likely using cracked/old Revit so not much we can do to help.

Sorry - I can’t justify derailing current efforts to rebuild a tool for an unsupported version. Best bet will be to use AutoCAD to extract the geometry of the polylines to another format (say a JSON string using the Dynamo for Civil 3D toolset) and bring that into Dynamo for Revit.

One of your issues is that in working with the DWG import means you’re into Revit data types - so there is no such thing as a polyline.

1 Like