<?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: AutoCAD 2020 Z-axis (ZAXIS) .net align polyline in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/autocad-2020-z-axis-zaxis-net-align-polyline/m-p/9250046#M20469</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easy way is to call the _UCS command.&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST1")]
        public static void Test1()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var peo = new PromptEntityOptions("\nSelect Polyline: ");
            peo.SetRejectMessage("\nSelected object is not a Polyline.");
            peo.AddAllowedClass(typeof(Polyline), true);
            var per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) 
                return;
            ed.Command("_.ucs", "_object", per.ObjectId);
        }&lt;/PRE&gt;
&lt;P&gt;But you can also mimic the native command by computing the Matrix3d.&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST2")]
        public static void Test2()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var peo = new PromptEntityOptions("\nSelect Polyline: ");
            peo.SetRejectMessage("\nSelected object is not a Polyline.");
            peo.AddAllowedClass(typeof(Polyline), true);
            var per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForRead);
                var origin = pline.StartPoint;
                var xAxis = pline.GetFirstDerivative(pline.StartParam);
                var zAxis = pline.Normal;
                var yAxis = zAxis.CrossProduct(xAxis).GetNormal();
                var ocs = Matrix3d.AlignCoordinateSystem(
                    Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
                    origin, xAxis, yAxis, zAxis);
                ed.CurrentUserCoordinateSystem = ocs;
                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Jan 2020 16:44:53 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2020-01-14T16:44:53Z</dc:date>
    <item>
      <title>AutoCAD 2020 Z-axis (ZAXIS) .net align polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-2020-z-axis-zaxis-net-align-polyline/m-p/9249417#M20468</link>
      <description>&lt;P&gt;Hello everybody!&lt;BR /&gt;In AutoCAD I can use the command "BKS" "ZA" "O" O for object&lt;BR /&gt;to align the UCS in the Z axis with an object (polyline).&lt;/P&gt;&lt;P&gt;Is there a way to do this in .NET or C # using code?&lt;/P&gt;&lt;P&gt;I click on a polyline and the UCS aligns with the Z-axis (ZAXIS)&lt;BR /&gt;on the polyline?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 13:19:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-2020-z-axis-zaxis-net-align-polyline/m-p/9249417#M20468</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-01-14T13:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD 2020 Z-axis (ZAXIS) .net align polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-2020-z-axis-zaxis-net-align-polyline/m-p/9250046#M20469</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easy way is to call the _UCS command.&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST1")]
        public static void Test1()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var peo = new PromptEntityOptions("\nSelect Polyline: ");
            peo.SetRejectMessage("\nSelected object is not a Polyline.");
            peo.AddAllowedClass(typeof(Polyline), true);
            var per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK) 
                return;
            ed.Command("_.ucs", "_object", per.ObjectId);
        }&lt;/PRE&gt;
&lt;P&gt;But you can also mimic the native command by computing the Matrix3d.&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("TEST2")]
        public static void Test2()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var peo = new PromptEntityOptions("\nSelect Polyline: ");
            peo.SetRejectMessage("\nSelected object is not a Polyline.");
            peo.AddAllowedClass(typeof(Polyline), true);
            var per = ed.GetEntity(peo);
            if (per.Status != PromptStatus.OK)
                return;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var pline = (Polyline)tr.GetObject(per.ObjectId, OpenMode.ForRead);
                var origin = pline.StartPoint;
                var xAxis = pline.GetFirstDerivative(pline.StartParam);
                var zAxis = pline.Normal;
                var yAxis = zAxis.CrossProduct(xAxis).GetNormal();
                var ocs = Matrix3d.AlignCoordinateSystem(
                    Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
                    origin, xAxis, yAxis, zAxis);
                ed.CurrentUserCoordinateSystem = ocs;
                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jan 2020 16:44:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-2020-z-axis-zaxis-net-align-polyline/m-p/9250046#M20469</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-01-14T16:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: AutoCAD 2020 Z-axis (ZAXIS) .net align polyline</title>
      <link>https://forums.autodesk.com/t5/net-forum/autocad-2020-z-axis-zaxis-net-align-polyline/m-p/9250472#M20470</link>
      <description>&lt;P&gt;... great, thank you, that helps me a lot.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 19:34:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/autocad-2020-z-axis-zaxis-net-align-polyline/m-p/9250472#M20470</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-01-14T19:34:16Z</dc:date>
    </item>
  </channel>
</rss>

