.NET

Reply
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 1 of 5 (641 Views)
Accepted Solution

Rubber band and Jig. I's a balloon.

641 Views, 4 Replies
12-23-2013 06:15 AM

   I thought if I got a man and a woman I can constitute my dream world, but my world is the result of men and women can not exist simultaneously

 

   Okay let’s back to the topic, first I know how to produce the effect of a rubber band, I just need to set those two properties, such as

     promptOptionsOjb.UseBasePoint = true;

     promptOptionsOjb.BasePoint = lineStartPoint3D;  

 

   Then I knew the effect of Jig class, this is my last question about Jig effect, there is a very good friend gave me a sample code, you can click this link to view the last question of mine. http://forums.autodesk.com/t5/NET/Is-this-a-ghost/m-p/4709915#M38307

 

   Finally, I try to combine the two effect  together, to achieve my SmartTag, due to the end of the line is associated with the center of the circle, so I try to use the following code to implement this idea

 

   After running,  it only have Jig effect, without rubber band effect, I need both of the effects, the effect is actually look like MultiLeader effect, or that looks similar with stretch command.

 

   Users operational processes:
   1, Execute the command, the program asks the user to select a base point,
   2, Then the mouse is free to move, but the cursor position has a radius of circle 3, and a straight line from the base point to the center point, but does not pass through the circle, just connect the circle, it will like a rubber band

 

Hope to get your help, sincerely thank

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;

namespace DragCircleSample
{
    public class CommandMethods
    {
        [CommandMethod("RJ")]
        public void DragCircle()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptPointOptions pPtOpts = new PromptPointOptions("\nSpecify the first point of line: ");

            //Prompt for the start point
            PromptPointResult promptPointResultObj = doc.Editor.GetPoint(pPtOpts);
            Point3d lineStartPoint3D = promptPointResultObj.Value;
            Point2d lineStartPoint2D = new Point2d(lineStartPoint3D.X, lineStartPoint3D.Y);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                Circle circle = new Circle(Point3d.Origin, Vector3d.ZAxis, 3.0);
                CircleJig jig = new CircleJig(circle, lineStartPoint3D);
                PromptResult pr = ed.Drag(jig);
                if (pr.Status == PromptStatus.OK)
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    btr.AppendEntity(circle);
                    tr.AddNewlyCreatedDBObject(circle, true);

                    Point3d realLineEndPoint3D = circle.Center;
                    Point2d theRealLineEndPoint2D = new Point2d(realLineEndPoint3D.X, realLineEndPoint3D.Y);

                    //Length
                    double overallLength = lineStartPoint3D.DistanceTo(realLineEndPoint3D);
                    double realLength = overallLength - 3;

                    //Angle
                    double angle = lineStartPoint2D.GetVectorTo(theRealLineEndPoint2D).Angle;

                    //Get the cross point of line and circle
                    Point2d crossingPoint2D = new Point2d(lineStartPoint2D.X + realLength * Math.Cos(angle), lineStartPoint2D.Y + realLength * Math.Sin(angle));
                    Point3d crossingPoint3D = new Point3d(crossingPoint2D.X, crossingPoint2D.Y, 0);

                    //Define the new line
                    Line acLine = new Line(lineStartPoint3D, crossingPoint3D);
                    acLine.SetDatabaseDefaults();

                    //Add the line to the drawing
                    ObjectId acLineId = btr.AppendEntity(acLine);
                    tr.AddNewlyCreatedDBObject(acLine, true);

                    tr.Commit();
                }
            }
        }

        class CircleJig : EntityJig
        {
            Circle circle;
            Point3d center;
            Point3d lineStartPoint3D;

            public CircleJig(Circle circle, Point3d lineStartPoint3D)
                : base(circle)
            {

                    this.lineStartPoint3D=lineStartPoint3D;
                this.circle = circle;
                this.center = circle.Center;
            }

            protected override bool Update()
            {
                circle.Center = center;
                return true;
            }

            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions jigPromptOptionsOjb = new JigPromptPointOptions();
                jigPromptOptionsOjb.Message = "\nSpecify the first circle center: ";

                jigPromptOptionsOjb.UseBasePoint = true;                 //trying to use the two line of code 
                jigPromptOptionsOjb.BasePoint = lineStartPoint3D;        //implement the rubber band effect..

                PromptPointResult ppr = prompts.AcquirePoint(jigPromptOptionsOjb);
                if (ppr.Value.DistanceTo(center) < Tolerance.Global.EqualPoint)
                    return SamplerStatus.NoChange;
                center = ppr.Value;
                return SamplerStatus.OK;
            }
        }
    }
}

 

 

 Jig effect

*Expert Elite*
norman.yuan
Posts: 959
Registered: ‎04-27-2009
Message 2 of 5 (620 Views)

Re: Rubber band and Jig. I's a balloon.

12-23-2013 07:20 AM in reply to: HelloWorlddd

If you mean to have arubberband line while user drags the entity, you can have it easily:

 

In the overriden Jampler() method, set

 

JigPromptPointOptions.Cursor=CursorType.Rubberband;

 

 

Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 3 of 5 (607 Views)

Re: Rubber band and Jig. I's a balloon.

12-23-2013 09:10 AM in reply to: norman.yuan

   It is much better, but not quite what I want.

   Just need to think the stretch commands inside AutoCAD.

   If this balloon tag to be used this command

   The line of the balloon tag will be stretch. The cirle will move free. And the line point to the circle center always. The line does not pass through the circle, just connected always The line is a real line, it has the same layer with the circle..

   My English is not very good, I hope you can understand, thank you very much

*Expert Elite*
_gile
Posts: 2,077
Registered: ‎04-29-2006
Message 4 of 5 (580 Views)

Re: Rubber band and Jig. I's a balloon.

12-23-2013 01:02 PM in reply to: HelloWorlddd

If I don't misunderstand what you want to do, you'd have ti use anther kind of Jig derived from DrawJig which allows to "jig" more than one entity.

The task is a little more complex because it would not apply the same transformations to the circle (displacement only) and to the line (scaling and rotation).

To make this easier, the input circle center would be the specified start point. The input line would start at this same point, have a 1.0 length (for scaling) and be oriented on X axis (rotation).

 

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace DragBalloonSample
{
    public class CommandMethods
    {
        [CommandMethod("RJ")]
        public void DragBalloon()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptPointResult ppr = doc.Editor.GetPoint("\nSpecify the first point of line: ");
            if (ppr.Status != PromptStatus.OK)
                return;
            Point3d basePt = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);

            using (Transaction tr = db.TransactionManager.StartTransaction())
            using (Circle circle = new Circle(basePt, Vector3d.ZAxis, 3.0))
            using (Line line = new Line(basePt, basePt + Vector3d.XAxis))
            {
                BalloonJig jig = new BalloonJig(circle, line);
                PromptResult pr = ed.Drag(jig);
                if (pr.Status == PromptStatus.OK)
                {
                    circle.TransformBy(jig.Displacement);
                    line.TransformBy(jig.RotateScale);
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    btr.AppendEntity(circle);
                    tr.AddNewlyCreatedDBObject(circle, true);
                    btr.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                }
                tr.Commit();
            }
        }

        class BalloonJig : DrawJig
        {
            private Circle circle;
            private Line line;
            private double radius;
            private Point3d basePoint, center;

            public Matrix3d Displacement { get; private set; }
            public Matrix3d RotateScale { get; private set; }

            public BalloonJig(Circle circle, Line line)
            {
                this.circle = circle;
                this.radius = circle.Radius;
                this.line = line;
                this.basePoint = line.StartPoint;
            }

            protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
            {
                Autodesk.AutoCAD.GraphicsInterface.WorldGeometry geo = draw.Geometry;
                if (geo != null)
                {
                    geo.PushModelTransform(Displacement);
                    geo.Draw(circle);
                    geo.PopModelTransform();
                    geo.PushModelTransform(RotateScale);
                    geo.Draw(line);
                    geo.PopModelTransform();
                }
                return true;
            }

            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions opts =
                    new JigPromptPointOptions("\nSpecify the circle center: ");
                opts.UserInputControls = UserInputControls.NullResponseAccepted;
                PromptPointResult ppr = prompts.AcquirePoint(opts);
                if (ppr.Value.DistanceTo(center) < Tolerance.Global.EqualPoint)
                    return SamplerStatus.NoChange;
                center = ppr.Value;
                Vector3d disp = basePoint.GetVectorTo(center);
                double angle = Vector3d.XAxis.GetAngleTo(disp, Vector3d.ZAxis);
                double scale = basePoint.DistanceTo(center) - radius;
                Displacement = Matrix3d.Displacement(disp);
                RotateScale =
                    Matrix3d.Rotation(angle, Vector3d.ZAxis, basePoint) *
                    Matrix3d.Scaling(scale, basePoint);
                return SamplerStatus.OK;
            }
        }
    }
}

 

Gilles Chanteau
Valued Contributor
HelloWorlddd
Posts: 87
Registered: ‎05-03-2013
Message 5 of 5 (548 Views)

Re: Rubber band and Jig. I's a balloon.

12-24-2013 07:19 AM in reply to: _gile

   It’s you, ah, thank you very much, I've Integrate the DrawJig class into my program, it’s running correctly, but I still do not understand Jig class detail, because AutoCAD Managed Class Reference in the ObjectARX for AutoCAD havn’t provide much detial about the Jig class, the EntityJig class and the DrawJig class.

   Now, I'm want to in-depth understanding of how the class Jig run, I want to fully understand this class, Can you provide me some references?       

   In addition, I added a new topic, I hope you can take a look.

   Sincere thanks,  Merry Christmas

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community