Jump to content
Pat Stanford

Convert Nested Symbols to Groups

Recommended Posts

Someone on the Vectorworks mail list needed a way to convert nested symbols to groups. The attached script converts all nested symbols in placed symbols in a drawing to groups. It does not purge the drawing, but that functionality could be easily added.

Copy everything in the code block and paste it into a new blank vectorscript.

Let me know if you have problems.

Procedure UnNest_Symbols;

{Converts nested symbols to Groups}
{Converts sub-symbols in all placed symbols in a drawing to groups}
{It will convert the 2D portion of the symbol if used in Top/Plan the 3D portion otherwise.}
{All sub-symbols will also be converted.}

{August 12, 2011  Version 1}
{? 2011, Coviana, Inc - Pat Stanford pat@coviana.com}
{Licensed under the GNU Lesser General Public License}
{No rights reserves}
{Use at your own risk. May cause pimples or hysterical blindness}

Var
PlacedSymbol:	Handle;


Procedure Doit(ProcessObject :Handle);


Var
	MyDefinition:	Handle;
	NestedObject:	Handle;
	SymDefName:		String;

Begin
	SymDefName:=GetSymName(ProcessObject);  {get the name of the symbol definition}
	MyDefinition:=GetObject(SymDefName);	{use the name to get a handle to the definition}

	If GetType(MyDefinition)=16 then		{only work on symbol definitions}
		Begin
			NestedObject:=FInSymDef(MyDefinition);	{Get the first object in the symbol def}
			While NestedObject <> Nil do 	{make sure you process all the objects in symbol def}
				Begin
					If GetType(NestedObject)=15 then SymbolToGroup(NestedObject,1); 	{if a symbol convert to a group}
					NestedObject := NextObj(NestedObject);	{get a handle to the next object in the symbol}
				End;
		End;				
End;

Begin
ForEachObject(DoIt,((T=SYMBOL)));
End;

Run(UnNest_Symbols);

Share this post


Link to post

Hysterical blindness... oh I'm so there!

But seriously nice script Pat, even just from a layout/efficient code perspective.

*General thanks*

J

Share this post


Link to post

hello, this is an old topic but its exactly what i need. I cant seem to get it to work though. Any reason why it wouldnt work on vectorworks 2020? (probably several reasons..) i used to use scripts in autocad but never tried them in vectorworks. 

 

it could well be user error. I click run and nothing seems to happen though . 

 

any thoughts?

 

ta

Share this post


Link to post
Posted (edited)

Hello @rexwexford,

   I am not sure how you are determining if the script works or doesn't, but it is working on my machine in VW 2020. That said, this is a weird script in that it does not convert symbols on the drawing to groups, but it does convert some nested symbols inside the symbols that are on the drawing to a group, but it does not convert ALL nested symbols to groups.

 

   I think it would be more thorough if it used option "2" (Convert all subobjects) in the SymbolToGroup() command. Currently it uses option "1" (Convert plug-in and symbol subjects). But even with this change, the net result would be you still have symbols on your drawing, AND, your symbol definitions may have been modified. 

 

   If you want to flatten your drawing, or just a selection of your drawing, why don't you use the VW menu Modify > Convert > Convert to Group (CMD-K)? You will be presented with a dialog box where the third option is "Convert all sub-objects". The net result will be that all your selected symbols will be flattened to Groups, and none of your symbol definitions will be modified. This is a much safer scenario, in my mind. If you don't want the symbol definitions intact, after you flatten everything to your liking, you can copy everything to a new drawing. This way you can always go backwards if you need to,. If you use the above script and save your file, you may do irreparable damage; and as Pat warns – {Use at your own risk. May cause pimples or hysterical blindness}

 

   If you are looking for something that is not addressed here, please write back.

 

HTH,

Raymond

 

Edited by MullinRJ
  • Like 1

Share this post


Link to post

hey raymond

 

thanks for the long detailed reply very helpul. One of the reasons i was looking at that script was that on some symbols, when i use the convert-convert to group command, it wasnt giving the dialogue box with the convert all sub-objects. Im not too sure why that is happening only for some symbols. 

 

any clues? 

Share this post


Link to post

You're welcome, Rex.

 

When a symbol only has simple objects inside, like Lines, and Circles, and Squares (oh my), you won't see the dialog box because there is only one way to decompose it. But if there are nested symbols and or Plug-in Objects inside, then you'll get the dialog asking you how to proceed. Do you want to preserve nested symbols, or flatten everything? If you pick the first option, then you can reselect objects after the operation and proceed "delicately". If you pick the third option, it's like you hit everything with a sledge hammer and everything comes out crumbs – or Lines, and Circles, and Squares (oh my).

 

Essentially, VW is looking inside your symbols first and only presenting you with the dialog if it will change how they get converted; otherwise it converts everything to primitive shapes, no questions asked. If your symbols only have one primitive object in each of them, then you won't get any groups, just the primitive objects. Symbols containing two or more objects will convert to groups.

 

HTH,

Raymond

Share this post


Link to post

ah ive realised my query is a little different. I want to convert several symbols contained within a group into basic objects. Because the symbols are in a group (not a larger symbol) it is quite time consuming to select them all individually converty them one by one, so i wanted something that would do all symbols in a file into basic elements. 

 

perhaps the best work around is to turn my all encompassing group into a symbol momentarily, and then use the command you refered to above. That wouldnt be too time consuming 

 

 

Share this post


Link to post
Posted (edited)

Hello Rex,

   Try this script on for size. It is a little different from the script Pat posted, and only works on selected objects on a drawing layer. Select everything you want flattened (i.e., Groups and Symbols) then run the script. Please try it on a COPY of your data first to determine its efficacy.

PROCEDURE FlattenSymsInGroups;
{ Flatten selected Symbols, and Symbols inside Groups. }
{ 15 May 2020 - Raymond J Mullin }

{ BE CAREFUL: }
{ Use on a copy of your file first to determine if this script does what you want. }
{ Always wear a mask. This script does not Social Distance in GROUPS. }

	function FlattenNestedSyms(H :Handle) :Boolean;
	Begin
		if (GetTypeN(H) = 15) then
			SymbolToGroup(H, 2);
	End;		{ FlattenNestedSyms }

BEGIN
	ForEachObjectInLayer(FlattenNestedSyms, 3, 2, 0);	{ Vis & Selected, Deep, Active Layer }
	SysBeep;		{ Beep when done }
END;
Run(FlattenSymsInGroups);

HTH,

Raymond

Edited by MullinRJ
spelling
  • Like 1

Share this post


Link to post

ok great thanks, looks like what i need will have a go and report back 

 

cheers 

Share this post


Link to post

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.


 

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.

×
×
  • Create New...