Jigging between two points

Jigging between two points

Anonymous
Not applicable
1,173 Views
2 Replies
Message 1 of 3

Jigging between two points

Anonymous
Not applicable

Hi,

 

My requirement is like I have to get a block on cursor and move it only along x-axis between two points. As of now I am able to drag anywhere, instead of x-axis and between two points restriction. could you please give some reference on this.

 

Thanks in advance.

Tejaswini

0 Likes
Accepted solutions (1)
1,174 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant
Accepted solution

Hi,

 

Here's a simple example (just replace "blockName" with the block name).

 

        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                if (!bt.Has("blockName"))
                    return;
                using (var br = new BlockReference(Point3d.Origin, bt["blockName"]))
                {
                    br.TransformBy(ed.CurrentUserCoordinateSystem);
                    var jig = new BlockJig(br, Point3d.Origin, new Point3d(10.0, 0.0, 0.0));
                    var pr = ed.Drag(jig);
                    if (pr.Status == PromptStatus.OK)
                    {
                        var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                        curSpace.AppendEntity(br);
                        tr.AddNewlyCreatedDBObject(br, true);
                    }
                        }
                tr.Commit();
            }
        }

        class BlockJig : EntityJig
        {
            BlockReference br;
            LineSegment3d line;
            Point3d dragPt;

            public BlockJig(BlockReference br, Point3d pt1, Point3d pt2) : base(br)
            {
                this.br = br;
                line = new LineSegment3d(pt1, pt2);
            }

            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                var options = new JigPromptPointOptions("\nInsertion point: ");
                options.UserInputControls = 
                    UserInputControls.Accept3dCoordinates | 
                    UserInputControls.UseBasePointElevation;
                var result = prompts.AcquirePoint(options);
                if (result.Value.IsEqualTo(dragPt))
                    return SamplerStatus.NoChange;
                dragPt = result.Value;
                return SamplerStatus.OK;
            }

            protected override bool Update()
            {
                br.Position = line.GetClosestPointTo(dragPt).Point;
                return true;
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi,

 

Thanks for the solution, It is very useful. But I am implementing using Drawjig instead of entityJig. Is there any equivalent method for Update in Drawjig as update method is not available in Drawjig class.

 

Thanks in advance.


@_gile wrote:

Hi,

 

Here's a simple example (just replace "blockName" with the block name).

 

        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                if (!bt.Has("blockName"))
                    return;
                using (var br = new BlockReference(Point3d.Origin, bt["blockName"]))
                {
                    br.TransformBy(ed.CurrentUserCoordinateSystem);
                    var jig = new BlockJig(br, Point3d.Origin, new Point3d(10.0, 0.0, 0.0));
                    var pr = ed.Drag(jig);
                    if (pr.Status == PromptStatus.OK)
                    {
                        var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                        curSpace.AppendEntity(br);
                        tr.AddNewlyCreatedDBObject(br, true);
                    }
                        }
                tr.Commit();
            }
        }

        class BlockJig : EntityJig
        {
            BlockReference br;
            LineSegment3d line;
            Point3d dragPt;

            public BlockJig(BlockReference br, Point3d pt1, Point3d pt2) : base(br)
            {
                this.br = br;
                line = new LineSegment3d(pt1, pt2);
            }

            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                var options = new JigPromptPointOptions("\nInsertion point: ");
                options.UserInputControls = 
                    UserInputControls.Accept3dCoordinates | 
                    UserInputControls.UseBasePointElevation;
                var result = prompts.AcquirePoint(options);
                if (result.Value.IsEqualTo(dragPt))
                    return SamplerStatus.NoChange;
                dragPt = result.Value;
                return SamplerStatus.OK;
            }

            protected override bool Update()
            {
                br.Position = line.GetClosestPointTo(dragPt).Point;
                return true;
            }
        }


@_gile wrote:

Hi,

 

Here's a simple example (just replace "blockName" with the block name).

 

        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            using (var tr = db.TransactionManager.StartTransaction())
            {
                var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                if (!bt.Has("blockName"))
                    return;
                using (var br = new BlockReference(Point3d.Origin, bt["blockName"]))
                {
                    br.TransformBy(ed.CurrentUserCoordinateSystem);
                    var jig = new BlockJig(br, Point3d.Origin, new Point3d(10.0, 0.0, 0.0));
                    var pr = ed.Drag(jig);
                    if (pr.Status == PromptStatus.OK)
                    {
                        var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                        curSpace.AppendEntity(br);
                        tr.AddNewlyCreatedDBObject(br, true);
                    }
                        }
                tr.Commit();
            }
        }

        class BlockJig : EntityJig
        {
            BlockReference br;
            LineSegment3d line;
            Point3d dragPt;

            public BlockJig(BlockReference br, Point3d pt1, Point3d pt2) : base(br)
            {
                this.br = br;
                line = new LineSegment3d(pt1, pt2);
            }

            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                var options = new JigPromptPointOptions("\nInsertion point: ");
                options.UserInputControls = 
                    UserInputControls.Accept3dCoordinates | 
                    UserInputControls.UseBasePointElevation;
                var result = prompts.AcquirePoint(options);
                if (result.Value.IsEqualTo(dragPt))
                    return SamplerStatus.NoChange;
                dragPt = result.Value;
                return SamplerStatus.OK;
            }

            protected override bool Update()
            {
                br.Position = line.GetClosestPointTo(dragPt).Point;
                return true;
            }
        }

 

0 Likes