Onink Posted May 18, 2022 Share Posted May 18, 2022 I've created a simple script to put selected objects in a specified class. But I found out that it does the same for objects that are selected within a group. How can I prevent that from happening? c='Gebouw' def DoIt(h): vs.SetClass(h, c) vs.ResetObject(h) return() criteria="((SEL=TRUE))" vs.ForEachObject(DoIt, criteria) Quote Link to comment
Peter Vandewalle Posted May 18, 2022 Share Posted May 18, 2022 This should do the trick: c='Gebouw' def DoIt(h): vs.SetClassN(h, c, False) vs.ResetObject(h) return() criteria="((SEL=TRUE))" vs.ForEachObject(DoIt, criteria) Quote Link to comment
Pat Stanford Posted May 18, 2022 Share Posted May 18, 2022 Just change the Criteria to VSEL instead of SEL. Objects in Groups and Symbols and (I think) hidden layers can be left selected even though you can't see them. The SEL criteria finds all of those objects. The VSEL is for Visible Selected objects, only the ones you can see. Which is what many of us always thought SEL was (or should have been) doing. Quote Link to comment
Onink Posted May 23, 2022 Author Share Posted May 23, 2022 Gentlemen, thanks for your help. The 'False' addition didn't work for me, but the VSEL does work. Quote Link to comment
Jesse Cogswell Posted May 23, 2022 Share Posted May 23, 2022 My absolute favorite thing about VSEL is that I can't find it mentioned anywhere in the function reference or the VectorScript Guide. There are so many times I've added criteria to include only selected objects on the current layer to avoid affecting selected objects on other layers that weren't visible, only to have a built in command to do exactly that. I don't know where you found VSEL, but it's life changing. Quote Link to comment
Pat Stanford Posted May 23, 2022 Share Posted May 23, 2022 It is in the Criteria Builder, but you are right it is not in the documentation. I have filed a bug agains the documentation for VSEL missing. Quote Link to comment
Sam Jones Posted May 23, 2022 Share Posted May 23, 2022 The problem with the VSEL criteria is that it will move objects all the objects that are visible and selected (as you would expect), except that it will do this with the Layer Options, "Show Others" and "Show/Snap Others. When those layer options are selected the selected objects on other layers are not shown as selected. This allows you to modify objects you did not intend to modify. Screen Recording 2022-05-23 at 11.39.43 AM.mov Quote Link to comment
Jesse Cogswell Posted May 23, 2022 Share Posted May 23, 2022 Looks like I was too quick to heap on praises for VSEL, because that is exactly the scenario I try to avoid since I always draft in Show/Snap mode. Thanks for pointing that out @Sam Jones before I went back and changed all of my scripts. Quote Link to comment
Sam Jones Posted May 23, 2022 Share Posted May 23, 2022 If I only want to change things that should be changed, 1. Everything I see selected in show/snap/modify layer option OR 2. Only things on the selected layer in all other layer options, since I cannot see what is selected, I do the following LayerOptions := GetLayerOptions; ActiveLyr := ActLayer; ActiveLyrName := GetLName(ActiveLyr); IF LayerOptions = 5 THEN {Show/Snap/Modify Others} ForEachObject(ProcedureToMakeChange, (((VSEL=TRUE) & (main criteria)))) ELSE ForEachObject(ProcedureToMakeChange, (((VSEL=TRUE) & (L=ActiveLyrName) & (main criteria))); 1 Quote Link to comment
Onink Posted June 28, 2022 Author Share Posted June 28, 2022 I'm using the VSEL option because that works best for me. But when I use this when I'm in a viewport, nothing happens. Why is this? Quote Link to comment
Jesse Cogswell Posted June 28, 2022 Share Posted June 28, 2022 You have to add INVIEWPORT to the selection criteria. Likewise, if you want to select objects while editing a symbol, you would need to add INSYMBOL. You have to be kind of careful with these, as they can have unintended consequences. Objects remain selected while inside edit containers like symbols, groups, and viewport annotations, and VSEL isn't as restrictive as it maybe should be. So if you have a script, say, delete objects you might accidentally delete objects out of viewport annotations that you didn't realize were still selected. 2 Quote Link to comment
Onink Posted July 5, 2022 Author Share Posted July 5, 2022 Is there a way, like VSEL, to only use this in the current viewport? Would VINVIEWPORT work? Quote Link to comment
Jesse Cogswell Posted July 5, 2022 Share Posted July 5, 2022 @Onink There is a way to do it, but it adds a couple more steps, not really a simple way to do it in the criteria check. The first thing you will need is a handle to the viewport itself. The easiest way I've found to do this is to employ the "waldo" method. You drop a locus point in and get its parent using GetParent, which will get you a handle to the viewport. Then you delete the locus point. From there, you do your standard ForEachObject call and add an extra check in your callback loop to test whether the object's parent handle matches the viewport handle. The code below should do the trick. But keep in mind that the get parent trick may also have the unintended consequence of preventing your code from working on intended objects on design layers, since the design layer will be the parent. So if you run this on a design layer, it will only work on selected objects on the active layer. c='Gebouw' def DoIt(h): if vs.GetParent(h) == sheetHd: vs.SetClass(h,c) vs.ResetObject(h) return() vs.Locus(0,0) waldo = vs.LNewObj() sheetHd = vs.GetParent(waldo) vs.DelObject(waldo) criteria="(INVIEWPORT & (VSEL=TRUE))" vs.ForEachObject(DoIt,criteria) 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.