<?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 Jigging a polyline extrusion in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8834494#M22242</link>
    <description>&lt;P&gt;I am trying to create a command that will let me place a polyline of a set shape and then extrude it along a path with custom keyword options. In testing to figure out how to do it I have run into two problems. The most important one to me is that the Jig to extrude dose not render the graphics while selecting a point. Though the solid is created correctly once the point is picked. What am I missing? How do I get the extrusion to render while picking the point?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The less important problem is that I am using two jigs. I am using a DrawJig to place the polyline, then I am using an EntityJig to extrude the solid. Is there a way to combine these both into one jig. So do both in a DrawJig or both in and EntityJig?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[CommandMethod("SolidJig")]
        public static void SolidJig()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;
            Database db = ed.Document.Database;
            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    JigPline jig = new JigPline();
                    Point3dCollection pts;
                    PromptResult res = jig.DragMe(out pts);
                    if (res.Status == PromptStatus.OK)
                    {
                        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                        Polyline3d pLine = new Polyline3d(Poly3dType.SimplePoly, pts, true);
                        DBObjectCollection dbObj = new DBObjectCollection();
                        dbObj.Add(pLine);
                        Region region = Region.CreateFromCurves(dbObj)[0] as Region;
                        btr.AppendEntity(region);
                        tr.AddNewlyCreatedDBObject(region, true);
                        Solid3d solid = new Solid3d();
                        btr.AppendEntity(solid);
                        tr.AddNewlyCreatedDBObject(solid, true);
                        JigSolid solJig = new JigSolid(solid, ed.CurrentUserCoordinateSystem, region, pts[0]);
                        btr.AppendEntity(pLine);
                        tr.AddNewlyCreatedDBObject(pLine, true);
                        res = ed.Drag(solJig);
                        switch (res.Status)
                        {
                            case PromptStatus.OK:

                                break;
                        }
                    }
                    tr.Commit();
                }
            }
            catch { }
        }


        public class JigPline : DrawJig
        {
            public Point3d startPt;
            public Point3dCollection pts;
            public PromptResult DragMe(out Point3dCollection o_pnts)
            {
                Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;
                while (true)
                {
                    PromptResult jigRes = ed.Drag(this);
                    if (jigRes.Status != PromptStatus.Keyword)
                    {
                        o_pnts = pts;
                        return jigRes;
                    }
                }
            }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions pointOpts = new JigPromptPointOptions();
                pointOpts.Keywords.Add("Insertion");
                pointOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NullResponseAccepted);
                pointOpts.Message = "\nSelect start point";
                PromptPointResult jigRes = prompts.AcquirePoint(pointOpts);
                Point3d pt = jigRes.Value;
                if (pt == startPt)
                    return SamplerStatus.NoChange;
                startPt = pt;
                if (jigRes.Status == PromptStatus.OK || jigRes.Status == PromptStatus.Keyword)
                    return SamplerStatus.OK;
                return SamplerStatus.Cancel;
            }
            protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
            {
                pts = new Point3dCollection();
                pts.Add(startPt + new Vector3d(-3, 0, 0));
                pts.Add(startPt + new Vector3d(3, 0, 0));
                pts.Add(startPt + new Vector3d(3, 0, 6));
                pts.Add(startPt + new Vector3d(2.5 , 0, 6));
                pts.Add(startPt + new Vector3d(2.5, 0, 1));
                pts.Add(startPt + new Vector3d(-2.5 , 0, 1));
                pts.Add(startPt + new Vector3d(-2.5 , 0, 6));
                pts.Add(startPt + new Vector3d(-3, 0, 6));
                pts.Add(startPt + new Vector3d(-3, 0, 0));
                return draw.Geometry.Polygon(pts);
            }
        }

        public class JigSolid : EntityJig
        {
            Matrix3d _ucs;
            Point3d _pt;
            Point3d _endPt;
            double _dist;
            Region _reg;
            Solid3d _sol;
            SweepOptions _swpOpts;
            Polyline _pLine = new Polyline();

            public JigSolid(Solid3d sol, Matrix3d ucs, Region region, Point3d insertionPt) : base(region)
            {
                _ucs = ucs;
                _pt = insertionPt;
                _reg = region;
                _sol = sol;
                _swpOpts = new SweepOptions();
                _pLine = new Polyline();
            }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions ptOpts = new JigPromptPointOptions();
                ptOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted 
                    | UserInputControls.GovernedByOrthoMode | UserInputControls.NoNegativeResponseAccepted);
                ptOpts.UseBasePoint = true;
                ptOpts.BasePoint = _pt;
                ptOpts.Cursor = CursorType.RubberBand;
                ptOpts.Message = "\nSpecify distance :";
                PromptPointResult ppr = prompts.AcquirePoint(ptOpts);
                if (ppr.Status == PromptStatus.OK)
                {
                    Point3d tmp = ppr.Value.TransformBy(_ucs.Inverse());
                    if (tmp.DistanceTo(_pt) &amp;lt; Tolerance.Global.EqualPoint)
                        return SamplerStatus.NoChange;
                }
                _dist = _pt.DistanceTo(new Point3d(_pt.X, ppr.Value.Y, _pt.Z));
                _endPt = ppr.Value;
                return SamplerStatus.OK;
            }
            protected override bool Update()
            {
                try
                {
                    //_sol.ExtrudeAlongPath(_reg, new Line(_pt, new Point3d(_pt.X, _endPt.Y + 20, _pt.Z))  , 0);
                    //_sol.Extrude(_reg, _dist, 0);
                    _sol.CreateExtrudedSolid(_reg, _pt.GetVectorTo(_endPt), _swpOpts);
                }
                catch (System.Exception ex)
                {
                    return false;
                }
                return true;
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jun 2019 16:54:18 GMT</pubDate>
    <dc:creator>dpayton</dc:creator>
    <dc:date>2019-06-05T16:54:18Z</dc:date>
    <item>
      <title>Jigging a polyline extrusion</title>
      <link>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8834494#M22242</link>
      <description>&lt;P&gt;I am trying to create a command that will let me place a polyline of a set shape and then extrude it along a path with custom keyword options. In testing to figure out how to do it I have run into two problems. The most important one to me is that the Jig to extrude dose not render the graphics while selecting a point. Though the solid is created correctly once the point is picked. What am I missing? How do I get the extrusion to render while picking the point?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The less important problem is that I am using two jigs. I am using a DrawJig to place the polyline, then I am using an EntityJig to extrude the solid. Is there a way to combine these both into one jig. So do both in a DrawJig or both in and EntityJig?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;[CommandMethod("SolidJig")]
        public static void SolidJig()
        {
            Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;
            Database db = ed.Document.Database;
            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    JigPline jig = new JigPline();
                    Point3dCollection pts;
                    PromptResult res = jig.DragMe(out pts);
                    if (res.Status == PromptStatus.OK)
                    {
                        BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                        Polyline3d pLine = new Polyline3d(Poly3dType.SimplePoly, pts, true);
                        DBObjectCollection dbObj = new DBObjectCollection();
                        dbObj.Add(pLine);
                        Region region = Region.CreateFromCurves(dbObj)[0] as Region;
                        btr.AppendEntity(region);
                        tr.AddNewlyCreatedDBObject(region, true);
                        Solid3d solid = new Solid3d();
                        btr.AppendEntity(solid);
                        tr.AddNewlyCreatedDBObject(solid, true);
                        JigSolid solJig = new JigSolid(solid, ed.CurrentUserCoordinateSystem, region, pts[0]);
                        btr.AppendEntity(pLine);
                        tr.AddNewlyCreatedDBObject(pLine, true);
                        res = ed.Drag(solJig);
                        switch (res.Status)
                        {
                            case PromptStatus.OK:

                                break;
                        }
                    }
                    tr.Commit();
                }
            }
            catch { }
        }


        public class JigPline : DrawJig
        {
            public Point3d startPt;
            public Point3dCollection pts;
            public PromptResult DragMe(out Point3dCollection o_pnts)
            {
                Editor ed = acApp.DocumentManager.MdiActiveDocument.Editor;
                while (true)
                {
                    PromptResult jigRes = ed.Drag(this);
                    if (jigRes.Status != PromptStatus.Keyword)
                    {
                        o_pnts = pts;
                        return jigRes;
                    }
                }
            }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions pointOpts = new JigPromptPointOptions();
                pointOpts.Keywords.Add("Insertion");
                pointOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NullResponseAccepted);
                pointOpts.Message = "\nSelect start point";
                PromptPointResult jigRes = prompts.AcquirePoint(pointOpts);
                Point3d pt = jigRes.Value;
                if (pt == startPt)
                    return SamplerStatus.NoChange;
                startPt = pt;
                if (jigRes.Status == PromptStatus.OK || jigRes.Status == PromptStatus.Keyword)
                    return SamplerStatus.OK;
                return SamplerStatus.Cancel;
            }
            protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
            {
                pts = new Point3dCollection();
                pts.Add(startPt + new Vector3d(-3, 0, 0));
                pts.Add(startPt + new Vector3d(3, 0, 0));
                pts.Add(startPt + new Vector3d(3, 0, 6));
                pts.Add(startPt + new Vector3d(2.5 , 0, 6));
                pts.Add(startPt + new Vector3d(2.5, 0, 1));
                pts.Add(startPt + new Vector3d(-2.5 , 0, 1));
                pts.Add(startPt + new Vector3d(-2.5 , 0, 6));
                pts.Add(startPt + new Vector3d(-3, 0, 6));
                pts.Add(startPt + new Vector3d(-3, 0, 0));
                return draw.Geometry.Polygon(pts);
            }
        }

        public class JigSolid : EntityJig
        {
            Matrix3d _ucs;
            Point3d _pt;
            Point3d _endPt;
            double _dist;
            Region _reg;
            Solid3d _sol;
            SweepOptions _swpOpts;
            Polyline _pLine = new Polyline();

            public JigSolid(Solid3d sol, Matrix3d ucs, Region region, Point3d insertionPt) : base(region)
            {
                _ucs = ucs;
                _pt = insertionPt;
                _reg = region;
                _sol = sol;
                _swpOpts = new SweepOptions();
                _pLine = new Polyline();
            }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions ptOpts = new JigPromptPointOptions();
                ptOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoZeroResponseAccepted 
                    | UserInputControls.GovernedByOrthoMode | UserInputControls.NoNegativeResponseAccepted);
                ptOpts.UseBasePoint = true;
                ptOpts.BasePoint = _pt;
                ptOpts.Cursor = CursorType.RubberBand;
                ptOpts.Message = "\nSpecify distance :";
                PromptPointResult ppr = prompts.AcquirePoint(ptOpts);
                if (ppr.Status == PromptStatus.OK)
                {
                    Point3d tmp = ppr.Value.TransformBy(_ucs.Inverse());
                    if (tmp.DistanceTo(_pt) &amp;lt; Tolerance.Global.EqualPoint)
                        return SamplerStatus.NoChange;
                }
                _dist = _pt.DistanceTo(new Point3d(_pt.X, ppr.Value.Y, _pt.Z));
                _endPt = ppr.Value;
                return SamplerStatus.OK;
            }
            protected override bool Update()
            {
                try
                {
                    //_sol.ExtrudeAlongPath(_reg, new Line(_pt, new Point3d(_pt.X, _endPt.Y + 20, _pt.Z))  , 0);
                    //_sol.Extrude(_reg, _dist, 0);
                    _sol.CreateExtrudedSolid(_reg, _pt.GetVectorTo(_endPt), _swpOpts);
                }
                catch (System.Exception ex)
                {
                    return false;
                }
                return true;
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 16:54:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8834494#M22242</guid>
      <dc:creator>dpayton</dc:creator>
      <dc:date>2019-06-05T16:54:18Z</dc:date>
    </item>
    <item>
      <title>Update: Jigging a polyline extrusion</title>
      <link>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8835107#M22243</link>
      <description>&lt;P&gt;Using &lt;A href="http://drive-cad-with-code.blogspot.com/2011/01/" target="_blank" rel="noopener"&gt;this post&lt;/A&gt; I was able to figure out how to move the polyline inside an entityjig using a PointMonitorEventHandler which answer one of my questions, however it created a new one. I am not very confident in my use of the PointMonitorEventHandler. Is inside the Sampler override the correct place to add and remove the handler, and will it get removed correctly the way I have written it?&lt;/P&gt;&lt;PRE&gt;public class RegionJig : EntityJig
    {
        Region _reg;
        Point3d _basePoint;
        Point3d _currentPoint;
        Editor _ed;

        private void Editor_PointMonitor(object sender, PointMonitorEventArgs e)
        {
            _currentPoint = e.Context.RawPoint;
        }
        public RegionJig(Region region) : base(region)
        {
            _reg = region;
            _ed = acApp.DocumentManager.MdiActiveDocument.Editor;
        }

        protected override SamplerStatus Sampler(JigPrompts prompts)
        {
            try
            {
                _ed.PointMonitor += new PointMonitorEventHandler(Editor_PointMonitor);
                JigPromptPointOptions pointOpts = new JigPromptPointOptions();
                pointOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoNegativeResponseAccepted | UserInputControls.NoZeroResponseAccepted);
                pointOpts.Message = "\nSelect insertion point: ";
                PromptPointResult pres = prompts.AcquirePoint(pointOpts);
                if (_basePoint.DistanceTo(pres.Value) &amp;lt; Tolerance.Global.EqualPoint)
                    return SamplerStatus.NoChange;
                else
                    _currentPoint = pres.Value;
                return SamplerStatus.OK;
            }
            catch (System.Exception e)
            {
                throw;
            }
            finally
            {
                _ed.PointMonitor -= new PointMonitorEventHandler(Editor_PointMonitor);
            }
                
        }
        protected override bool Update()
        {
            try
            {
                _reg.TransformBy(Matrix3d.Displacement(_basePoint.GetVectorTo(_currentPoint)));
                _basePoint = _currentPoint;
            }
            catch(System.Exception ex)
            {
                return false;
            }
            return true;
        }
    }&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jun 2019 21:31:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8835107#M22243</guid>
      <dc:creator>dpayton</dc:creator>
      <dc:date>2019-06-05T21:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Update: Jigging a polyline extrusion</title>
      <link>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8840514#M22244</link>
      <description>&lt;P&gt;Turns out the point monitor is unnecessary. I still have not had any luck figuring out how to render the extrusion, anyone have any advice?&lt;/P&gt;&lt;PRE&gt;        public class RegionJig : EntityJig
        {
            Region _reg;
            Point3d _basePoint;
            Point3d _currentPoint;
            Editor _ed;
            Vector3d _baseVector;
            Vector3d _deltaVector;
            int _phase;
            Solid3d _solid;
            SweepOptions _swepOts;
            public RegionJig(Region region,Solid3d solid) : base(region)
            {
                _reg = region;
                _ed = acApp.DocumentManager.MdiActiveDocument.Editor;
                _solid = solid;
                _phase = 1;
                _swepOts = new SweepOptions();
                _baseVector = new Vector3d(1, 0, 0);
            }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                try
                {
                    JigPromptPointOptions pointOpts = new JigPromptPointOptions();
                    PromptPointResult pointRes;
                    pointOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NoNegativeResponseAccepted | UserInputControls.NoZeroResponseAccepted);
                    switch (_phase)
                    {
                        case 1:
                            pointOpts.Message = "\nSelect insertion point: ";
                            pointRes = prompts.AcquirePoint(pointOpts);
                            if (pointRes.Status == PromptStatus.OK)
                            {
                                if (_basePoint.DistanceTo(pointRes.Value) &amp;lt; Tolerance.Global.EqualPoint)
                                    return SamplerStatus.NoChange;
                                _currentPoint = pointRes.Value;
                                return SamplerStatus.OK;
                            }
                            else
                                return SamplerStatus.Cancel;
                        case 2:
                            pointOpts.Message = "\nSelect direction: ";
                            pointOpts.Cursor = CursorType.RubberBand;
                            pointOpts.UseBasePoint = true;
                            pointOpts.BasePoint = _basePoint;
                            pointRes = prompts.AcquirePoint(pointOpts);
                            if (pointRes.Status == PromptStatus.OK)
                            {
                                if (_basePoint.DistanceTo(pointRes.Value) &amp;lt; Tolerance.Global.EqualPoint)
                                    return SamplerStatus.NoChange;
                                _currentPoint = pointRes.Value;
                                _deltaVector = new Vector3d(_basePoint.GetVectorTo(_currentPoint).X, _basePoint.GetVectorTo(_currentPoint).Y, 0);
                                return SamplerStatus.OK;
                            }
                            else
                                return SamplerStatus.Cancel;
                    }
                    return SamplerStatus.Cancel;
                }
                catch (System.Exception e)
                {
                    throw;
                }
            }
            protected override bool Update()
            {
                try
                {
                    switch (_phase)
                    {
                        case 1:
                            _reg.TransformBy(Matrix3d.Displacement(_basePoint.GetVectorTo(_currentPoint)));
                            _basePoint = _currentPoint;
                            break;
                        case 2:
                            _reg.TransformBy(Matrix3d.Rotation(_baseVector.GetAngleTo(_deltaVector, Vector3d.ZAxis), Vector3d.ZAxis, _basePoint));
                            _solid.CreateExtrudedSolid(_reg, _deltaVector, _swepOts);
                            _baseVector = _deltaVector;
                            break;
                    }
                }
                catch (System.Exception ex)
                {
                    return false;
                }
                return true;
            }
            internal void NextPhase()
            {
                _phase++;
            }
            internal void RunTillComplete(Editor ed)
            {
                try
                {
                    while (true)
                    {
                        var res = ed.Drag(this);
                        if (res.Status == PromptStatus.OK)
                        {
                            if (_phase == 2)
                            {
                                return;
                            }
                            NextPhase();
                        }
                        else if (res.Status == PromptStatus.Cancel)
                            return;
                    }
                }
                catch (System.Exception ex)
                {
                    throw;
                }
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Jun 2019 17:41:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8840514#M22244</guid>
      <dc:creator>dpayton</dc:creator>
      <dc:date>2019-06-08T17:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Update: Jigging a polyline extrusion</title>
      <link>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8840731#M22245</link>
      <description>&lt;P&gt;Figured it out, seems out the base needs to be the Solid3d not the Region. Like this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            public RegionJig(Region region,Solid3d solid) : base(solid)
            {
                _reg = region;
                _ed = acApp.DocumentManager.MdiActiveDocument.Editor;
                _solid = solid;
                _phase = 1;
                _swepOts = new SweepOptions();
                _baseVector = new Vector3d(1, 0, 0);
            }&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Not this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;            public RegionJig(Region region,Solid3d solid) : base(region)
            {
                _reg = region;
                _ed = acApp.DocumentManager.MdiActiveDocument.Editor;
                _solid = solid;
                _phase = 1;
                _swepOts = new SweepOptions();
                _baseVector = new Vector3d(1, 0, 0);
            }&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Jun 2019 00:52:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/jigging-a-polyline-extrusion/m-p/8840731#M22245</guid>
      <dc:creator>dpayton</dc:creator>
      <dc:date>2019-06-09T00:52:08Z</dc:date>
    </item>
  </channel>
</rss>

