Graphical user input

Graphical user input

prahtYHGMJ
Explorer Explorer
447 Views
2 Replies
Message 1 of 3

Graphical user input

prahtYHGMJ
Explorer
Explorer

What technics needs to be used to get user input like in OFFSET command.

If cursor are in one side of line - first option,

cursor are in other side of line - second option.

So far I am using PointMonitorEventHandler() and TransientManager() to draw what user will get,

after he makes a choice, but I am stuck at distinguishing what side of line are cursor.

It's in 3d space and line can be at any random position. I have a Plane() on which line resides.

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

_gile
Consultant
Consultant
Accepted solution

Hi,

Here's an example using a Jig (instead of PointMonitorEventHandler and TransientManager).

The jigged perpendicular line is red or green according to the side of the source line the cursor is. The reference vector is the current view direction.

 

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

            var options = new PromptEntityOptions("\nSelect line: ");
            options.SetRejectMessage("\nSelected entity is not a line.");
            options.AddAllowedClass(typeof(Line), true);
            var result = ed.GetEntity(options);
            if (result.Status != PromptStatus.OK)
                return;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var axis = (Line)tr.GetObject(result.ObjectId, OpenMode.ForRead);
                using (var perp = new Line(Point3d.Origin, axis.GetClosestPointTo(Point3d.Origin, true)))
                {
                    var jig = new PerpendicularJig(perp, axis, ed);
                    var pr = ed.Drag(jig);
                    if (pr.Status == PromptStatus.OK)
                    {
                        var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                        curSpace.AppendEntity(perp);
                        tr.AddNewlyCreatedDBObject(perp, true);
                    }
                }
                tr.Commit();
            }
        }
    }

    class PerpendicularJig : EntityJig
    {
        Point3d dragPoint;
        Line axis, perp;
        Vector3d axisDir;
        Editor ed;

        public PerpendicularJig(Line perp, Line axis, Editor ed) : base(perp)
        {
            this.axis = axis;
            this.perp = perp;
            axisDir = axis.StartPoint.GetVectorTo(axis.EndPoint);
            this.ed = ed;
        }

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

        protected override bool Update()
        {
            using (var view = ed.GetCurrentView())
            {
                var viewDir = view.ViewDirection;
                perp.StartPoint = dragPoint;
                perp.EndPoint = axis.GetClosestPointTo(dragPoint, viewDir, true);
                var xform = Matrix3d.WorldToPlane(viewDir);
                var v1 = axisDir.ProjectTo(viewDir, viewDir);
                var v2 = perp.EndPoint.GetVectorTo(dragPoint).ProjectTo(viewDir, viewDir);
                perp.ColorIndex = v1.GetAngleTo(v2, viewDir) < Math.PI ? 1 : 3;
            }
            return true;
        }
    }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

prahtYHGMJ
Explorer
Explorer
Thank You
0 Likes