Jump to content
Developer Wiki and Function Reference Links ×

Help - Script to adjust the zoom on all sheet layers to "Fit to Page/Fit to Window"


Recommended Posts

Try the following script and see if it meets your needs.

 

1. This changes the selection state of objects by deselecting everything as I had to draw a new object to fit to.

2. This can be run with any layer active and that layer will still be active after the script it run.

3. There is only one Zoom and View setting in the file, so if you have layers with different page sizes, the zoom will be set to whatever the last SL in the stacking order is. As long as your Sheets are all centered around the same origin and you have not moved the Page Area on any sheets, it should only be an issue of zooming in/out.

4. This command is based on the Page Area, so if you have objects outside of the page area, they might be outside the viewable area.

 

Procedure FitSLs;

{©2025  Pat Stanford - pat@coviana.com}
{licensed under the Boost Software License 1.0}
{https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt}
{TL/DR Use as you want, attribution for source, No warranty}

VAR	H1, H2, OriginalL	:Handle;
	X1,Y1,X2,Y2		:Real;

BEGIN
	OriginalL:=ActLayer;
	H1:=FLayer;
	While H1 <> Nil DO
		BEGIN
			If GetObjectVariableInt(H1, 154) = 2 then 
				BEGIN
					Layer(GetLName(H1));
					GetDrawingSizeRectN(H1, X1,Y1,X2,Y2);
					Rect(X1,Y1,X2,Y2);
					H2:=LNewObj;
					DSelectAll;
					SetSelect(H2);
					DoMenuTextByName('Fit To Objects',0);
					Delobject(H2);
				End;
			H1:=NextLayer(H1);
		End;
	Layer(GetLName(OriginalL));
End;

Run(FitSLs);
					

 

Link to comment

Thank you Joshua.  I was looking for that and could not find 'Fit to Window', so I used the work around using the 'Fit to Objects' after creating a rectangle matching the page area.

 

So the script simplifies to:

 

Procedure FitSLs;

{©2025  Pat Stanford - pat@coviana.com}
{licensed under the Boost Software License 1.0}
{https://github.com/boostorg/boost/blob/master/LICENSE_1_0.txt}
{TL/DR Use as you want, attribution for source, No warranty}

VAR	H1, H2, OriginalL	:Handle;
	X1,Y1,X2,Y2		:Real;

BEGIN
	OriginalL:=ActLayer;
	H1:=FLayer;
	While H1 <> Nil DO
		BEGIN
			If GetObjectVariableInt(H1, 154) = 2 then 
				BEGIN
					Layer(GetLName(H1));
					DoMenuTextByName('Fit To Window',0);
				End;
			H1:=NextLayer(H1);
		End;
	Layer(GetLName(OriginalL));
End;

Run(FitSLs);

 

And if you do have Separate Sheet Views turned on in Options, then you can ignore my comment #3 in the first post as it will zoom every sheet layer to the correct drawing area.

Link to comment

Hi Pat,

in the past we used to have a script like that and we would add it to the saved view, then use the saved view to call the sheet layer. Not as elegant as yours, but for simple people like me used to work. I recently set up a project to use same views for each drawing so that we could ensure that the guides class was turned off on our sheet layers. The architect wanted to use guides on the sheet layers for the placement of the details.

2025-01-25_10-49-56.png

  • Like 1
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...