Jump to content
Developer Wiki and Function Reference Links ×

set class - a beginner script


halfcoupler

Recommended Posts

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 😀

 

Link to comment

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

 

  • Like 4
Link to comment

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 ! 😀

Link to comment

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

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