Jump to content

Get handle to First Selected Object not necessarily on Active Layer


Nik

Recommended Posts

How does one get a handle to the First Selected Object that is not necessarily on the Active Layer? 

 

In my instance I am trying to step through all the selected items that might or might not be on the Active Layer since View->Layer Options->Show/Snap/Modify Others is selected. 

 

If I use vs.FSActiveLayer() it only will cycle through selected items on the active layer.  

 

 

 

 

Link to comment

Hi @Nik,

   Good question. Complicated answer. As @Pat Stanford implies, there is no elegant solution. However, the ForEachObjectInLayer() function (FEOIL) can get you there, but it's still not an elegant solution. I am posting a VS code snippet and I'll leave Pythonizing it to you. The FEOIL call does all of the work on its first iteration, but it is geared to iterate over all of the objects in the drawing, only being constrained by its search arguments (3, 0, 2 in this case). The trick to get it to stop on the FIRST selected object is to have its "actionFunction" return TRUE immediately, which causes it to STOP iterating. Usually, no boolean value is returned in an actionFunction, which is equivalent to returning FALSE each time, and FEOIL will iterate through the whole document. 

 

	Function FSObj :Handle;
	{ Return a handle to the first visible/selected object on the Active Layer, or }
	{ the on first Visible Layer if the Show/Snap/Modify LayerOption is enabled. }
	{ If nothing is selected, return NIL. }
	Var
		ObjHnd :Handle;

		Function FSEL(H :Handle) :Boolean;
		Begin
			ObjHnd := H;
			FSEL := True;	{ return after first object }
		End;		{ FSEL }

	Begin		{ FSObj }
		ForEachObjectInLayer(FSEL, 3, 0, 2);	{ Visible/Selected objects, Shallow, Visible Layers }
		FSObj := ObjHnd;
	End;		{ FSObj }

 

   If you want to limit the FEOIL function to only process Editable Layers use:

ForEachObjectInLayer(FSEL, 3, 0, 4);    { Visible/Selected objects, Shallow, Editable Layers }

 

Happy New Year,

Raymond

  • Like 1
Link to comment

It is important with Raymond's function that "Show/Snap/Modify Others" is selected.  If you have "Show Others" selected there will  be objects that are selected on other layers that do not present as selected.  There may be times when you don't care if the selected object is not seen as selected, but those will be rare and they can be handled just as well with "Show/Snap/Modify Others".  If you do care, but you don't want to have to be sure that "Show/Snap/Modify Others" is selected, do the following

You will need to change the ForEachObjectInLayer function to this:

 

ForEachObjectInLayer(FSEL, 3, 0, 4);      { Visible/Selected objects, Shallow, Editable Layers }

 

Edited by Sam Jones
remove performance description
  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...