Jump to content
  • 10

Create new class with attributes of selected object



Recommended Posts

  • 0
On 10/20/2018 at 6:37 PM, michaelk said:

Try this:

So I just used the MakeClassWithObjAttribs script for the first time on an actual project file and it went weird on me.


A whole bunch of notes & annotations all 'disappeared' from every sheet layer. They were still selectable but no colour or fill even though the attributes palette say attributes are still 'by-class'.


Many, but not all disappeared objects are on the none class. The none class is not listing in the organisation dialogue but is listing in the navigation palette. Couldn't undo so need to recover file from backup.



Link to comment
  • 0

Thanks for sending the file.  I was able to replicate the problem immediately.


The problem - and I don't know why this is a problem yet - occurs when the selected object is in the annotation space or inside a group.


If you put the object directly on a design or sheet layer it works fine.


In the example in your file when you run the script on an object inside the annotation space it is setting the pen opacity of the None class to 0!  (Not working as designed:-)


It also behaves strangely when selecting one of the rectangles in a group.  In my quick test it ignored the change and reset it self to the old attributes.


For now:  Just duplicate the object and paste it directly on the design or sheet layer - not inside of a group or annotation space.  Then run the script and delete the object.


We'll have to do a little debugging!  🕷️



Link to comment
  • 0

Oh I didn't notice it was the opacity setting changing. Well spotted! I was looking at lineweight, pen colour etc. When I change the none class opacity back to 100% all seems to go back to normal.


Will make sure I use this script only outside groups/viewports for the meantime. Cheers

Link to comment
  • 0

OK.  With a lot of help from @Pat Stanford & @JBenghiat here is a working version that doesn't get freaked out by an object inside a group.


Let me know if there are any more surprises!


Procedure EditClassOfSelectedObject;

October 29, 2018.  Ok.  The previous version of the script was horribly done.
Even by my standards.
This version uses the Waldo technique (thanks Josh and Patrick!) to get the actual 
handle of the selected object. Even if that object is in a group.}


This is a fork of the original script described in the comments below.


{Unceremoniously an inelegantly forked by Michael Klaers October 19, 2018}

{This script will update the class of the selected object 
to have the attributes that the object currently has.

It will force that class to be Use at Creation and 
the object will be forced to have all attribues by class}


{© 2016, Pat Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}
{No warranty or guarantee, expressed or implied. Use at your own risk.}
{Test for suitability for your use before using on live data.}
{Immediately discontinue use if hair loss occurs.}

{December 2, 2016}
{This script creates a new class and sets the class attributes to those of the selected}
{object. The only parameter that is not set is TextStyle}
{Based on a request on the tech board by michaelk, September 21, 2016.}

{Updated by Michael Klaers May 8 2017.}
{Changes:	1)  Newly created class will have "Use At Creation" checked.}
{			2)  Active class will not change to newly created class.}

{Updated by Michael Klaers October 2 2018}
{Changes:	3)  Selected object will be in the new class, not the active class}

{Updated by Michael Klaers October 4 2018}
{Changes:  	4) Selected object attributes will all be by class}

VAR	FPat:							LONGINT;
	FillBackR,FillBackG,FillBackB:	LONGINT;
	FillForeR,FillForeG,FillForeB:	LONGINT;	
	LineS:							LONGINT;  
	LineW:							INTEGER;
	ObjBMarkStyl:					LONGINT;
	ObjBMarkAngle:					INTEGER;
	ObjBMarkSize:					REAL;
	ObjBMarkWidth:					REAL;
	ObjBMarkThickB:					INTEGER;
	ObjBMarkThick:					REAL;
	ObjBMarkVis:					BOOLEAN;
	ObjEMarkStyl:					LONGINT;
	ObjEMarkAngle:					INTEGER;
	ObjEMarkSize:					REAL;
	ObjEMarkWidth:					REAL;
	ObjEMarkThickB:					INTEGER;
	ObjEMarkThick:					REAL;
	ObjEMarkVis:					BOOLEAN;
	POpacity:						INTEGER;
	FOpacity:						INTEGER;
	PenBackR,PenBackG,PenBackB:		LONGINT;
	PenForeR,PenForeG,PenForeB:		LONGINT;
	DSEnabled:						BOOLEAN;
	DSnUnits:						INTEGER;
	DSdOffset:						REAL;
	DSdBlurRadius:					REAL;
	DSdAngle:						REAL;
	DSOpacity:						INTEGER;
	DSRed:							INTEGER;
	DSGreen:						INTEGER;
	DSBlue:							INTEGER;
	ThisObject:						HANDLE;
	SelectedCount:					LONGINT;
	ReturnBool:						BOOLEAN;
	Class2Edit:						STRING;
	SetExistingClass:				BOOLEAN;
	ActiveClassName:				STRING;
	Waldo:							HANDLE;


{***************************  Make sure only one object selected  ***************************}
	If NumSObj(ActLayer) =1 then 
{***************************  Get handle to selected object  ***************************}

Waldo := LNewObj;
ThisObject := PrevSObj(Waldo);
IF (Waldo <> nil) THEN
{***************************  Get all graphic attributes of selected object  ***************************}
			FPat := GetFPat(ThisObject);

{***************************  Write those attributes to class of selected object  ***************************}


{***************************  Set all attributes of selected object back to By Class  ***************************}			





Edit Class Fix.vwx

  • Like 2
Link to comment
  • 0

I started writing scripts 6 or 7 years ago.  In all that time I never realized one of the most common functions for getting a handle to the selected object actually returns the group (if any) that contains the object.


Hence the Where's Waldo technique.


I wonder what other revelations I'm in for…

  • Like 1
Link to comment
  • 0

Thanks for this script. I am very new to Vectorworks, but did manage to add the script. However, I created a class from an object with a 20% fill opacity, and full pen opacity, and the class that was created switched those two values. Also, I noticed the object from which I created the class did not get added to the class. Any suggestions, or additional ideas? 

Link to comment
  • 0

@michaelk This is your script. You want to take a look.  


It looks like you followed the function descriptions in the manual directly, but I think either GetClOpacityN or SetClOpacityN are wrong in that the Fill and Pen are reversed between the two in the Function Reference.


@TD-Ben Since the object had to be in the Class originally, I don't understand what you mean about the object not getting added to the class?

Link to comment
  • 0

Scripts are just another resource that you can import from other files.  If you download the file you can import the script into one of your own files, perhaps a library and/or template file? 

You need to place scripts into script palettes. Vw will ask you which palette to place the script or you can create a new one.


Once imported go to the bottom of the windows menu, select the file and check next to the palette to display it.



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

Answer this question...

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