Jump to content
Pat Stanford

Convert Objects in Symbol to ByClass

Recommended Posts

This script was written based on a query in another forum:

https://techboard.vectorworks.net/ubbthreads.php?ubb=showflat&Number=218975#Post218975

Procedure SymbolContentsToByClass;

{If the selected object in a drawing is a symbol, it locates the}
{symbol definition and converts all objects inside the definition}
{to use the ByClass option for all attributes}

{November 6, 2015}
{© 2015, Pat Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}

{This has only been lightly tested. I recommend that you use this on a }
{copy of your primary file. No warranty expressed or implied. Use at}
{your own risk. Do not operate heavy machinery while using this script.}

Var H1, H2, H3: Handle;
SymDefName: String;

Begin

     H1:=FSActLayer;

     If GetType(H1)=15 then
	Begin
	  SymDefName:=GetSymName(H1);
	  H2:=GetObject(SymDefName);
	  H3:=FinSymDef(H2);
	  While H3 <> Nil do
		Begin
			SetLSByClass(H3);
			SetLWByClass(H3);
			SetMarkerByClass(H3);
			SetOpacityByClass(H3);
			SetPenColorByClass(H3);
			SetFPatByClass(H3);
			SetFillColorByClass(H3);
			H3:=NextObj(H3);
		End;
	End;
	ResetObject(H1);
	RedrawAll;

End;

Run(SymbolContentsToByClass);

Share this post


Link to post

Just tried this and it works! Is it easy to change this script it's inverse? (i.e.Remove all "by-class" settings of objects in a symbol).

Edited by Boh

Share this post


Link to post

Boh,

   There may be a more elegant way to remove the Attributes-By-Class setting for selected objects, but I can't find it.  I can only do it by removing each attribute individually. Here's a script to that effect.

 

   This will work on multiple selected symbols, but not on nested symbols. If a symbol definition contains other symbol instancess, they will not be affected. You will have to run this script on instances of each symbol  you want to convert. You can place them in the drawing, select them all, then run the script once.

 

   After this script is run, you will not see any differences in the symbol's appearance. The objects inside will have the same attributes as the classes they are in. However, if you then change the appearance of a controlling class, these symbols will not follow the new class appearance since their contents no longer are set By-Class. I hope this is what you were looking for.

 

Raymond

 

Procedure SymbolContentsNotByClass;
{ If the selected objects in a drawing are symbols, this script locates }
{ each symbol definition and converts all objects inside the definition }
{ to REMOVE the SetByClass option for all attributes. }

{ 21 December 2017 - Raymond Mullin }

{ This has been less than lightly tested. Pat Stanford recommends you use }
{ this on a copy of your primary file. No warranty expressed or implied. }
{ Use at your own risk. Do not operate heavy machinery while using this script. }
{ I concur. }

VAR
	SymH, H: Handle;
	B, visibility :Boolean;
	thickBasis, angul, Opacity, PenOp, FillOp :Integer;
	style, Red, Grn, Blu :Longint;
	size, wydth, thickness :Real;
BEGIN
	SymH := FSActLayer;
	while (SymH <> Nil) do begin

		if (GetTypeN(SymH) = 15) then begin		{ if it is a Symbol }
			H := FinSymDef(GetObject(GetSymName(SymH)));
			while (H <> Nil) do begin
				SetLW(H, GetLW(H));
				SetLSN(H, GetLSN(H));
				GetPenFore(H, Red, Grn, Blu);
				SetPenFore(H, Red, Grn, Blu);
				GetPenBack(H, Red, Grn, Blu);
				SetPenBack(H, Red, Grn, Blu);
				
				SetFPat(H, GetFPat(H));
				GetFillFore(H, Red, Grn, Blu);
				SetFillFore(H, Red, Grn, Blu);
				GetFillBack(H, Red, Grn, Blu);
				SetFillBack(H, Red, Grn, Blu);
	
				if GetObjBeginningMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility) then
					B := SetObjBeginningMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility);
					
				if GetObjEndMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility) then
					B := SetObjEndMarker(H, style, angul, size, wydth, thickBasis, thickness, visibility);

			{	For VW 2016 and earlier, use the following for Opacity: }
				GetOpacity(H, Opacity);
				SetOpacity(H, Opacity);
		
			{	For VW 2017 and later, use the following for Opacity: }
{				if GetOpacityN(H, PenOp, FillOp) then
					B := SetOpacityN(H, PenOp, FillOp);
}
			
				H := NextObj(H);
			end;		{ while (H <> Nil) }
			ResetObject(SymH);
		end;		{ if }
		
		SymH := NextSObj(SymH);
	end;		{ while (SymH <> Nil) }

	RedrawAll;
END;
Run(SymbolContentsNotByClass);

 

 

Share this post


Link to post

That is brilliant Raymond! Thank you. Perfect for me as I am sorting out my library of symbols so very useful.

 

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.

×