.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rubber band and Jig. I's a balloon.

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
HelloWorlddd
2211 Views, 4 Replies

Rubber band and Jig. I's a balloon.

   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

4 REPLIES 4
Message 2 of 5
norman.yuan
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;

 

 

Message 3 of 5
HelloWorlddd
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

Message 4 of 5
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 5
HelloWorlddd
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

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost