Jump to content
  • 9
michaelk

Create new class with attributes of selected object

Question

I'd like a new contextual click  / menu command to create a new class with the graphic attributes of the selected object.

 

mk

  • Like 3

Share this post


Link to post

Recommended Posts

  • 0

It occurs to me that it might have been a good idea to put a logic test in to make sure you don't run this script when the selected object is in the None class.

 

Be careful out there.

Share this post


Link to post
  • 0

This script is definitely going to join the category of "I don't know what I ever did without it" tools. Thanks Michael. 

 

The other command I would love to have is "Edit Class of selected object".Any takers?!

 

Mark

  • Like 1

Share this post


Link to post
  • 0

Glad you like it.  I use that first script all the time.

 

So you'd like a script that opens the Edit Class dialog for the class of the currently selected object?

 

I'm not aware of a VS function that has access to that dialog box.  

 

@Pat Stanford?

Share this post


Link to post
  • 0

Yes. It would be a tool to get passed the Organisation Dialogue and the search for the class you want to edit and straight to the specific Edit Class dialogue. It would make my way of working so much more efficient.

Share this post


Link to post
  • 0

@michaelk

thanks for hooking it up!

I haven't had a chance to use it, but I really appreciate that both of these tools exist now!

Share this post


Link to post
  • 0
6 hours ago, markdd said:

It would make my way of working so much more efficient.

Yes! This 3rd script would kind of complete the right click dream work flow. Good call @markdd

 

Share this post


Link to post
  • 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.

 

Hmmm......Capture.thumb.JPG.cded38f7ebad50d4d8eede8c33d7a36d.JPG

Share this post


Link to post
  • 0

Any chance you can send me the file to take a look at?  Feel free to send it in a personal message.

 

 

Share this post


Link to post
  • 0

Ok. Sent you the file. Hopefully you can see where things are going pear shape. 🙂

 

Cheers

Share this post


Link to post
  • 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!  🕷️

 

 

Share this post


Link to post
  • 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

Share this post


Link to post
  • 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;

		
		
BEGIN

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

Locus(0,0);
Waldo := LNewObj;
ThisObject := PrevSObj(Waldo);
IF (Waldo <> nil) THEN
	DelObject(waldo);		
		
			
{***************************  Get all graphic attributes of selected object  ***************************}
			
			FPat := GetFPat(ThisObject);
			GetFillBack(ThisObject,FillBackR,FillBackG,FillBackB);
			GetFillFore(ThisObject,FillForeR,FillForeG,FillForeB);
			LineS:=GetLSN(ThisObject);
			LineW:=GetLW(ThisObject);
			ReturnBool:=GetObjBeginningMarker(ThisObject,ObjBMarkStyl,ObjBMarkAngle,ObjBMarkSize,
								ObjBMarkWidth,ObjBMarkThickB,ObjBMarkThick,
								ObjBMarkVis);
			ReturnBool:=GetObjEndMarker(ThisObject,ObjEMarkStyl,ObjEMarkAngle,ObjEMarksize,ObjEMarkWidth,
									ObjEMarkThickB,ObjEMarkThick,ObjEMarkVis);
			ReturnBool:=GetOpacityN(ThisObject,POpacity,FOpacity);
			GetPenBack(ThisObject,PenBackR,PenBackG,PenBackB);
			GetPenFore(ThisObject,PenForeR,PenForeG,PenForeB);
			DSEnabled:=IsDropShadowEnabled(ThisObject);
			ReturnBool:=GetDropShadowData(ThisObject,DSnUnits,DSdOffset,
									DSdBlurRadius,DSdAngle,DSOpacity,
									DSRed,DSGreen,DSBlue);
									

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


			Class2Edit:=GetClass(ThisObject);
					
			SetClFPat(Class2Edit,FPat);
			SetClFillBack(Class2Edit,FillBackR,FillBackG,FillBackB);
			SetClFillFore(Class2Edit,FillForeR,FillForeG,FillForeB);
			SetClLSN(Class2Edit,LineS);
			SetClLW(Class2Edit,LineW);
			ReturnBool:=SetClassBeginningMarker(Class2Edit,
							ObjBMarkStyl,ObjBMarkAngle,ObjBMarkSize,
							ObjBMarkWidth,ObjBMarkThickB,ObjBMarkThick);
			ReturnBool:=SetClassEndMarker(Class2Edit,
							ObjEMarkStyl,ObjEMarkAngle,ObjEMarksize,
							ObjEMarkWidth,ObjEMarkThickB,ObjEMarkThick);
			SetClOpacityN(Class2Edit,FOpacity,POpacity);

			SetClPenBack(Class2Edit,PenBackR,PenBackG,PenBackB);
			SetClPenFore(Class2Edit,PenForeR,PenForeG,PenForeB);
			EnableCLDropShadow(Class2Edit,DSEnabled);
			SetCLDrpShadowData(Class2Edit,DSnUnits,DSdOffset,
							DSdBlurRadius,DSdAngle,DSOpacity,
							DSRed,DSGreen,DSBlue);
			
			
{***************************  Set all attributes of selected object back to By Class  ***************************}			
			

			SetClass(ThisObject,Class2Edit);				
			SetFPatByClass(ThisObject);
			SetFillColorByClass(ThisObject);
			SetLSByClass(ThisObject);
			SetLWByClass(ThisObject);
			SetMarkerByClass(ThisObject);
			SetOpacityByClass(ThisObject);
			SetPenColorByClass(ThisObject);
			SetTextStyleByClass(ThisObject);

				
		
		End
	
END;

Run(EditClassOfSelectedObject);

 

Edit Class Fix.vwx

  • Like 1

Share this post


Link to post
  • 0

Liking that Waldo technique! Thanks Michael. All seems to be working well!

Share this post


Link to post
  • 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

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

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.

×