Jump to content

Sheet Layer Stacking Order


Recommended Posts

I've been using this script for a while.  It doesn't check for temporary duplicate sheet numbers.  So I will add an X in the suffix field or a crazy prefix field, run the script, run it again and set it to what I really want.

 

Let me know if that doesn't make sense 🙂 

 

 

 

 

{Badly scripted by Michael Klaers}
{March 2020}

PROCEDURE RenumberSheetLayers; 

VAR
	
LayerInQuestion
:HANDLE;

LyrTypInt, Counter, StackOrderBegin, StackOrderEnd, RenumStart, 
RenumCount, HowManyLayers, NumDesignLayers, id, item  
: INTEGER;

SheetPrefix, SheetSuffix, NewName, TempString
: STRING;

Bool 	:BOOLEAN;

{******************************** The ever confusing dialog handler ****************}
PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);
BEGIN
	CASE item OF
		SetupDialogC:
			BEGIN
				Bool := GetSavedSetting('SLRename','StackOrderBegin',TempString);
				SetEditInteger(id,6,Str2Num(TempString));
					
				Bool := GetSavedSetting('SLRename','StackOrderEnd',TempString);
				SetEditInteger(id,7,Str2Num(TempString));
					
				Bool := GetSavedSetting('SLRename','SheetPrefix',TempString);
				SetItemText(id,12,TempString);
				
				Bool := GetSavedSetting('SLRename','RenumStart',TempString);
				SetEditInteger(id,13,Str2Num(TempString));
					
				Bool := GetSavedSetting('SLRename','SheetSuffix',TempString);
				SetItemText(id,14,TempString);
			END;
		1:
			BEGIN
					
				Bool := GetEditInteger(id,6,StackOrderBegin);
				Bool := GetEditInteger(id,7,StackOrderEnd);
					
				GetItemText(id,12,SheetPrefix);
				Bool := GetEditInteger(id,13,RenumStart);
				GetItemText(id,14,SheetSuffix);
					
			END;
			2:
				BEGIN
				END;
	END; {Case}
END; {Dialog Handler}

{******************************** The slightly less confusing dialog layout ****************}
PROCEDURE MakeMeADialogBox;
BEGIN
	id:=CreateLayout('Renumber Sheet Layers',TRUE,'OK','Never Mind');
	
	CreateStaticText(id,4,'First',-1);
	CreateStaticText(id,5,'Last',-1);
	CreateEditInteger(id,6,1,6);
	CreateEditInteger(id,7,1,6);
	CreateStaticText(id,9,'Prefix',-1);
	CreateStaticText(id,10,'Num',-1);
	CreateStaticText(id,11,'Suffix',-1);
	CreateEditText(id,12,'A',6);
	CreateEditInteger(id,13,0,6);
	CreateEditText(id,14,'',6);
	
	SetFirstLayoutItem(id,4);
	SetRightItem(id,4,6,0,0);
	SetBelowItem(id,4,5,0,0);
	SetRightItem(id,5,7,0,0);
	SetBelowItem(id,5,9,0,0);
	SetRightItem(id,9,10,1,0);
	SetRightITem(id,10,11,2,0);
	SetBelowItem(id,9,12,0,0);
	SetBelowItem(id,10,13,0,0);
	SetBelowItem(id,11,14,0,0);
	
	SetHelpText(id,4,'Stacking order of first sheet to be renumbered');
	SetHelpText(id,6,'Stacking order of first sheet to be renumbered');
	SetHelpText(id,5,'Stacking order of last sheet to be renumbered');
	SetHelpText(id,7,'Stacking order of last sheet to be renumbered');
	SetHelpText(id,9,'New prefix for renamed sheet layers');
	SetHelpText(id,12,'New prefix for renamed sheet layers');
	SetHelpText(id,10,'New starting number for renamed sheet layers');
	SetHelpText(id,13,'New starting number for renamed sheet layers');
	SetHelpText(id,11,'New suffix for renamed sheet layers');
	SetHelpText(id,14,'New suffix for renamed sheet layers');
END;

BEGIN 								{**** MAIN ****} 


MakeMeADialogBox;	
	
item := RunLayoutDialog(id, Dialog_Handler);

IF item = 1 THEN
	
	BEGIN
		{MESSAGE	('Stacking Begin: ',StackOrderBegin,CHR(13),
				'Stacking End: ',StackOrderEnd,CHR(13),
				'Prefix: ',SheetPrefix,CHR(13),
				'RenumStart: ',RenumStart,CHR(13),
				'Suffix: ',SheetSuffix);}
				
		
		Counter := 1;
		LayerInQuestion:=FLayer;
		HowManyLayers := NumLayers;
		RenumCount := RenumStart;

	For Counter := 1 to HowManyLayers DO			{Step through every layer, including Design Layers}
	BEGIN

		LyrTypInt := GetObjectVariableInt(LayerInQuestion,154);


		{***************************************************************************}
		{Layer type 1 is a design layer.  It counts them from the bottom of the stack to the top.
		Ignore and go to the next layer.  
		But count how many design layers there are. You'll need that later.}

		IF LyrTypInt = 1 THEN
			Begin
			NumDesignLayers := Counter;
			End;

		{***************************************************************************}
		{Now we're in business.  Layer type 2 is a Sheet Layer
		Sheet Layers are counted by stacking order from top to bottom.}

		IF LyrTypInt = 2 THEN
			BEGIN
			
			IF (StackOrderBegin <= (Counter-NumDesignLayers)) AND ((Counter-NumDesignLayers) <= StackOrderEnd) THEN
		
				BEGIN
					NewName := CONCAT(SheetPrefix,Num2Str(0,RenumCount),SheetSuffix);
					SetName(LayerInQuestion,NewName);
					RenumCount := RenumCount + 1;
				END; {IF counter is in change range}
			
			END; {If LyrTypInt is 2 (i.e. Sheet Layer}
			
{***************************************************************************}			
			
		LayerInQuestion:=NextLayer(LayerInQuestion);
		
	END; {1 to number of layers}	

	SetSavedSetting('SLRename','StackOrderBegin',Num2Str(0,StackOrderBegin));
	SetSavedSetting('SLRename','StackOrderEnd',Num2Str(0,StackOrderEnd));
	SetSavedSetting('SLRename','SheetPrefix',SheetPrefix);
	SetSavedSetting('SLRename','RenumStart',Num2Str(0,RenumStart));
	SetSavedSetting('SLRename','SheetSuffix',SheetSuffix);
					
	
END; {If user clicked OK}

END; {main} 

RUN(RenumberSheetLayers);



 

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