Civil 3D Alignment entities as DesignScript Geometry PolyCurve

Hi …
Using Python Script, CLR, .NET managed C3D DLL’s…
Is there a simple cast method to represent Autodesk.Civil.DatabaseServices.Alignment Entities as a DesignScript Geometry PolyCurve?
Thx for your patience,
K.

The C3DToolkit and Arkance Systems Node Library contains nodes to do that, can you use these? Or do you want to code it yourself?

Thx … I need to code it in python (referencing .NET) … please … if that’s ok …

I don’t speak Python, but here is some C# code (for a Dynamo node, not for a plug-in) that does the trick, you could rewrite it into Python:

using acAppServ = Autodesk.AutoCAD.ApplicationServices;
using acDbServ = Autodesk.AutoCAD.DatabaseServices;
using acGeom = Autodesk.AutoCAD.Geometry;
using acRuntime = Autodesk.AutoCAD.Runtime;
using cdDbServ = Autodesk.Civil.DatabaseServices;
using cdAppServ = Autodesk.Civil.ApplicationServices;
using dynAppServ = Autodesk.AutoCAD.DynamoApp.Services;
using dynACNodes = Autodesk.AutoCAD.DynamoNodes;
using dynCDNodes = Autodesk.Civil.DynamoNodes;

/// <summary>
/// Returns the Dynamo geometry of the Alignment (lines and arcs, spirals become short lines and MultipleSegments are returned as single line)
/// </summary>
[Dynamo.Graph.Nodes.NodeCategory("Query")]
public static PolyCurve GetDynamoGeometry(dynCDNodes.Alignment alignment)
{
    if (alignment == null) { return null; }

    cdDbServ.Alignment alignmentCD = alignment.InternalDBObject as cdDbServ.Alignment;
    List<Curve> curves = new List<Curve>();

    try
    {
        dynACNodes.Document document = dynACNodes.Document.Current;
        using (dynAppServ.DocumentContext ctx = new dynAppServ.DocumentContext(document.AcDocument))
        {
            acDbServ.Transaction tr = ctx.Transaction; // using, disposing or submit a Transaction results in Fatal Error

            if (alignmentCD.Entities.Count != 0)
            {

                for (int i = 0; i < alignmentCD.Entities.Count; i++)
                {
                    cdDbServ.AlignmentEntity aeEnt = alignmentCD.Entities.GetEntityByOrder(i); // Entities in an Alignment are not in order.

                    if (aeEnt.EntityType == cdDbServ.AlignmentEntityType.Arc)
                    {
                        cdDbServ.AlignmentArc aaEnt = (cdDbServ.AlignmentArc)aeEnt;
                        // Clockwise arcs become the remainder of a circle, so draw the opposite.
                        if (aaEnt.Clockwise == true)
                        {
                            curves.Add(Arc.ByCenterPointStartPointEndPoint(Point.ByCoordinates(aaEnt.CenterPoint.X, aaEnt.CenterPoint.Y), Point.ByCoordinates(aaEnt.EndPoint.X, aaEnt.EndPoint.Y), Point.ByCoordinates(aaEnt.StartPoint.X, aaEnt.StartPoint.Y)));
                        }
                        else
                        {
                            curves.Add(Arc.ByCenterPointStartPointEndPoint(Point.ByCoordinates(aaEnt.CenterPoint.X, aaEnt.CenterPoint.Y), Point.ByCoordinates(aaEnt.StartPoint.X, aaEnt.StartPoint.Y), Point.ByCoordinates(aaEnt.EndPoint.X, aaEnt.EndPoint.Y)));
                        }
                    }

                    else if (aeEnt.EntityType == cdDbServ.AlignmentEntityType.Line)
                    {
                        cdDbServ.AlignmentLine alEnt = (cdDbServ.AlignmentLine)aeEnt;
                        curves.Add(Line.ByStartPointEndPoint(Point.ByCoordinates(alEnt.StartPoint.X, alEnt.StartPoint.Y), Point.ByCoordinates(alEnt.EndPoint.X, alEnt.EndPoint.Y)));
                    }
                    else if (aeEnt.EntityType == cdDbServ.AlignmentEntityType.MultipleSegments)
                    {
                        cdDbServ.AlignmentMultipleSegments alEnts = (cdDbServ.AlignmentMultipleSegments)aeEnt;

                        curves.Add(Line.ByStartPointEndPoint(Point.ByCoordinates(alEnts.StartPoint.X, alEnts.StartPoint.Y), Point.ByCoordinates(alEnts.EndPoint.X, alEnts.EndPoint.Y)));
                    }
                    else
                    {
                        cdDbServ.AlignmentCurve ac = (cdDbServ.AlignmentCurve)aeEnt;
                        if (ac != null)
                        {
                            Point start = Point.ByCoordinates(ac.StartPoint.X, ac.StartPoint.Y);

                            // Divide the curve and loop through points on the alignment between startstation and endstation.
                            double divideLength = ac.Length / 10.0;
                            for (double j = ac.StartStation + divideLength; j < ac.EndStation; j += divideLength)
                            {
                                acGeom.Point3d endCD = alignmentCD.GetPointAtDist(j);
                                Point end = Point.ByCoordinates(endCD.X, endCD.Y);
                                curves.Add(Line.ByStartPointEndPoint(start, end));
                                start = end;
                            }

                            // Add last part to the endpoint of the curve.
                            Point endCurve = Point.ByCoordinates(ac.EndPoint.X, ac.EndPoint.Y);
                            if (global::Functions.Numbers.IsSameValue(start.DistanceTo(endCurve), 0.0) == false)
                            {
                                curves.Add(Line.ByStartPointEndPoint(start, endCurve));
                            }
                        }
                    }
                }
            }
        }
    }
    catch (System.Exception ex) { GenericException.Logging.ExceptionLog.Log(ex); }

    return PolyCurve.ByJoinedCurves(curves);
}

Excellent - Thank You : )