<?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 Betreff: Jig with dimension in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/jig-with-dimension/m-p/13225007#M1554</link>
    <description>&lt;P&gt;To any one who comes across this post and wants to do some thing similar&lt;/P&gt;&lt;P&gt;here is my last attempt where you can select two lines/polylines to guide an entity movement along two dimensions while jigging:&lt;BR /&gt;this is where to call the drag method of Jig:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public void Move()
{
    if (!SelectGuideLine()) 
        return;

    _movingPoint = _basePoint;

    _dim1 = new AlignedDimension(_basePoint,_movingPoint,Point3d.Origin,
        "0000",_dwg.Database.DimStyleTableId);

    using (var tr =_dwg.Database.TransactionManager.StartTransaction())
    {
        var md = tr.GetObject(_dwg.Database.CurrentSpaceId,OpenMode.ForWrite) as BlockTableRecord;

        do
        {
            var res = _ed.Drag(this);
            if (res.Status != PromptStatus.OK)
                return;
            if (_dim2 == null)
            {
                _dwg.Database.TransactionManager.QueueForGraphicsFlush();
                if (SelectGuideLine())
                {
                    _dim2 = new AlignedDimension(_basePoint,_movingPoint,Point3d.Origin,
                                    "0000",_dwg.Database.DimStyleTableId);
                }
                else
                {
                    tr.Commit();
                    return;
                }
            }
            else
            {
                md.AppendEntity(_dim2);
                tr.AddNewlyCreatedDBObject(_dim2, true);
                md.AppendEntity(_dim1);
                tr.AddNewlyCreatedDBObject(_dim1, true);
                md.AppendEntity(_jigEntity);
                tr.AddNewlyCreatedDBObject(_jigEntity, true);

                tr.Commit();
                return;
            }
        } while (true);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;this is sampler and world draw:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override SamplerStatus Sampler(JigPrompts prompts)
{
    
    var status = SamplerStatus.NoChange;
    _dwg.Database.Orthomode = false;
    var opt = new JigPromptPointOptions("\nMove to:");
    opt.UseBasePoint = true;
    if(_dim2 is null)
    {
        _basePoint = _guideLine1.GetClosestPointTo(_movingPoint, true);
        _dim1.XLine1Point = _basePoint;
    }
    else
    {
        _basePoint = _guideLine2.GetClosestPointTo(_movingPoint, true);
        _dim2.XLine1Point = _basePoint;
    }
    opt.BasePoint = _basePoint;
    var res = prompts.AcquirePoint(opt);
    
    if (res.Status == PromptStatus.OK)
    {
        if (!res.Value.Equals(_rawMovingPoint))
        {
            _rawMovingPoint = res.Value;
            if (_dim2 is null)
            {
                _dim1.XLine2Point = res.Value;
                _dim1.DimLinePoint = res.Value;
                var dist = _basePoint.DistanceTo(res.Value).ToString("######0.000");
                _dim1.DimensionText = dist;
                _jigEntity.Center = _dim1.XLine2Point;
            }
            else
            {
                var dim1Vector = _dim1.XLine1Point.GetVectorTo(_dim1.XLine2Point);
                _dim1.XLine1Point = _guideLine1.GetClosestPointTo(res.Value, true);
                _dim1.XLine2Point = _dim1.XLine1Point.Add(dim1Vector);
                _dim1.DimLinePoint = res.Value;

                _dim2.XLine2Point = res.Value;
                _dim2.DimLinePoint = res.Value;
                var dist = _dim2.XLine1Point.DistanceTo(_dim2.XLine2Point).ToString("######0.000");
                _dim2.DimensionText = dist;
                
                _jigEntity.Center = _dim1.XLine2Point;
            }
            _movingPoint = res.Value;
            status = SamplerStatus.OK;
        }
    }
    else
    {
        status = SamplerStatus.Cancel;
    }

    return status;
}

protected override bool WorldDraw(WorldDraw draw)
{
    if (_dim1.ObjectId == ObjectId.Null)
    {
        _dim1.RecomputeDimensionBlock(true);
        draw.Geometry.Draw(_dim1);
    }
    if(_dim2 != null)
    {
        _dim2.RecomputeDimensionBlock(true);
        draw.Geometry.Draw(_dim2);
        draw.Geometry.Draw(_dim1);
    }
    return draw.Geometry.Draw(_jigEntity);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and this is the method that selects guide lines:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private bool SelectGuideLine()
{
    var eRes = _ed.GetEntity("\nSelect guide line");
    if (eRes.Status == PromptStatus.OK)
    {
        using (var tr =_dwg.Database.TransactionManager.StartOpenCloseTransaction())
        {
            if (_dim1 is null)
            {
                _guideLine1 = tr.GetObject(eRes.ObjectId, OpenMode.ForRead) as Line;
                if (_guideLine1 is null)
                    return false;
                _basePoint = eRes.PickedPoint;
            }
            else
            {
                _guideLine2 = tr.GetObject(eRes.ObjectId, OpenMode.ForRead) as Line;
                if (_guideLine2 is null)
                    return false;

                _basePoint = _guideLine2.GetClosestPointTo(_dim1.XLine2Point, true);
                var l = new Line(_basePoint, _dim1.XLine2Point);
                var md = tr.GetObject(CadApp.DocumentManager.MdiActiveDocument.Database.CurrentSpaceId,
                    OpenMode.ForWrite) as BlockTableRecord;
            }
            tr.Commit();
        }
        return true;
    }
    else
    {
        return false;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="akouchakzadeh_0-1734854593666.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1448406i12A96812EA9DB923/image-size/medium?v=v2&amp;amp;px=400" role="button" title="akouchakzadeh_0-1734854593666.png" alt="akouchakzadeh_0-1734854593666.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Dec 2024 08:03:33 GMT</pubDate>
    <dc:creator>a.kouchakzadeh</dc:creator>
    <dc:date>2024-12-22T08:03:33Z</dc:date>
    <item>
      <title>Jig with dimension</title>
      <link>https://forums.autodesk.com/t5/net-forum/jig-with-dimension/m-p/13204908#M1553</link>
      <description>&lt;P&gt;In Mr.&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@Norman_Yuan&lt;/a&gt;&amp;nbsp; blog there is a &lt;A href="https://drive-cad-with-code.blogspot.com/2020/04/jig-with-dimension.html" target="_blank" rel="noopener"&gt;post&lt;/A&gt; which demonstrates how to jig an object with dimension.&lt;/P&gt;&lt;P&gt;I tried to modify the code so that I would pick the first guideline, enter a distance and then the code fixes the jigged entity from the first guideline so it can only be moved in that certain distance. now the code asks for the second guide line, I select it and if I enter distance, it considers both distance values and place the entity accordingly (dist1 from guide line 1, dist2 from guide line 2).&lt;BR /&gt;the code works fine with the first distance but does not work ok when the second distance is entered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it has to do some thing with constantly moving basepoint?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class DimMoveJig : DrawJig
{
    private Point3d _basePoint = Point3d.Origin;
    private Point3d _movingPoint = Point3d.Origin;
    private Line _guideLine1;
    private Line _guideLine2;
    private Document _dwg;
    private Editor _ed;

    private Circle _jigEntity= new Circle(Point3d.Origin, Vector3d.ZAxis,5);
    private AlignedDimension _dim1 = null;
    private AlignedDimension _dim2 = null;
    private Point3d _rawMovingPoint;
    public DimMoveJig() : base()
    {
        _dwg = CadApp.DocumentManager.MdiActiveDocument;
        _ed = _dwg.Editor;
        _dwg.Database.Pdmode = 34;
    }

    public void Move()
    {
        if (!SelectGuideLine()) 
            return;

        _movingPoint = _basePoint;

        _dim1 = new AlignedDimension(_basePoint,_movingPoint,Point3d.Origin,
            "0000",_dwg.Database.DimStyleTableId);

        using (var tr =_dwg.Database.TransactionManager.StartTransaction())
        {
            var md = tr.GetObject(_dwg.Database.CurrentSpaceId,OpenMode.ForWrite) as BlockTableRecord;

            do
            {
                var res = _ed.Drag(this);
                if (res.Status != PromptStatus.OK)
                    return;
                if (_dim2 == null)
                {
                    md.AppendEntity(_dim1);
                    tr.AddNewlyCreatedDBObject(_dim1, true);
                    _dwg.Database.TransactionManager.QueueForGraphicsFlush();
                    if (SelectGuideLine())
                    {
                        _dim2 = new AlignedDimension(_basePoint,_movingPoint,Point3d.Origin,
                                        "0000",_dwg.Database.DimStyleTableId);
                    }
                    else
                    {
                        tr.Commit();
                        return;
                    }
                }
                else
                {
                    md.AppendEntity(_dim2);
                    tr.AddNewlyCreatedDBObject(_dim2, true);
                    md.AppendEntity(_jigEntity);

                    var dbpt = new DBPoint(_basePoint);
                    tr.AddNewlyCreatedDBObject(_jigEntity, true);

                    md.AppendEntity(dbpt);
                    tr.AddNewlyCreatedDBObject(dbpt, true);
                    tr.Commit();
                    return;
                }
            } while (true);
        }
    }

    protected override SamplerStatus Sampler(JigPrompts prompts)
    {
        var status = SamplerStatus.NoChange;

        var opt = new JigPromptPointOptions("\nMove to:");
        opt.UseBasePoint = true;
        var guideLine1Vector = new Vector3d();
        if(_dim2 is null)
        {
            _basePoint = _guideLine1.GetClosestPointTo(_movingPoint, true);
            _dim1.XLine1Point = _basePoint;
        }
        else
        {
            guideLine1Vector = _dim1.XLine1Point.GetVectorTo(_dim1.XLine2Point);
            var closestPointOnGuideLine1 = _guideLine1.GetClosestPointTo(_movingPoint, true);
            _dim2.XLine2Point = closestPointOnGuideLine1.Add(guideLine1Vector);
            _dim2.XLine1Point = _guideLine2.GetClosestPointTo(_dim2.XLine2Point, true);
            _basePoint = _dim2.XLine1Point;
        }

        opt.BasePoint = _basePoint;
        var res = prompts.AcquirePoint(opt);
        
        if (res.Status == PromptStatus.OK)
        {
            if (!res.Value.Equals(_rawMovingPoint))
            {
                _rawMovingPoint = res.Value;
                if (_dim2 is null)
                {
                    _dim1.XLine2Point = res.Value;
                    _dim1.DimLinePoint = res.Value;
                    var dist = _basePoint.DistanceTo(res.Value).ToString("######0.000");
                    _dim1.DimensionText = dist;
                    _jigEntity.Center = _dim1.XLine2Point;
                    _movingPoint = res.Value;
                }
                else
                {
                    var closestPointOnGuideLine1 = _guideLine1.GetClosestPointTo(res.Value, true);
                    _dim2.XLine2Point = closestPointOnGuideLine1.Add(guideLine1Vector);
                    _dim2.XLine1Point = _guideLine2.GetClosestPointTo(_dim2.XLine1Point, true);
                    var dist = _dim2.XLine1Point.DistanceTo(_dim2.XLine2Point).ToString("######0.000");
                    _dim2.DimensionText = dist;
                    _dim2.DimLinePoint = res.Value;
                    _jigEntity.Center = _dim2.XLine2Point;
                    _movingPoint = _dim2.XLine2Point;
                }
                status = SamplerStatus.OK;
            }
        }
        else
        {
            status = SamplerStatus.Cancel;
        }

        return status;
    }

    protected override bool WorldDraw(WorldDraw draw)
    {
        if (_dim1.ObjectId == ObjectId.Null)
        {
            _dim1.RecomputeDimensionBlock(true);
            draw.Geometry.Draw(_dim1);
        }
        if(_dim2 != null)
        {
            _dim2.RecomputeDimensionBlock(true);
            draw.Geometry.Draw(_dim2);
        }
        return draw.Geometry.Draw(_jigEntity);
    }


    private bool SelectGuideLine()
    {
        var eRes = _ed.GetEntity("\nSelect guide line");
        if (eRes.Status == PromptStatus.OK)
        {
            using (var tr =_dwg.Database.TransactionManager.StartOpenCloseTransaction())
            {
                if (_dim1 is null)
                {
                    _guideLine1 = tr.GetObject(eRes.ObjectId, OpenMode.ForRead) as Line;
                    if (_guideLine1 is null)
                        return false;
                    _basePoint = eRes.PickedPoint;
                }
                else
                {
                    _guideLine2 = tr.GetObject(eRes.ObjectId, OpenMode.ForRead) as Line;
                    if (_guideLine2 is null)
                        return false;
                    _basePoint = _guideLine2.GetClosestPointTo(_dim1.XLine2Point, true);
                    var l = new Line(_basePoint, _dim1.XLine2Point);
                    var md = tr.GetObject(CadApp.DocumentManager.MdiActiveDocument.Database.CurrentSpaceId,
                        OpenMode.ForWrite) as BlockTableRecord;
                }
                tr.Commit();
            }
            return true;
        }
        else
        {
            return false;
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 11 Dec 2024 09:10:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/jig-with-dimension/m-p/13204908#M1553</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2024-12-11T09:10:33Z</dc:date>
    </item>
    <item>
      <title>Betreff: Jig with dimension</title>
      <link>https://forums.autodesk.com/t5/net-forum/jig-with-dimension/m-p/13225007#M1554</link>
      <description>&lt;P&gt;To any one who comes across this post and wants to do some thing similar&lt;/P&gt;&lt;P&gt;here is my last attempt where you can select two lines/polylines to guide an entity movement along two dimensions while jigging:&lt;BR /&gt;this is where to call the drag method of Jig:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public void Move()
{
    if (!SelectGuideLine()) 
        return;

    _movingPoint = _basePoint;

    _dim1 = new AlignedDimension(_basePoint,_movingPoint,Point3d.Origin,
        "0000",_dwg.Database.DimStyleTableId);

    using (var tr =_dwg.Database.TransactionManager.StartTransaction())
    {
        var md = tr.GetObject(_dwg.Database.CurrentSpaceId,OpenMode.ForWrite) as BlockTableRecord;

        do
        {
            var res = _ed.Drag(this);
            if (res.Status != PromptStatus.OK)
                return;
            if (_dim2 == null)
            {
                _dwg.Database.TransactionManager.QueueForGraphicsFlush();
                if (SelectGuideLine())
                {
                    _dim2 = new AlignedDimension(_basePoint,_movingPoint,Point3d.Origin,
                                    "0000",_dwg.Database.DimStyleTableId);
                }
                else
                {
                    tr.Commit();
                    return;
                }
            }
            else
            {
                md.AppendEntity(_dim2);
                tr.AddNewlyCreatedDBObject(_dim2, true);
                md.AppendEntity(_dim1);
                tr.AddNewlyCreatedDBObject(_dim1, true);
                md.AppendEntity(_jigEntity);
                tr.AddNewlyCreatedDBObject(_jigEntity, true);

                tr.Commit();
                return;
            }
        } while (true);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;this is sampler and world draw:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override SamplerStatus Sampler(JigPrompts prompts)
{
    
    var status = SamplerStatus.NoChange;
    _dwg.Database.Orthomode = false;
    var opt = new JigPromptPointOptions("\nMove to:");
    opt.UseBasePoint = true;
    if(_dim2 is null)
    {
        _basePoint = _guideLine1.GetClosestPointTo(_movingPoint, true);
        _dim1.XLine1Point = _basePoint;
    }
    else
    {
        _basePoint = _guideLine2.GetClosestPointTo(_movingPoint, true);
        _dim2.XLine1Point = _basePoint;
    }
    opt.BasePoint = _basePoint;
    var res = prompts.AcquirePoint(opt);
    
    if (res.Status == PromptStatus.OK)
    {
        if (!res.Value.Equals(_rawMovingPoint))
        {
            _rawMovingPoint = res.Value;
            if (_dim2 is null)
            {
                _dim1.XLine2Point = res.Value;
                _dim1.DimLinePoint = res.Value;
                var dist = _basePoint.DistanceTo(res.Value).ToString("######0.000");
                _dim1.DimensionText = dist;
                _jigEntity.Center = _dim1.XLine2Point;
            }
            else
            {
                var dim1Vector = _dim1.XLine1Point.GetVectorTo(_dim1.XLine2Point);
                _dim1.XLine1Point = _guideLine1.GetClosestPointTo(res.Value, true);
                _dim1.XLine2Point = _dim1.XLine1Point.Add(dim1Vector);
                _dim1.DimLinePoint = res.Value;

                _dim2.XLine2Point = res.Value;
                _dim2.DimLinePoint = res.Value;
                var dist = _dim2.XLine1Point.DistanceTo(_dim2.XLine2Point).ToString("######0.000");
                _dim2.DimensionText = dist;
                
                _jigEntity.Center = _dim1.XLine2Point;
            }
            _movingPoint = res.Value;
            status = SamplerStatus.OK;
        }
    }
    else
    {
        status = SamplerStatus.Cancel;
    }

    return status;
}

protected override bool WorldDraw(WorldDraw draw)
{
    if (_dim1.ObjectId == ObjectId.Null)
    {
        _dim1.RecomputeDimensionBlock(true);
        draw.Geometry.Draw(_dim1);
    }
    if(_dim2 != null)
    {
        _dim2.RecomputeDimensionBlock(true);
        draw.Geometry.Draw(_dim2);
        draw.Geometry.Draw(_dim1);
    }
    return draw.Geometry.Draw(_jigEntity);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and this is the method that selects guide lines:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;private bool SelectGuideLine()
{
    var eRes = _ed.GetEntity("\nSelect guide line");
    if (eRes.Status == PromptStatus.OK)
    {
        using (var tr =_dwg.Database.TransactionManager.StartOpenCloseTransaction())
        {
            if (_dim1 is null)
            {
                _guideLine1 = tr.GetObject(eRes.ObjectId, OpenMode.ForRead) as Line;
                if (_guideLine1 is null)
                    return false;
                _basePoint = eRes.PickedPoint;
            }
            else
            {
                _guideLine2 = tr.GetObject(eRes.ObjectId, OpenMode.ForRead) as Line;
                if (_guideLine2 is null)
                    return false;

                _basePoint = _guideLine2.GetClosestPointTo(_dim1.XLine2Point, true);
                var l = new Line(_basePoint, _dim1.XLine2Point);
                var md = tr.GetObject(CadApp.DocumentManager.MdiActiveDocument.Database.CurrentSpaceId,
                    OpenMode.ForWrite) as BlockTableRecord;
            }
            tr.Commit();
        }
        return true;
    }
    else
    {
        return false;
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="akouchakzadeh_0-1734854593666.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1448406i12A96812EA9DB923/image-size/medium?v=v2&amp;amp;px=400" role="button" title="akouchakzadeh_0-1734854593666.png" alt="akouchakzadeh_0-1734854593666.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2024 08:03:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/jig-with-dimension/m-p/13225007#M1554</guid>
      <dc:creator>a.kouchakzadeh</dc:creator>
      <dc:date>2024-12-22T08:03:33Z</dc:date>
    </item>
  </channel>
</rss>

