Jump to content

Custom “Assign to [class name]” script.


Recommended Posts

I can’t write script but I do use the inbuilt custom selection and visibility tools to create my own custom scripts a lot. 


I can’t figure out how, using the Vw menu commands, to create a simple script that simply assigns a currently selected object or objects to a class.


Can anyone point me in the right direction?


ive started using object styles a lot however for plug in style symbols there is no option to assign a class on insertion. They simply go to the active class.


We always leave “none” as our active class so I’m repeatedly having to reassign the class of some plug-in style symbols as soon as I insert them. 


It would be nice to have a set of little scripts tucked in a palette off to the side which when run will assign the selected object(s) to a predetermined class. 


Can anyone help?


Its probably one line of script?...

Link to comment

Hi guys, lately i' ve been searching for exactly same script, but I cant make it work

I paste line

SetClassN(FSActLayer, 'my class name', True);

in script window (python), change 'my class name' to my custom one...and save it to resource browser. However when I have selected some object and initiate script i get error messages


Am I missing something? In terms of scripting I am beginner.

Thanks you in advance for directing me right way.





Snímka obrazovky 2019-09-19 o 9.33.38.png

Edited by drelARCH
Link to comment

It’s working perfect for me.


If Julian’s suggestions don’t work there is  a chance your browser may be introducing erroneous characters when you copy and paste. This has happened to me before but when I did exactly the same copy and paste but with a different browser (firefox in that case) it worked. 


Try a different browser or simply type the script yourself rather than copy and paste.

Link to comment
  • 2 weeks later...
On 9/18/2019 at 9:46 AM, Julian Carr said:

I likely won't work in groups or symbols though. If used on a group (not in a group), the last argument (true or false) will determine if all the objects in the group also get the class assignment.

This little script is great@Julian Carr.


Unfortunately it doesn't seem to work in viewport annotation space. Is it easy to fix this?

Link to comment
4 hours ago, grant_PD said:

As I understand it, I have the object selected that I want to change all of its parts and pieces to the current active class

No, that script changes the selected object to a particular class - In that case a class called 'my class name'.


I don't know of a script that will change objects to the current active class though I imagine that it wouldn't be hard to write one - unfortunately I don't know how to script.


I always have 'none' as the active class. If you do that too then you could change 'my class name' in the script to 'none' and the selected objects will then be placed in the none class. It doesn't work within groups or annotations.

Edited by Boh
Link to comment

I always keep the none class as the active class so that I don’t inadvertently create objects on random classes they shouldn’t be on. The none class is always set to visible so I always create the objects on the none class then class them as required (hence why I wanted this “assign class” script).


With this way of working groups will always be on the none class with the objects inside classed. That way the grouped objects vp visibilities is only dependant on the class they are on and not also the class the group is on.


For most “standard” symbols I do it the other way around where the symbol instance is on a class and the objects inside the symbol are on the none class. I do it this way so:

1. I can set up the symbol to insert straight into a specified class (in edit symbol options).

2. The symbol can be used in different files without bringing in additional classes. 

3. The symbol’s visibility still only relies on a single class.

Link to comment
  • 4 months later...

Coming back to this. The script to assign an object to a class is:


SetClassN(FSActLayer, 'my class name', True);


I am doing a lot of work in annotation space however this awesome script doesn't work in annotation space or groups. I wish I could edit the script myself to work inside groups/annotations space however I need to resort to any helpful scripters out there who don't mind having a look. If it is a major exercise then I will just leave it but I'm hoping it is simple and would only take a few minutes for someone to tweek...


Thanks in advance!

Link to comment

Many thanks to @Julian Carr for tweeking the assign to class script to work within viewports and groups. Posting here (with his permission) for anyone interested:


Procedure SetTheClass;
	kCName = 'My Class Name';
	gh1 : HANDLE;
Function DoIt(h1 : HANDLE) : BOOLEAN;
	SetClassN(h1, kCName, True);

	Locus(0, 0);
	gh1 := LNewObj;
	ForEachObjectInList(DoIt, 2, 2, FInGroup(GetParent(gh1)));


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

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