Пример #1
0
        /// <summary>
        /// Create Edge (Line or Arc2) from Dynamo Line or Arc.
        /// Used for bar definition.
        /// </summary>
        public static Geometry.Edge FromDynamoLineOrArc2(Autodesk.DesignScript.Geometry.Curve obj)
        {
            // if polyline or similar.
            Autodesk.DesignScript.Geometry.Geometry[] items = obj.Explode();
            if (items.Length != 1)
            {
                throw new System.ArgumentException("Exploded Curve should only have one item.");
            }
            Autodesk.DesignScript.Geometry.Geometry item = items[0];

            // if Arc
            if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Arc))
            {
                return(Edge.FromDynamoArc2((Autodesk.DesignScript.Geometry.Arc)item));
            }

            // if Line
            else if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Line))
            {
                return(Edge.FromDynamoLine((Autodesk.DesignScript.Geometry.Line)item));
            }

            else
            {
                throw new System.ArgumentException($"Curve type: {obj.GetType()}, is not Line or Arc.");
            }
        }
Пример #2
0
        /// <summary>
        /// Create FdCoordinateSystem from Dynamo coordinate system on curve mid u-point.
        /// </summary>
        internal static FdCoordinateSystem FromDynamoCurve(Autodesk.DesignScript.Geometry.Curve obj)
        {
            // CoordinateSystemAtParameter returns a coordinate system on curve
            // with origin at the point at the given parameter.
            // The XAxis is aligned with the curve normal,
            // the YAxis is aligned with the curve tangent at this point,
            // and the ZAxis is aligned with the up-vector or binormal at this point
            Autodesk.DesignScript.Geometry.CoordinateSystem cs = obj.CoordinateSystemAtParameter(0.5);

            // Note: Arcs and Circles in Dynamo are defined with left-hand rule while coordinate system is defined by right-hand rule
            if (obj.GetType() == typeof(Autodesk.DesignScript.Geometry.Arc) || obj.GetType() == typeof(Autodesk.DesignScript.Geometry.Circle))
            {
                return(FdCoordinateSystem.FromDynamoCoordinateSystemArcOrCircle(cs));
            }
            else
            {
                return(FromDynamoCoordinateSystemLine(cs));
            }
        }
Пример #3
0
        /// <summary>
        /// Convert a Dynamo Curve to Edge.
        /// </summary>
        /// <param name="obj"></param>
        public static Geometry.Edge FromDynamo(Autodesk.DesignScript.Geometry.Curve obj)
        {
            // if polyline or similar.
            Autodesk.DesignScript.Geometry.Geometry[] items = obj.Explode();
            if (items.Length != 1)
            {
                throw new System.ArgumentException("Exploded Curve should only have one item.");
            }
            Autodesk.DesignScript.Geometry.Geometry item = items[0];

            // if Arc
            if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Arc))
            {
                // output is a general purpose Edge
                return(Edge.FromDynamoArc1((Autodesk.DesignScript.Geometry.Arc)item));
            }

            // if Circle
            else if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Circle))
            {
                return(Edge.FromDynamoCircle((Autodesk.DesignScript.Geometry.Circle)item));
            }

            // if Line
            else if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.Line))
            {
                return(Edge.FromDynamoLine((Autodesk.DesignScript.Geometry.Line)item));
            }

            // if NurbsCurve
            else if (item.GetType() == typeof(Autodesk.DesignScript.Geometry.NurbsCurve))
            {
                return(Edge.FromDynamoNurbsCurve((Autodesk.DesignScript.Geometry.NurbsCurve)item));
            }

            // else
            else
            {
                throw new System.ArgumentException($"Curve type: {obj.GetType()}, is not supported for conversion to an Edge.");
            }
        }
 public static Autodesk.AutoCAD.DatabaseServices.Polyline ConvertPolyCurveToPolyline(Autodesk.DesignScript.Geometry.PolyCurve polyCurve)
 {
     Autodesk.AutoCAD.DatabaseServices.Polyline retVal = new Autodesk.AutoCAD.DatabaseServices.Polyline();
     if (polyCurve != null)
     {
         // extract each segment
         Autodesk.DesignScript.Geometry.Curve[] curves = new Autodesk.DesignScript.Geometry.Curve[polyCurve.NumberOfCurves];
         // convert segment into AutoCAD polyline
         int curIndex = 0;
         while (curIndex < polyCurve.NumberOfCurves)
         {
             double bulge = 0.0;
             Autodesk.DesignScript.Geometry.Curve curCurve = polyCurve.CurveAtIndex(curIndex);
             // trying to figure out if the segment is an arc or line...for some reason it thinks lines are arcs
             var typeOfcurve = curCurve.GetType();
             if (typeOfcurve == typeof(Autodesk.DesignScript.Geometry.Arc))
             {
                 // set the bulge for the curve
                 //bulge = BulgeFromCurve(curCurve, true);
                 bulge = 0.5;
             }
             // otherwise, it's a line, and default bulge applies
             retVal.AddVertexAt(curIndex, new Point2d(curCurve.StartPoint.X, curCurve.StartPoint.Y), bulge, 0.0, 0.0);
             curIndex = curIndex + 1;
         }
         if (polyCurve.StartPoint == polyCurve.EndPoint)
         {
             retVal.Closed = true;
         }
         else
         {
             retVal.AddVertexAt(curIndex, new Point2d(polyCurve.EndPoint.X, polyCurve.EndPoint.Y), 0.0, 0.0, 0.0);
         }
         //retVal = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(curves);
     }
     return(retVal);
 }