Jump to content
Developer Wiki and Function Reference Links ×

Set active class and layer to object


Taproot

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,

Link to comment
Guest Frank Brault

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:

NameClass(GetClass(FSActLayer));

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.

hth,

Link to comment

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;
VAR
pt : POINT;
h : HANDLE;
BEGIN
GetPt(pt.x,pt.y);
h:=PickObject(pt.x,pt.y);
IF h<>NIL THEN
BEGIN
	NameClass(GetClass(h));
	Layer (GetLName (GetLayer(h)));
END;
END;
RUN(ActivateLayerAndClass);

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

Link to comment
Guest Frank Brault

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;
Begin
DoMenuTextByName('Activate Class', 0);
DoMenuTextByName('Activate Layer', 0);
Redraw;
End;
Run(ActivateLayerAndClass2);

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.

Link to comment

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

Save

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!

Link to comment
  • 11 years later...

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)

 

1342208095_Class_LayerTools.thumb.png.2e3947b5fec060bc1d0a71ef31be4498.png

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