Jump to content
Developer Wiki and Function Reference Links ×

Un-group or Explode Symbol Script


MTRobin

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

Link to comment

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);

 

Link to comment

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);

Link to comment
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....

 

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.

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.

×
×
  • Create New...