Nik Posted January 4, 2023 Share Posted January 4, 2023 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. Quote Link to comment
Pat Stanford Posted January 4, 2023 Share Posted January 4, 2023 FObject If Not Selected then NextSObj. No direct VS command to get the first selected object in the file. Alternately, iterate through the Layer List and use FSObject on each layer until you find something selected. 1 Quote Link to comment
MullinRJ Posted January 4, 2023 Share Posted January 4, 2023 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 1 Quote Link to comment
Sam Jones Posted January 4, 2023 Share Posted January 4, 2023 (edited) 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 January 4, 2023 by Sam Jones remove performance description 1 Quote Link to comment
Recommended Posts
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.