halfcoupler Posted November 25, 2023 Share Posted November 25, 2023 Hope someone can help a VS beginner with this very simple script: I want to set my current selection to a certain class. My script so far: PROCEDURE Set_A_Class; BEGIN SetClass(FSActLayer, 'MyClass-Pink_Flamingo'); END; RUN(Set_A_Class); ok, this works, but it is very buggy: - after running the script, the OIP does not refresh,- I need to deselect and reselect the objects to get the right information in the OIP. - I don't know if this is also the right syntax if multiple objects are selected. (Is FSActLayer the right handle for this purpose?) Many thanks for all hints 😀 Quote Link to comment
MullinRJ Posted November 25, 2023 Share Posted November 25, 2023 Hello, @halfcoupler. Your script seems to work in VW 2024, and 2023. If only one object is selected the OIP updates. If multiple objects are selected, then, yes, the OIP does not update the Class popup menu and displays the old setting. If you have multiple objects selected, do you want to apply the new class name to all of the selected objects? If so, try this script: PROCEDURE Set_A_Class; { Change the class name of all selected objects that are on editable layers. } CONST kNewClass = 'MyClass-Pink_Flamingo'; function ApplyClass(H :Handle) :Boolean; Begin SetClass(H, kNewClass); SetSelect(H); { Resets OIP } End; BEGIN ForEachObjectInLayer(ApplyClass, 3, 0, 4); { Visible/Selected, Shallow, Editable } SysBeep; { make noise when done } END; RUN(Set_A_Class); To assign other class names, change the constant "kNewClass". The ForeEachObjectInLayer() function loops through every object that meets the conditions specified by the three numbers shown in the call. In this case it looks for Visible and Selected objects (1+2), does not go inside Groups or other containers, or Shallow (0), and works across Editable Layers (4). If you need more information on this and similar ForEachObject functions, check out the Developer Wiki and Function Reference Links in the blue bar shown at the top of this page. HTH, Raymond 4 Quote Link to comment
halfcoupler Posted November 26, 2023 Author Share Posted November 26, 2023 Thank You so much @MullinRJ , this its a great learning start for me. I already asumed that I have to loop through the objects, but referring to my little Visual Basic knowledge I was looking for some 'Do...Loop...While - phrase' in the function reference. VS is much more straight forward than VB and this is a very good example for it's structure. The script works perfect and I have already added it to my workspace ! Thank You ! 😀 Quote Link to comment
Pat Stanford Posted November 26, 2023 Share Posted November 26, 2023 In addition to the ForEachObject functions, VS also has full looping capabilities both with a While loop (evaluates at the top of the loop and executes zero or more times) and a Repeat loop (evaluates at the end of the loop and executes one or more times). Take a look at the VS Language Guide for more information on control structures. https://developer.vectorworks.net/images/7/72/VectorScriptGuide.pdf 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.