Author Topic: Jig with Multiple Entities  (Read 3213 times)

0 Members and 1 Guest are viewing this topic.

SomeCallMeDave

  • Guest
Jig with Multiple Entities
« on: December 12, 2007, 06:09:24 PM »
I would like to know if it is possible to 'jig' with multiple entities.  All the code that I have seen uses only a single entity for dragging.

I would like to be able to do something like image below (coded in LISP with grread and grdraw).

Can anyone point me in the right direction?

Thanks

Glenn R

  • Guest
Re: Jig with Multiple Entities
« Reply #1 on: December 12, 2007, 06:31:19 PM »
According to what I suspected and just looked up on ADN, EntityJig is for singles and DrawJig is for multiples. Also, you will have to override WorldDraw and 'draw' your entities (from a list of points you maintain internally) using the graphics device context passed into WorldDraw.

I've never had the need to do this, but if you get stuck, I'll have a go at it myself in the next couple of days.

Hope this helps.

Cheers,
Glenn.

SomeCallMeDave

  • Guest
Re: Jig with Multiple Entities
« Reply #2 on: December 12, 2007, 07:17:08 PM »
Thanks Glenn.   

I may not know how to do it, but at least I know it can be done.  :)

I will dig into DrawJig.

Thanks again

SomeCallMeDave

  • Guest
Re: Jig with Multiple Entities
« Reply #3 on: December 12, 2007, 11:57:43 PM »
Glenn,
Thanks for the nudge in the right direction.  Using your suggestion and some sample code from Bobby Jones and Kean Walmsley I was able to get the circle and the text to  drag.  Next comes the lines (well, bed then the lines).

The code is just a proof of concept and is still very rough, but I would appreciate it if any of the experts could point out the major flaws and any pitfalls that I should be wary of.

Code: [Select]
namespace dkb_GolfJig
{
    /// <summary>
    /// Summary for dkb_GolfJig.
    /// </summary>
    public class dkb_GolfJig
    {
        class GolfJig : DrawJig
        {
            #region Private Member Fields
            private Point3d mRadiusPt;
            private double mRadius;
            private String mRadStr1;
            private String mRadStr2;
            private Boolean mIsTeeBox;
            private Boolean mIsGreen;
            private Circle mCircle;
            private MText mRadText;
            #endregion


            public GolfJig(Point3d pRadPt)
            {
                mRadiusPt = pRadPt;
                mCircle = new Circle(mRadiusPt,new Vector3d(0.0,0.0,1.0),1);
                mRadText = new MText();
                mRadText.Location = mRadiusPt;
                mRadText.Attachment = AttachmentPoint.MiddleCenter;
                mRadText.TextHeight = 5.0;
               
            }//constructor

            protected override SamplerStatus Sampler(JigPrompts prompts)
            {
                JigPromptPointOptions opts = new JigPromptPointOptions();
                opts.UserInputControls = (UserInputControls.Accept3dCoordinates |UserInputControls.NoNegativeResponseAccepted);

                //get the radius Pt
                if (mRadiusPt == null)
                {
                    opts.UserInputControls |= UserInputControls.NullResponseAccepted;
                    opts.Message = "\nPick Radius Pt: ";
                    opts.UseBasePoint = false;

                }
                //else we have a radius pt now we get the radius by dragging
                else if (mRadiusPt != null)
                {
                    opts.UserInputControls |= UserInputControls.NullResponseAccepted;
                    opts.Message = "\nEnter Radius: ";
                    opts.UseBasePoint = true;
                    opts.BasePoint = mRadiusPt;
                }
                else
                    return SamplerStatus.Cancel;

                PromptPointResult pRes = prompts.AcquirePoint(opts);

                if (pRes.Status == PromptStatus.Cancel)
                {
                    return SamplerStatus.Cancel;
                }
                if (mRadiusPt.DistanceTo(pRes.Value) == mRadius)
                {
                    return SamplerStatus.NoChange;
                }
                else if (pRes.Status == PromptStatus.OK)
                {
                    mRadius = mRadiusPt.DistanceTo(pRes.Value);
                    mCircle.Radius = mRadius;
                    double radiusYards = mRadius/3.0;
                    mRadText.Contents = "Radius=" + mRadius.ToString("N02")+"'\n" + radiusYards.ToString("N02")+ " yards";
                    return SamplerStatus.OK;
                }
                return SamplerStatus.Cancel;
            }// samplerStatus

            protected override bool  WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
            {
                draw.Geometry.Draw(mCircle);
                draw.Geometry.Draw(mRadText);
                return true;
            }

        } //class
        [CommandMethod("golfTest")]
        public void golfTest()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointResult pRes = ed.GetPoint("\nPick Radius Point: ");

            if (pRes.Status == PromptStatus.OK)
            {
                GolfJig gJig = new GolfJig(pRes.Value);
                PromptResult dragRes = ed.Drag(gJig);


            }
        }
    }
}


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Jig with Multiple Entities
« Reply #4 on: December 13, 2007, 12:08:40 AM »
Quote
namespace dkb_GolfJig

Dave,
Is this in shares with Greg Norman and Tiger Woods ??



 
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

SomeCallMeDave

  • Guest
Re: Jig with Multiple Entities
« Reply #5 on: December 13, 2007, 12:19:22 AM »
Not yet.  Do you have Greg's email address?  :)

Glenn R

  • Guest
Re: Jig with Multiple Entities
« Reply #6 on: December 13, 2007, 02:07:39 PM »
Another approach you can use in the WorlDraw callback, is something like this:

Code: [Select]
draw.Geometry.Line(blah blah);

So you're using the graphics context to draw the primitives directly. This would rely on you keeping all the points for all the objects you want to draw, as I mentioned earlier.

The other approach is what you've done - create new non db resident objects and just draw those.
Let us know how you get on.

Cheers,
Glenn.

SomeCallMeDave

  • Guest
Re: Jig with Multiple Entities
« Reply #7 on: December 13, 2007, 03:18:59 PM »
As it stands now, I have created a List<Entity> and each segment for the Jig class is responsible clearing the list then  putting the appropriate entities in it for WorldDraw.

Then the calling command  can use a Jig.getEnts function to retrieve the list and add all the 'dragged' entities to the working database with a foreach loop.

That was the way that I first stumbled upon.  It seems to work well because I don't have clean up any entities that are being dragged when the user hits escape.

But I don't know if it is an efficient way to handle the situation.

Any comments or suggestions?

Glenn R

  • Guest
Re: Jig with Multiple Entities
« Reply #8 on: December 14, 2007, 04:28:45 AM »
None. What you're doing is fine. EntityJig works essentially the same way, but with only one entity - this is just more than one, so the same principle applies.

Just remember, that if the user hits escape, Dispose() of any non db resident objects that you're still holding onto. just because it's a managed enviroment, doesn't mean you should leave all housekeeping to the runtime and with respect to AutoCAD, there are definately situations where NOT cleaning up after yourself has some very bad consequences.

Cheers,
Glenn.