Command line command to move to layout and do other commands

Command line command to move to layout and do other commands

MrMuscl3
Advocate Advocate
5,228 Views
18 Replies
Message 1 of 19

Command line command to move to layout and do other commands

MrMuscl3
Advocate
Advocate

I have a drawing which does not have any printing intelligence inside it. In the drawings modelspace there are almost 100 sheets that needs to be printed. These drawings are located with same pattern. Now, I have created "zoom window command generator" with excel for zooming these areas to viewports inside each layout. Here is example of what my excel already does:

 

Zoom window 25.5,22.5 445.5,319.5
Zoom window 25.5,337.5 445.5,634.5
Zoom window 25.5,652.5 445.5,949.5
Zoom window 25.5,967.5 445.5,1264.5
Zoom window 466.5,22.5 886.5,319.5

 

This excel needs to know first sheet offset from origo (x and y coordinate), size of the windows and space between the windows. Thats all for now.

 

I would like to make it work so that I can just copy these commands from my excel to autocad without having to be in the same layout which the command was created for and without being "inside" the viewport. I am aware of things that these commands lack at moment but I dont have enough knowledge to fullfill them.

 

Steps that need to be added from my point of view are following:

 

1. Set current layout (move to layout with its name, these names are added to my excel)

2. Choose the viewport inside the chosen layout (double click the viewport to be active, these layouts have only one viewport which was created with mview fit command)

AutoCAD 2025
0 Likes
5,229 Views
18 Replies
Replies (18)
Message 2 of 19

pendean
Community Legend
Community Legend
Q: why not have one template file with all of this already done ahead of time, then just start with that DWG file for new projects?
0 Likes
Message 3 of 19

cadffm
Consultant
Consultant
Do you have or create the Layout(names)?
Ok
command Layout Option Set
command mspace (and pspace)

?

Sebastian

Message 4 of 19

h_s_walker
Mentor
Mentor

To do what you ask add the following before each of the zoom commands

 

LAYOUT;S:*Put your layout name here*;mspace;

 

 

Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Left Handed and Proud

Message 5 of 19

MrMuscl3
Advocate
Advocate

pendean: I'm creating this "tool" especially for old projects. My company already has templates and every other thing for starting new projects. Every now and then we get these "renovate" projects and the digital documentation we get with these projects is what it is. I allways have to do few tricks with the files before start modifying them. Especially ones that come from different CAD software.

 

And when the customer changes - very often the reference changes too and can't apply same template everytime. Changes in the reference are sheet window size (sometimes A3, A4 or some other standard or no stardard at all) and distances between the windows.

 

This excel I'm creating needs only offset from origo, sheet window size and offset between windows, also layout names (which are pretty standard for my uses Layout (01), ... , Layout (99). And I think with this tool it is easy to create layout viewports with automated zooming. After creating these to first drawing I can bring the settings from it to next 49 with import feature.

 

I have also just started to use autocad more so Im kind of trying to learn and understand. AutoCAD command line seems to be very usefull for automating things to happen. I just dont know yet how to use it effectively.

AutoCAD 2025
0 Likes
Message 6 of 19

h_s_walker
Mentor
Mentor

Sorry, made a very tiny mistake. It should be a semicolon after the S. Like below

 

LAYOUT;S;*Put your layout name here*;mspace;

Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Left Handed and Proud

0 Likes
Message 7 of 19

pendean
Community Legend
Community Legend
Thanks for the info: how about something like this https://www.scriptsheets.com/
Message 8 of 19

cadffm
Consultant
Consultant

; is for Macros, not for Scripts,

-

Excel is cool for writing Scripts, but for <enter> Textstrings where [Space] are allowd,
you need a Line-Break for a real <enter>.
This is without (VBA) programming then not so funny, Because you have to leave the elegant ONE-LINE formatting
The link from Pendean is certainly a good thing, there everything is necessary in an ExtraProgramm prepared (dll)
to create the finished script.

If you are not allowed to install any programs:
Then you look for an Excel VBA solution or you can do it yourself in VBA.
If a VBA solution is not allowed, maybe it can be your text editor. (TextPAD, NotePAD++..)
Insert a special string as Enter, for example ";"
Copies everything into a good text editor and serach% replace. Search ";" And replace with "<newLine>"


Script for: [create new Layout], set active, [create MVIEW], going into, Zoom, going back to Paperspace.


before Excel:
_.OSNAPCOORD 1
_.PSPACE
_.MODEL
_.UCS _world
_.VTENABLE 2
_.LAYOUT    _new    Layout3;    _.LAYOUT    _set    Layout3;    _.MVIEW    0,0    290,200    _.MSPACE    _.ZOOM    480,0    680,180    _.PSPACE    _.ZOOM    _e
_.LAYOUT    _new    Layout4;    _.LAYOUT    _set    Layout4;    _.MVIEW    0,0    290,200    _.MSPACE    _.ZOOM    720,0    920,180    _.PSPACE    _.ZOOM    _e
_.LAYOUT    _new    Layout5;    _.LAYOUT    _set    Layout5;    _.MVIEW    0,0    290,200    _.MSPACE    _.ZOOM    960,0    1160,180    _.PSPACE    _.ZOOM    _e
_.VTENABLE 3

after Copy to Texteditor(TextPAD,Notepad++ aso), search$replace:
_.OSNAPCOORD 1
_.PSPACE
_.MODEL
_.UCS _world
_.VTENABLE 2
_.LAYOUT    _new    Layout3
    _.LAYOUT    _set    Layout3
    _.MVIEW    0,0    290,200    _MSPACE    _ZOOM    480,0    680,180    _.PSPACE    _.ZOOM    _e
_.LAYOUT    _new    Layout4
    _.LAYOUT    _set    Layout4
    _.MVIEW    0,0    290,200    _MSPACE    _ZOOM    720,0    920,180    _.PSPACE    _.ZOOM    _e
_.LAYOUT    _new    Layout5
    _.LAYOUT    _set    Layout5
    _.MVIEW    0,0    290,200    _MSPACE    _ZOOM    960,0    1160,180    _.PSPACE    _.ZOOM    _e
_.VTENABLE 3

Sebastian

Message 9 of 19

steven-g
Mentor
Mentor

Just so we are all clear on this it would be helpfull if you could post an example of what you are trying to achieve, I read this in two ways, is it 100 print areas in modelspace to be automatically printed, using an offset for each or is it 100 named paperspace layouts that each have 1 single "viewport" that needs activating and then zoom to a diferent location in modelspace with a know offset. And then the paperspace layout printed.

Message 10 of 19

cadffm
Consultant
Consultant

1. Set current layout (move to layout with its name, these names are added to my excel)

2. Choose the viewport inside the chosen layout (double click the viewport to be active, these layouts have only one viewport which was created with mview fit command)

 

Layout and Mview exist, ok:

Example File - Without additional programming

Sebastian

Message 11 of 19

MrMuscl3
Advocate
Advocate

I attached now an example. There are 3 drawing files from which 2 are external references. I also added 3 missing autocad fonts (.shx). These files are originally Micro Station .dgn so you need to set these 3 files to your AutoCAD font folder.

 

My skills are not good enough yet for creating script for autocad. I've used AutoCAD LT officially just for 1 month. I started creating these printing layouts by hand and after that got idea that couldnt this all be done with certain command chain. So I'm now creating officially my first tool to help me in future projects and the outcome will be most likely the same as everyones first tool they ever created for helping themselves 🙂 Its not gonna be perfect or rocket science but its a start. I dont know how to code VBA or if my AutoCAD has support it or not.

 

It is not very important for this tool to create these layouts since its very easy to create 1 layout with certain viewport (fit) and then copy it as 2, 4, 8, 16, 32, 64. So there is no big victory in time by importing this feature. The real time goes surfing between multiple layouts, picking the viewport, zooming the window by hand. Since my knowledge is pretty low, I thought the best feature for me is to start creating these command chains which should look something like this:

 

layout set Layout (01) ms zoom window 5.5 200.200

 

When this command is written to command line, following message appears: Command: layout
Enter layout option [Copy/Delete/New/Template/Rename/SAveas/Set/?] <set>: set
Enter layout to make current <Layout (01)>: Layout (01) ms zoom window 5.5 200.200
Cannot find layout "Layout (01) ms zoom window 5.5 200.200".

 

I realize that there is not "press enter" after the layout pick "Layout (01)". How can the "press enter" be applied to here?

 

And after my excel creates these chains I would like to apply them to autocad all at once. How would that be possible? Now the only way I know is copy the chains one by one from excel and paste it to command line and press enter.

AutoCAD 2025
0 Likes
Message 12 of 19

h_s_walker
Mentor
Mentor

If your layout has spaces you need to need to put the layout name in speech marks

 

eg. "This is a layout name which has spaces in it"

Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Left Handed and Proud

Message 13 of 19

MrMuscl3
Advocate
Advocate

I added "" around the layout name and it still wouldnt work 😞

 

layout set "Layout (01)" ms zoom window 5.5 200.200

 

Enter layout option [Copy/Delete/New/Template/Rename/SAveas/Set/?] <set>: set
Enter layout to make current <Layout (01)>: "Layout (01)" ms zoom window 5.5 200.200
Cannot find layout ""Layout (01)" ms zoom window 5.5 200.200".

AutoCAD 2025
0 Likes
Message 14 of 19

h_s_walker
Mentor
Mentor

Change MS to MSPACE.

 

Also make sure the layout name is exactly the same as what is written between the speech marks". No double spaces between words. No spaces before LAYOUT or after (01)

 

Command: SCR
SCRIPT
Command: layout
Enter layout option [Copy/Delete/New/Template/Rename/SAveas/Set/?] <set>: set
Enter layout to make current <A2_>: "Layout (01)" Regenerating layout.
Regenerating model.

Command: mspace
Command: zoom
Specify corner of window, enter a scale factor (nX or nXP), or
[All/Center/Dynamic/Extents/Previous/Scale/Window/Object] <real time>: window
Specify first corner: 5.5 Specify opposite corner: 200.200

 

The above was from a script containing the following

 

layout set "Layout (01)" mspace zoom window 5.5 200.200

Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Left Handed and Proud

Message 15 of 19

steven-g
Mentor
Mentor

You need to rethink the script a little, the problem is when Autocad encounters a command that expects a text input it takes anything following as text so in a script or copy paste from excel you have to format your code so that the text is the last item on the row, and then Autocad reads the end of line as the end of the text input. I have attached a full working excel and text file (change the .txt to .scr), notice as well the subtle difference between script and excel copy paste, a script needs quotes. In both script and excel you use a space as <enter> in a macro everything changes again and ";" a semicolon can be used as <enter>

The different first and last line of the attached make sure that the layout name is Always at the end, and the extra 4 layouts in the script are to show that it doesn't cause any problems having a too long script as the last few lines just give the error message that a layout can't be found.

Message 16 of 19

MrMuscl3
Advocate
Advocate

First of all I would like to thank hwalker and steven-g for walking me through this. There is much for me to learn in AutoCAD since I've used it very little. AutoCAD has much functions which the users dont even know. Since I'm going to work with AutoCAD for ~38 years I really want to know how to get the most of the program. I think best way for me to start "automating" things is now to write these scripts since the input with the scripts is very much the same as with command line. Maybe in near future I will dig deeper into macros. I already have my first macro for sequential numbering and it didnt seem too hard to understand 🙂

 

I thought that since I started ot create this script, it could have also the missing parts in it which I first decided to do by hand but I became lazy. Things that need to be added:

 

1. create layout with specific name

2. select the viewport inside created layout

3. delete selected viewport

4. create new viewport with option fit

 

This is as far as I got:

 

layout new "Layout (01)" "select viewport" "delete viewport" mview fit mspace zoom window 25.5,22.5 445.5,319.5 pspace
layout new "Layout (02)" "select viewport" "delete viewport" mview fit mspace zoom window 25.5,337.5 445.5,634.5 pspace

empty line

 

Since the default viewport is not "mview fit", I need to delete it and create new. Though, I think the default viewport form can be adjusted to be "fit" the paperspace?

 

How to select the viewport inside layout which is created default by autocad?

AutoCAD 2025
Message 17 of 19

h_s_walker
Mentor
Mentor

You can switch off the creation of layout viewports for new layouts by doing the following

 

At the command line type OPTIONS

 

Choose the DISPLAY tab

 

Bottom left hand side says LAYOUT ELEMENTS

 

untick CREATE VIEWPORT IN NEW LAYOUT

Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Left Handed and Proud

Message 18 of 19

cadffm
Consultant
Consultant

In my appendix above (05-11-2017 / 4Layoutworking.xlsx) in the third Excelsheet tab,
There I had given you some commands and variables on the subject., without a long explanation, as one learns more by own research for the terms.

 

Complementary to hwalker way over the GUI, the way over the UI

SysVar: LAYOUTCREATEVIEWPORT

 

 

 

Sebastian

Message 19 of 19

steven-g
Mentor
Mentor

Seeing that in a new viewport the only thing is a layout (unless you turn it off as stated above), then by selecting and deleting everything you only delete the viewport.

layout new "Layout (01)" layout set "Layout (01)" erase all  mview fit mspace zoom window 25.5,22.5 445.5,319.5 pspace