Make a jig of aligned dimensions

BIM_VIET
Enthusiast
Enthusiast

Make a jig of aligned dimensions

BIM_VIET
Enthusiast
Enthusiast

Dear All,

I want to make a collection of aligned Dimension by make a Fence selection intersect with some line or polyline.

Step 1: I got the the collection of intersection points,

Step 2: Please help how to make a jig of aligned dimensions like picture below:

 

BIM_VIET_0-1671097008468.png

 

0 Likes
Reply
Accepted solutions (1)
505 Views
5 Replies
Replies (5)

_gile
Mentor
Mentor

Hi,

 

Here's an example:

        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var options = new PromptPointOptions("\nFirst point: ");
            var result = ed.GetPoint(options);
            if (result.Status != PromptStatus.OK) return;
            var pt1 = result.Value;

            options.Message = "\nSecond point: ";
            options.UseBasePoint = true;
            options.BasePoint = pt1;
            result = ed.GetPoint(options);
            if (result.Status != PromptStatus.OK) return;
            var pt2 = result.Value;

            var fence = new Point3dCollection(new[] { pt1, pt2 });
            var filter = new SelectionFilter(new[] { new TypedValue(0, "LINE,LWPOLYLINE") });
            var selection = ed.SelectFence(fence, filter);
            if (selection.Status != PromptStatus.OK) return;

            using (var tr = db.TransactionManager.StartTransaction())
            using (var line = new Line(pt1, pt2))
            {
                line.TransformBy(ed.CurrentUserCoordinateSystem);
                var points = new Point3dCollection();
                foreach (ObjectId id in selection.Value.GetObjectIds())
                {
                    var curve = (Curve)tr.GetObject(id, OpenMode.ForRead);
                    curve.IntersectWith(line, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero);
                }

                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var dims = new List<AlignedDimension>();
                for (int i = 0; i < points.Count - 1; i++)
                {
                    var dim = new AlignedDimension(points[i], points[i + 1], points[i], "", db.Dimstyle);
                    curSpace.AppendEntity(dim);
                    tr.AddNewlyCreatedDBObject(dim, true);
                    dims.Add(dim);
                }

                var jig = new AlignedDimensionsJig(dims);
                var pr = ed.Drag(jig);
                if (pr.Status != PromptStatus.OK)
                {
                    foreach (var dim in dims)
                    {
                        dim.Erase();
                    }
                }
                tr.Commit();
            }
        }

        class AlignedDimensionsJig : DrawJig
        {
            List<AlignedDimension> dims;
            Point3d dragPoint;
            public AlignedDimensionsJig(List<AlignedDimension> dims)
            { this.dims = dims; }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                var options = new JigPromptPointOptions("\nSpecify Dimension Line Location: ");
                options.UserInputControls =
                    UserInputControls.Accept3dCoordinates | UserInputControls.GovernedByUCSDetect;
                var result = prompts.AcquirePoint(options);
                if (result.Value.IsEqualTo(dragPoint)) return SamplerStatus.NoChange;
                dragPoint = result.Value;
                return SamplerStatus.OK;
            }
            protected override bool WorldDraw(WorldDraw draw)
            {
                foreach (var dim in dims)
                {
                    dim.DimLinePoint = dragPoint;
                    dim.Draw();
                }
                return true;
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

_gile
Mentor
Mentor
Accepted solution

In a more conventional way (entities are added to the Database only if the Jig result is OK).

        [CommandMethod("TEST")]
        public static void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            var options = new PromptPointOptions("\nFirst point: ");
            var result = ed.GetPoint(options);
            if (result.Status != PromptStatus.OK) return;
            var pt1 = result.Value;

            options.Message = "\nSecond point: ";
            options.UseBasePoint = true;
            options.BasePoint = pt1;
            result = ed.GetPoint(options);
            if (result.Status != PromptStatus.OK) return;
            var pt2 = result.Value;

            var fence = new Point3dCollection(new[] { pt1, pt2 });
            var filter = new SelectionFilter(new[] { new TypedValue(0, "LINE,LWPOLYLINE") });
            var selection = ed.SelectFence(fence, filter);
            if (selection.Status != PromptStatus.OK) return;

            using (var tr = db.TransactionManager.StartTransaction())
            using (var line = new Line(pt1, pt2))
            {
                line.TransformBy(ed.CurrentUserCoordinateSystem);
                var points = new Point3dCollection();
                foreach (ObjectId id in selection.Value.GetObjectIds())
                {
                    var curve = (Curve)tr.GetObject(id, OpenMode.ForRead);
                    curve.IntersectWith(line, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero);
                }

                var dims = new List<AlignedDimension>();
                for (int i = 0; i < points.Count - 1; i++)
                {
                    var dim = new AlignedDimension(points[i], points[i + 1], points[i], "", db.Dimstyle);
                    dim.SetDatabaseDefaults();
                    dims.Add(dim);
                }

                var jig = new AlignedDimensionsJig(dims);
                var pr = ed.Drag(jig);
                if (pr.Status == PromptStatus.OK)
                {
                    var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    foreach (var dim in dims)
                    {
                        curSpace.AppendEntity(dim);
                        tr.AddNewlyCreatedDBObject(dim, true);
                    }
                }
                else
                {
                    foreach (var dim in dims)
                    {
                        dim.Dispose();
                    }
                }
                tr.Commit();
            }
        }

        class AlignedDimensionsJig : DrawJig
        {
            List<AlignedDimension> dims;
            Point3d dragPoint;
            public AlignedDimensionsJig(List<AlignedDimension> dims)
            { this.dims = dims; }
            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                var options = new JigPromptPointOptions("\nSpecify Dimension Line Location: ");
                options.UserInputControls =
                    UserInputControls.Accept3dCoordinates | UserInputControls.GovernedByUCSDetect;
                var result = prompts.AcquirePoint(options);
                if (result.Value.IsEqualTo(dragPoint)) return SamplerStatus.NoChange;
                dragPoint = result.Value;
                return SamplerStatus.OK;
            }
            protected override bool WorldDraw(WorldDraw draw)
            {
                var geometry = draw.Geometry;
                if (geometry != null)
                {
                    foreach (var dim in dims)
                    {
                        dim.DimLinePoint = dragPoint;
                        geometry.Draw(dim);
                    }
                }
                return true;
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

BIM_VIET
Enthusiast
Enthusiast

Dear @_gile ,

Thank you for your code. it run perfectly.

Now I would like to update a Jig with Aligned Dimension & Arc Length Dimension when pick 1 or more polylines as the picture below, Please help how to do that.

BIM_VIET_0-1671163064512.png

 

0 Likes

_gile
Mentor
Mentor

Didn't my first replies help you ?

You should be able to adapt the above code to fit your new request.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

BIM_VIET
Enthusiast
Enthusiast

hi @_gile ,

Yes your code is help me in first one. thank you very much

 

0 Likes