<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get the Vector3d value from Polyine3d in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7311144#M30054</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;waseefur.rahman a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;One more thing please, Is there any way to Convert Polyline3d to Polyline.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, this may be quite easy using the Curve.GetOthoProjectedCurve() or Curve.GetProjectedCurve() method but it requires to already know the Polyline plane (its normal and elevation).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What have you so far? Why do you need the Normal vector for? How are drawn your 3d polylines?&lt;/P&gt;</description>
    <pubDate>Fri, 18 Aug 2017 14:06:58 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2017-08-18T14:06:58Z</dc:date>
    <item>
      <title>Get the Vector3d value from Polyine3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7310691#M30051</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am having a entity as Polyline, from that I was able to get the normal value&lt;BR /&gt;&lt;BR /&gt;Dim Obj As Entity&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Dim Objpts As Vector3d = Obj.Normal&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Incase if the entity is Polyline3d&lt;BR /&gt;&lt;BR /&gt;how to get the normal value for that?&lt;BR /&gt;&lt;BR /&gt;i am getting the error as&amp;nbsp;Normal is not a member of Polyline3d,&lt;BR /&gt;Could any suggest how to get Vector3d value for Polyline3d.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 11:29:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7310691#M30051</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-08-18T11:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get the Vector3d value from Polyine3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7310719#M30052</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Normal property of some entities refers to the normal of the entity plane (i.e. the unit vector perpendicular to the plane).&lt;/P&gt;
&lt;P&gt;2D entities as Polyline, Circle, Arc, Text, and so on lie on a (single) plane so the Normal property of these entities refers the the normal vector of their plane.&lt;/P&gt;
&lt;P&gt;Typically a Polyline3d is not planar (a planar Polyline3d should be replaced by aPolyline2d or a Polyline), so there's no plane to define a normal vector.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be more explicit about what you're trying to do so that it may be possible to find a work around.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 11:41:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7310719#M30052</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-08-18T11:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: Get the Vector3d value from Polyine3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7311034#M30053</link>
      <description>&lt;P&gt;Hi Gile,&lt;BR /&gt;&lt;BR /&gt;Many Thanks for your brief description.&lt;BR /&gt;&lt;BR /&gt;One more thing please, Is there any way to Convert Polyline3d to Polyline.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 13:40:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7311034#M30053</guid>
      <dc:creator>waseefur.rahman</dc:creator>
      <dc:date>2017-08-18T13:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Get the Vector3d value from Polyine3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7311144#M30054</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;waseefur.rahman a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;One more thing please, Is there any way to Convert Polyline3d to Polyline.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, this may be quite easy using the Curve.GetOthoProjectedCurve() or Curve.GetProjectedCurve() method but it requires to already know the Polyline plane (its normal and elevation).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What have you so far? Why do you need the Normal vector for? How are drawn your 3d polylines?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2017 14:06:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7311144#M30054</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-08-18T14:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get the Vector3d value from Polyine3d</title>
      <link>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7311713#M30055</link>
      <description>&lt;P&gt;The following Polyline3d.ToPolyline() extension method returns a new instance of Polyline if the Polyline3d is planar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    public static class ExtensionMethods
    {
        /// &amp;lt;summary&amp;gt;
        /// Gets the vertices of a polyline 3d.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="pline3d"&amp;gt;The instance this method applies to.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;The collection of vertices positions (SimpleVertex or FitVertex).&amp;lt;/returns&amp;gt;
        public static Point3dCollection GetVertices(this Polyline3d pline3d)
        {
            if (pline3d == null)
                throw new ArgumentNullException(nameof(pline3d));

            var points = new Point3dCollection();
            using (var tr = pline3d.Database.TransactionManager.StartOpenCloseTransaction())
            {
                foreach (ObjectId id in pline3d)
                {
                    var vx = (PolylineVertex3d)tr.GetObject(id, OpenMode.ForRead);
                    if (vx.VertexType != Vertex3dType.ControlVertex)
                        points.Add(vx.Position);
                }
                tr.Commit();
            }
            return points;
        }

        /// &amp;lt;summary&amp;gt;
        /// Evaluates if the points lies on a single plane.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="points"&amp;gt;The instance this method applies to.&amp;lt;/param&amp;gt;
        /// &amp;lt;param name="normal"&amp;gt;Normal of the plane.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;
        public static bool IsPlanar(this Point3dCollection points, out Vector3d normal)
        {
            if (points == null)
                throw new ArgumentNullException(nameof(points));

            normal = new Vector3d();
            if (points.Count &amp;lt; 3)
                return false;
            var v = points[0].GetVectorTo(points[1]);
            var u = new Vector3d();
            bool found = false;
            for (int i = 2; i &amp;lt; points.Count; i++)
            {
                u = points[0].GetVectorTo(points[i]);
                if (!u.IsParallelTo(v))
                {
                    found = true;
                    break;
                }
            }
            if (!found)
                return false;
            normal = v.CrossProduct(u).GetNormal();
            var plane = new Plane(points[0], normal);
            double d = Tolerance.Global.EqualPoint;
            return points.Cast&amp;lt;Point3d&amp;gt;().All(p =&amp;gt; Math.Abs(plane.GetSignedDistanceTo(p)) &amp;lt;= d);
        }

        /// &amp;lt;summary&amp;gt;
        /// Gets a Polyline from the Polyline3d. 
        /// An exception is thrown if the Polyline3d vertices do not define a single plane.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="pline3d"&amp;gt;The instance this method applies to.&amp;lt;/param&amp;gt;
        /// &amp;lt;returns&amp;gt;A new Polyline instance.&amp;lt;/returns&amp;gt;
        public static Polyline ToPolyline(this Polyline3d pline3d)
        {
            if (pline3d == null)
                throw new ArgumentNullException(nameof(pline3d));

            Vector3d normal;
            var points = pline3d.GetVertices();
            if (!points.IsPlanar(out normal))
                throw new InvalidOperationException("The Polyline3d does not define a single plane.");
            var plane = new Plane(Point3d.Origin, normal);
            var pline = new Polyline(points.Count);
            for (int i = 0; i &amp;lt; points.Count; i++)
            {
                pline.AddVertexAt(i, points[i].Convert2d(plane), 0.0, 0.0, 0.0);
            }
            pline.Normal = normal;
            pline.Elevation = points[0].TransformBy(Matrix3d.WorldToPlane(plane)).Z;
            pline.Closed = pline3d.Closed;
            return pline;
        }
    }&lt;/PRE&gt;
&lt;P&gt;Testing example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST")]
        public void Polyline3dToPolyline()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var peo = new PromptEntityOptions("\nSelect a 3D polyline: ");
            peo.SetRejectMessage("\nSelected object is not a 3D polyline.");
            peo.AddAllowedClass(typeof(Polyline3d), true);
            var per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var pl3d = (Polyline3d)tr.GetObject(per.ObjectId, OpenMode.ForWrite);
                var space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                try
                {
                    var pline = pl3d.ToPolyline();
                    pline.SetDatabaseDefaults();
                    space.AppendEntity(pline);
                    tr.AddNewlyCreatedDBObject(pline, true);
                    pl3d.Erase();
                }
                catch (System.Exception ex)
                {
                    Application.ShowAlertDialog(ex.Message);
                }
                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2017 16:47:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/get-the-vector3d-value-from-polyine3d/m-p/7311713#M30055</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2017-08-18T16:47:43Z</dc:date>
    </item>
  </channel>
</rss>

