Editor.GetEntity() and PickPointSelectedSubObject

Editor.GetEntity() and PickPointSelectedSubObject

Anonymous
Not applicable
3,873 Views
11 Replies
Message 1 of 12

Editor.GetEntity() and PickPointSelectedSubObject

Anonymous
Not applicable

Hi,

 

a user needs to select an object. I need to know exactly where the object was clicked as I will process the segment the user clicked on.
Now, so far I'm using editor.GetSelection(). In most cases the user should only select one single object - and I havent figured out how to limit the selection process to exactly one object.


But there is also Editor.GetEntity() - which seems a better choice for my use case. Now, here is the question:
with GetSelection I get the point where the user clicked with the following code:

 

foreach (SelectedObject ssobj in selSet)
{
	// usually AC Object
	if (ssobj.SelectionMethod == SelectionMethod.PickPoint)
	{
		PickPointSelectedObject ppsd = ssobj as PickPointSelectedObject;
	PickPointDescriptor ppd = ppsd.PickPoint;
		p = ppd.PointOnLine;
		UtilCadActive.WriteMessage("\nCAD->" + ppd.PointOnLine.ToString());
		break;
		
	}
	// usually Map-FDO Object
	if (ssobj.SelectionMethod == SelectionMethod.SubEntity)
	{
		SelectedSubObject[] subOb = ssobj.GetSubentities();
		foreach (SelectedSubObject o in subOb)
		{
			if (o.SelectionMethod == SelectionMethod.PickPoint)
			{
				PickPointSelectedSubObject so = o as PickPointSelectedSubObject;
				PickPointDescriptor ppd = so.PickPoint;
				p = ppd.PointOnLine;
				UtilCadActive.WriteMessage("\nMap->" + ppd.PointOnLine.ToString());
				break;
			}
		}
		break;
	}

I have to deal with CAD entities and Map objects (FDO features). The way to get the pickpoint is different. Is there something similiar for GetEntity()? I only see PromptEntityResult.PickedPoint - how would I get to the Subentities and their PickPoint?

 

Thanks, Rob

0 Likes
Accepted solutions (1)
3,874 Views
11 Replies
Replies (11)
Message 2 of 12

BKSpurgeon
Collaborator
Collaborator

You can use a prompt selection option to limit your selections to only one object. e.g. see below for an example. hope it helps.

 

 

 [CommandMethod("SelectOnlyOne")]
        public static void SelectOnlyOne()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            PromptSelectionOptions pso = new PromptSelectionOptions();

                // selects only a single entity            
            pso.SingleOnly = true;
                // selects only one at a time - but since singleOnly is true it selects only once.
            pso.SinglePickInSpace = true;

            PromptSelectionResult psr = ed.GetSelection(pso);

            if (psr.Status == PromptStatus.OK)
            {
                SelectionSet ss = psr.Value;

                // deal with the selection set as you see fit
            }

        }

 

0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi,

 

many thanks for your reply. Yes, I have done that already - problem is: user can still draw window to perform selection. And in that case I don't get a pickpoint back. Thats why I thought GetEntity would be better choice,

 

Rob

0 Likes
Message 4 of 12

_gile
Consultant
Consultant

Hi,

 

I'm not certain to understand what you're trying to do, but to mimic GetEntity with GetSelection, the options are:

  • SingleOnly = true;
  • SelectEverythingInAperture = true;

Here's a little example:

 

            var ed = Application.DocumentManager.MdiActiveDocument.Editor;
            var opts = new PromptSelectionOptions();
            opts.AllowSubSelections = true;
            opts.SingleOnly = true;
            opts.SelectEverythingInAperture = true;
            var psr = ed.GetSelection(opts);
            if (psr.Status == PromptStatus.OK)
            {
                var ssObj = psr.Value[0];
                if (ssObj.SelectionMethod == SelectionMethod.PickPoint)
                {
                    ed.WriteMessage("\nPick point: " + ((PickPointSelectedObject)ssObj).PickPoint.PointOnLine);
                }
                if (ssObj.SelectionMethod == SelectionMethod.SubEntity)
                {
                    foreach (SelectedSubObject subEnt in ssObj.GetSubentities())
                    {
                        if (subEnt.SelectionMethod == SelectionMethod.PickPoint)
                        {
                            ed.WriteMessage("\nSub entity pick point: " + ((PickPointSelectedSubObject)subEnt).PickPoint.PointOnLine);
                        }
                    }
                }
            }

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 12

Anonymous
Not applicable

Hi Gile,

 

as far as I have figured out GetSelection allows to draw a selection window - even if only one object can be picked.

I do not want the user to be able to select by window. Thats why I thought "GetEntity" would be better suited for my use-case. But I haven't tested whether you can select by window when using GetEntity - I just assume you cant, but who knows.

 

 

Rob

0 Likes
Message 6 of 12

_gile
Consultant
Consultant
Accepted solution

Did you try the code I posted ?

Using SelectEverythingInAperture = true (:E) and SingleOnly = true (:S) options forces a single pick selection as GetEntity does.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 12

Anonymous
Not applicable

Hi Gile,

 

many thanks - that's what I was looking for. 

 

Rob

0 Likes
Message 8 of 12

BKSpurgeon
Collaborator
Collaborator

Hi Mr Gilles i have a question:

 

            var opts = new PromptSelectionOptions();
            opts.AllowSubSelections = true;

 

 

What is the meaning of AllowSubSelections?

 

The documentation is quite sparse on this point. clarification much appreciated.

 

rgds

 

 

0 Likes
Message 9 of 12

_gile
Consultant
Consultant

Hi,

 

AllowSubSelections allows to select sub entities (solid or meshes edges, attribute references, ...) accordingly with the LEGACYCTRLPICK and SUBOBJSELECTMODE sysvar settings.

 

With default settings (LEGACYCTRLPICK = 2 and SUBOBJSELECTMODE = 0), AllowSubSelections allows sub entities selection using Ctrl+click.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 10 of 12

BIM_VIET
Enthusiast
Enthusiast

@_gile 

I have a problem when using the method pickpoint as your code.

Here I pick a point on the cyan polyline to make a leader, but the coordinate of point does not really intersect with this polyline, it depends on the pickbox size.

 

Please help me to get the intersect point when pick this polyline.

Thanks!

 

BIM_VIET_2-1668422989667.png

 

0 Likes
Message 11 of 12

norman.yuan
Mentor
Mentor

the pickedpoint is where the center of the "pickbox". You need to CALCULATE where exactly the point to a selected entity is. In your case, when the selected entity is an entity derived from curve, you can calculate with Curve.GetClosestPoint() method:

 

var pointOnPickedPolyline=PickedPolyline.GetClosestPoint(pickedPoint, false);

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 12 of 12

BIM_VIET
Enthusiast
Enthusiast

Thanks @norman.yuan 

0 Likes