Jump to content

Set active class and layer to object

Recommended Posts

I've been working with NNA's example files for a wee bit and have yet to find the right chemistry with Vectorscript.

I'm trying to create a tool or menu command that will allow me to set the active class and layer to that of an object by selecting it. Intuitively, I know this is only a few lines of code, can anyone enlighten me on how to do it?

Many thanks,

Share this post

Link to post


Thoughtful - yes, that is my current process. I often want to jump to both the object class and layer in one step and right clicking on each object twice is slow. This seems like a perfect opportunity for Vectorscript (to combine the two).

Share this post

Link to post

This task is possible without any VectorScript; Control/Right Click on object; Activate Class and Activate Layer commands appear in the context menu.

Perhaps you are actually interested in learning VectorScript. The VectorScript pseudo code for this would be:

Set the active class or layer to the class or layer of the selected or picked object

It's one line of code if you only want one permutation of the possible variations;

Here is the code to set the active class to the class of the selected object if the object is on the active layer:


Reading backwards: FSActlayer returns a handle reference to the First Selected object in the ACTive LAYER; GetClass() returns the name of the object's class as a text string; NameClass() creates a new class if the class doesn't exist and then sets the active class to the class named in the string.

It is considerably more work if you want to get an object that is not on the active layer or if the layer or class options prevent the user from selecting the object. If you want an interface with preferences or settings and if you want your procedure to remember the settings across uses it is yet more work.


Share this post

Link to post

This should do the trick. There are other ways of doing it, but as Frank said, getting the layer of the selected object is not that easy.

PROCEDURE ActivateLayerAndClass;
pt : POINT;
	Layer (GetLName (GetLayer(h)));

It lets you pick an object and then will set the class and layer of that object active.

Share this post

Link to post

After reading Maarten's post I thought of another approach. Since the work is already being accomplished by menu commands, why not create a script that calls the two existing commands one after the other? Create a new VectorScript menu and paste the lines below:

Procedure ActivateLayerAndClass2;
DoMenuTextByName('Activate Class', 0);
DoMenuTextByName('Activate Layer', 0);

Add your new command to the document and object context menus of your workspace with the workspace editor.

Standard disclaimer: I haven't tested this script at all - Use at your own risk.

Share this post

Link to post

It seems like the "Activate Layer" command isn't standaard in the Dutch workspace so therefor i had no idea of its excistence... Thanks for the info Frank, i learn something new every day :) .

Share this post

Link to post

Frank and Maarten - Brilliant!

Both of your approaches are sound and easy to implement (even for me as a relative script novice). I went with Frank's approach, because it flowed right into my context menu (beside Activate Class and Activate Layer).

For any other script beginners wanting to implement this, this is how I did it:

Copy Frank (or Maarten's) script out of this thread,

Tools->Scripts->Plug-in Editor

Create New Command (and name it): "Activate L+C" (or any name you wish less than 20 characters)

Select "Script" button

Paste text from this thread


Hit "Done"

You can now go into your Workspace Editor and place it in any menu you want, assign a keyboard shortcut, etc.

Many thanks!

Share this post

Link to post
Posted (edited)

Has it really been 12 years since the above post (incredulous voice)?


I recently needed to revise the plugins that I created from this thread and thought that they might be useful to some of you, so I'm going to include them here.


These are all point and shoot tools.  Clicking on an object carries out an action.  Listed in order of appearance (icons below)



  1. TA_Set To Active Class - In the event that an object is mis-classed.  This tool lets you click on the object and move it to the active class.
  2. TA_Class Hide - Sometimes a class is in my way and I just want to hide it from view.  Clicking on an object will hide its class.
  3. TA_Activate L+C-Tool - I jump around a lot in the drafting process.  When clicking on an object, this tool makes the active layer and class that of the object.  I've set this one to a standard hot key in the workspace editor (makes it really convenient to use).


Use at your own risk ... but works fine on my 2020 mac setup and as they are über simple and should work on most any configuration of VW.

To use:  Download, move into your plugins folder (start or restart VW)  and then add them to your workspace.


TA_Set To Active Class.vst

TA_Class Hide.vst

TA_Activate L+C-Tool.vst

Edited by Taproot

Share this post

Link to post

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.

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.


7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114


© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

  • Create New...