Jump to content
MTRobin

Un-group or Explode Symbol Script

Recommended Posts

Hi Everyone,

 

I have a script that converts a symbol to a group and then ungroups it. This is assigned to a shortcut so I can quickly "explode" symbols. I would like to add an IF statement so if the selected objects are a symbol is will convert symbol to group and then ungroup it. If it is a group it will just ungroup it. It would be great if this worked with a multiple selection of a mixture of groups and symbols. Can anyone help me write the IF statement?

 

PROCEDURE ExplodeSymbol;

VAR
Selection : HANDLE;

BEGIN
    Selection:= FSActLayer;
    SymbolToGroup(Selection,0);
    Ungroup;
END;
Run(ExplodeSymbol);

 

Thank you,

 

Maxwell

Share this post


Link to post

Not to rain on your scripting parade, but command+k command+u?

 

Applying the script to all selected objects adds a couple levels of complexity — not a lot, but beyond basic.

Share this post


Link to post

I know about the key commands. I was trying to automate the process into a single script I can then assign a key command.

 

Would you be able to help with applying the script to all objects?

 

Thanks

 

Maxwell

Share this post


Link to post

Untested

 

PROCEDURE ExplodeSymbol;
VAR
	Selection : HANDLE;
	arrSelH   : dynarray[] OF handle;
	numObjects : integer;
	i			:INTEGER;
	hPrev		:HANDLE;

{---------------------------------------------------------------------}
FUNCTION AddToArr( h :HANDLE) : boolean;
	BEGIN
		numObjects := numObjects + 1;
		arrSelH[numObjects] := h;
	END;


BEGIN
	ALLOCATE arrSelH[1..Count('sel=true')];
	numObjects := 0;
	ForEachObjectInList( AddToArr, 2, 0, FSActLayer );
	FOR i:=1 TO numObjects DO BEGIN
		if GetTypeN( arrSelH[i]) = 15 THEN BEGIN
			hPrev := PrevObj( arrSelH[i]);
			SymbolToGroup( arrSelH[i], 0);
			arrSelH[i] := NextObj(hPrev);
		END;
		if GetTypeN( arrSelH[i]) = 11 THEN begin
			HUngroup( arrSelH[i]);
		END;
	END;	
END;
Run(ExplodeSymbol);

 

Share this post


Link to post

Thank you!

 

I am getting an error message. Please see attached.

 

Best,


Maxwell

image.png

Share this post


Link to post

Try this.  It will only go on level deep.  If you want to explode symbols in symbols or you want to ungroup groups within groups more is needed.

 

PROCEDURE ExplodeSymbol;


{---------------------------------------------------------------------}

PROCEDURE Explode( h :HANDLE);
    BEGIN
        IF Gettype(h) = 15 THEN
            BEGIN
                SymbolToGroup(h,0);
                HUngroup(h);
            END
        ELSE IF Gettype(h) = 11 THEN
            HUngroup(h);
    END; {PROCEDURE Explode}

{---------------------------------------------------------------------}

BEGIN
    ForEachObject( Explode, ((SEL=TRUE)));
END;
Run(ExplodeSymbol);

Share this post


Link to post
On 8/20/2019 at 7:09 PM, MTRobin said:

Thank you!

 

I am getting an error message. Please see attached.

 

Best,


Maxwell

image.png

 

Looking at Sam’s code, Count('sel=true') should probably be Count((SEL=TRUE))

I might also start with setting numObjects := Count((SEL==TRUE)) and testing:

IF numObjects > 0 THEN BEGIN

Allocate....

 

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