Jump to content

selected objects in script


Recommended Posts

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)

Link to comment

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.

Link to comment

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.

Link to comment

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. 

Link to comment

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)));

 

 

 

 

  • Like 1
Link to comment
  • 1 month later...

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.

  • Like 2
Link to comment

@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)

 

  • 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...