Author Topic: acedSSGet wrapper  (Read 5505 times)

0 Members and 1 Guest are viewing this topic.

Draftek

  • Guest
acedSSGet wrapper
« on: October 09, 2008, 03:43:41 PM »
Code: [Select]
// Selects entity passing through point (5,5).
acedSSGet(NULL, pt2, NULL, NULL, ssname);

I'm racking my brain trying to figure out how to do this with .net. I have a point3D and I want to select the entity that passes through it.

Any ideas?

TonyT

  • Guest
Re: acedSSGet wrapper
« Reply #1 on: October 09, 2008, 08:17:36 PM »
Code: [Select]
// Selects entity passing through point (5,5).
acedSSGet(NULL, pt2, NULL, NULL, ssname);

I'm racking my brain trying to figure out how to do this with .net. I have a point3D and I want to select the entity that passes through it.

Any ideas?

This may be release-dependent i think, but have you tried the Editor's
GetNestedEntity() method, setting the NonInteractivePickPoint and
UseNonInteractivePickPoint properties?

Bryco

  • Water Moccasin
  • Posts: 1883
Re: acedSSGet wrapper
« Reply #2 on: October 10, 2008, 12:46:30 AM »
If that doesn't work try this
Code: [Select]
       static public bool CursorSelectionSet(ref SelectionSet ss,Point3d p)
        {

            Document doc=cad.DocumentManager.MdiActiveDocument;
            Editor ed=doc.Editor;
            Point3dCollection pts = CursorPts(p,ed);
            PromptSelectionOptions sso = new PromptSelectionOptions();
            sso.AllowDuplicates = false;
            PromptSelectionResult psr = ed.SelectCrossingWindow(pts[0], pts[1]);
            if (psr.Status != PromptStatus.OK) return false;
            ss = psr.Value;
            return true;
        }


        static public bool CursorSelectionSet(ref SelectionSet ss, Point3d p,SelectionFilter sf)
        {
            Document doc = cad.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Point3dCollection pts = CursorPts(p, ed);
            PromptSelectionOptions sso = new PromptSelectionOptions();
            sso.AllowDuplicates = false;
            PromptSelectionResult psr = ed.SelectCrossingWindow(pts[0], pts[1], sf);
            if (psr.Status != PromptStatus.OK) return false;
            ss = psr.Value;
            return true;

        }

        static private Point3dCollection CursorPts(Point3d p,Editor ed)
        {
            double sc = Screensize().Y;
            double ht = Viewsize();
            double d = (Pickbox() / sc) * ht;
            Matrix3d ucs = ed.CurrentUserCoordinateSystem;
            Point3d u = p.TransformBy(ucs.Inverse());
            Point3d p1 = new Point3d(u.X - d, u.Y - d, u.Z).TransformBy(ucs);
            Point3d p2 = new Point3d(u.X + d, u.Y + d, u.Z).TransformBy(ucs);
            Point3dCollection pts = new Point3dCollection();
            pts.Add (p1); pts.Add(p2);
            return pts;
        }


        static public int Pickbox()
        {
            //("pickbox")=pixels
            return (int)(Int16)(cad.GetSystemVariable("Pickbox"));
        }

        static public Point2d Screensize()
        {
            //Screensize stores current viewport in pixels (x,y)
            return (Point2d)cad.GetSystemVariable("Screensize");
        }


        static public double Viewsize()
        {
            //("viewsize")=Stores the height
            //of the view in the current viewport. Expressed in drawing units
            return (double)cad.GetSystemVariable("viewsize");
        }
call it with
            SelectionSet ss = null;
            TypedValue[] filterList = { new TypedValue(0, "INSERT") };
            SelectionFilter sf = new SelectionFilter(filterList);
            if (SSets.SSets.CursorSelectionSet(ref ss, pickedpoint, sf))
            {
                //yada yada

            }


It's not too elegant but it is related to how a pickbox works
« Last Edit: October 10, 2008, 12:51:31 AM by Bryco »

Draftek

  • Guest
Re: acedSSGet wrapper
« Reply #3 on: October 10, 2008, 05:53:41 AM »
Thanks guys,

I'll try them out - Tony's first and yours, Bryco and let you know.

I'm off today, the weather is good so I'm going to give the Harley a workout in Northwest Arkansas.....

See you Monday.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: acedSSGet wrapper
« Reply #4 on: October 10, 2008, 02:18:38 PM »
I was about to post a question on how to select items in an xref, using a window like the trim command does.
It treats everything as active, so individual lines and things get selected from xrefs, not whole xref.
I have routines to select xref stuff from nentsel calls in lisp, but crossing windows grab the whole xref.

So I am wondering if the .net API has a selection technique that allows xref stuff to be selected.
thanks
James Maeding

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: acedSSGet wrapper
« Reply #5 on: October 10, 2008, 06:07:56 PM »
I was about to post a question on how to select items in an xref, using a window like the trim command does.
It treats everything as active, so individual lines and things get selected from xrefs, not whole xref.
I have routines to select xref stuff from nentsel calls in lisp, but crossing windows grab the whole xref.

So I am wondering if the .net API has a selection technique that allows xref stuff to be selected.
thanks

James, have a play with these

http://www.theswamp.org/index.php?topic=13749.0;all
http://through-the-interface.typepad.com/through_the_interface/2006/12/highlighting_an.html
http://through-the-interface.typepad.com/through_the_interface/2006/12/highlighting_a_.html
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: acedSSGet wrapper
« Reply #6 on: October 10, 2008, 06:18:05 PM »


also, from the SDK  ..
.... \ObjectARX 2008\samples\dotNet\Prompts\....
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.

Draftek

  • Guest
Re: acedSSGet wrapper
« Reply #7 on: October 14, 2008, 10:51:56 AM »
Thanks Tony,

That worked perfectly:
Code: [Select]
static public ObjectId GetEntityAtPoint(Point3d pickedPt)
        {
            ObjectId id = new ObjectId();
            try
            {
                Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
                PromptNestedEntityOptions pNEo = new PromptNestedEntityOptions("\nSome Prompt Text you will Never SEE!");
                pNEo.UseNonInteractivePickPoint = true;
                pNEo.NonInteractivePickPoint = pickedPt;
                PromptNestedEntityResult pEr = ed.GetNestedEntity(pNEo);
                id = pEr.ObjectId;
            }
            catch { }
            return id;
        }

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: acedSSGet wrapper
« Reply #8 on: October 14, 2008, 01:24:17 PM »
I think the TTI articles are on selecting items with single picks.
I am talking about selecting with a crossing or inside window.
Only the trim (and extend) command does this, and its super, super useful in many things I do.
Currently, I make users select via single picks when picking xref stuff.
thx
James Maeding

TonyT

  • Guest
Re: acedSSGet wrapper
« Reply #9 on: October 15, 2008, 02:42:59 AM »
Glad it worked for you.

Regarding the use of try/catch, its generally good practice to avoid
empty catch blocks. That's functionally the same as using 'On Error
Resume Next' in VB/VBA, and is also a source of many bugs.

If you don't expect an exeption, don't try to catch them, because any
exception you didn't expect should stop your program, rather than let
it continue running.

If you are expecting an exception, then catch the specific exception
type, or catch a System.Exception and test it to see if it is what you
expect. If it is not, then call throw;

Thanks Tony,

That worked perfectly:
Code: [Select]
static public ObjectId GetEntityAtPoint(Point3d pickedPt)
        {
            ObjectId id = new ObjectId();
            try
            {
                Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
                PromptNestedEntityOptions pNEo = new PromptNestedEntityOptions("\nSome Prompt Text you will Never SEE!");
                pNEo.UseNonInteractivePickPoint = true;
                pNEo.NonInteractivePickPoint = pickedPt;
                PromptNestedEntityResult pEr = ed.GetNestedEntity(pNEo);
                id = pEr.ObjectId;
            }
            catch { }
            return id;
        }

Draftek

  • Guest
Re: acedSSGet wrapper
« Reply #10 on: October 15, 2008, 10:12:52 AM »
Thanks for the advice, I'll definitely follow it.

What do you think of using a global error return enum like objectARX does?

I really need to get organized....

TonyT

  • Guest
Re: acedSSGet wrapper
« Reply #11 on: October 15, 2008, 04:53:12 PM »
Sorry, I wrote a rather lengthy response to this, but this dumb forum
software let me accidently naviagate away from the page, and I lost it. :(

The abridged version is that I would merely return ObjectId.Null if
no object was found at the point (which is what your code does).
In this case, there's little need for a try/catch block because there's
no exceptions thrown by any of those APIs you call in that method.

Thanks for the advice, I'll definitely follow it.

What do you think of using a global error return enum like objectARX does?

I really need to get organized....
« Last Edit: October 15, 2008, 04:59:45 PM by TonyT »

Draftek

  • Guest
Re: acedSSGet wrapper
« Reply #12 on: October 16, 2008, 08:05:17 AM »
Okay, cool!

I'm kinda on the right track then.

The more I think about setting up a global error enum, I don't like it.

Thanks

itcad

  • Guest
Re: acedSSGet wrapper
« Reply #13 on: November 02, 2008, 05:04:07 AM »
Code: [Select]
// Selects entity passing through point (5,5).
acedSSGet(NULL, pt2, NULL, NULL, ssname);

I'm racking my brain trying to figure out how to do this with .net. I have a point3D and I want to select the entity that passes through it.

Any ideas?

           [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,
            EntryPoint = "acedGetString")]
            extern static public int acedGetString(int cronly, string  prompt,ref  string  result);
            public string LhAcedGetString()
            {
                string a="";
                acedGetString(0, "enter a string :",ref a);
                return a;
            }

but,it has some wrong.