Why does foreach layoutlist command acting weird?

Why does foreach layoutlist command acting weird?

oli-123
Contributor Contributor
1,179 Views
5 Replies
Message 1 of 6

Why does foreach layoutlist command acting weird?

oli-123
Contributor
Contributor
(defun c:ttest (/ lay startNOMUTT)

;;;Simple LISP routine to place a circle on every Layout....or does it?;;;
(setq startNOMUTT (getvar "NOMUTT")) (setvar "NOMUTT" 1) (foreach lay (layoutlist) (command "CIRCLE" "0,0" 5)
(command "ZOOM" "E") (setvar "CTAB" lay) ) ;foreach layout (setvar "NOMUTT" startNOMUTT) (princ) ) ;defun (princ)

 

Hello there,

 

After testing this command on a blank drawing with 2 layouts, the circles are placed differently depending on my current Layout tab (before using the LISP routine).

  1. If my current layout tab is on Model space, a circle is placed on the Model space and Layout1 tab.
  2. If my current layout tab is on Layout1, two circles are placed on Layout1 tab.
  3. If my current layout tab is on Layout2, a circle is placed on Layout1 and Layout2.

So my question is, what's up with this inconsistency? How can I make sure only one circle is placed on each layout (preferably excluding the Model space)?

 

Bonus Question: The NOMUTT variable doesn't seem to suppress the command messages. How come?

 

FYI, I'm using AutoCAD Civil 3D 2018.

0 Likes
Accepted solutions (1)
1,180 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant
Accepted solution

Take time and read your code:

Example is a dwg with two layouts and the current layout is layout1

 

 

(foreach lay (layoutlist) (command "CIRCLE" "0,0" 5)
(command "ZOOM" "E") (setvar "CTAB" lay) ) ;foreach layout

 

Is the same as:

 

(command "CIRCLE" "0,0" 5) ; you create a circle in current space (=layout1)
(command "ZOOM" "E"); zoom extents in current space (=layout1)

(setvar "CTAB" "layout1"); set layout1 as current layout

(command "CIRCLE" "0,0" 5); create another circle in current layout (=layout1)
(command "ZOOM" "E"); zoom in....layout1

(setvar "CTAB" "layout2"); set layout current.

 

and now the foreach "loop" ends.

 

Set your setvar ctab statement first, then create your circle and zoom.

 

Sebastian

0 Likes
Message 3 of 6

dlanorh
Advisor
Advisor

@oli-123 wrote:
(defun c:ttest (/ lay startNOMUTT)

;;;Simple LISP routine to place a circle on every Layout....or does it?;;;
(setq startNOMUTT (getvar "NOMUTT")) (setvar "NOMUTT" 1) (foreach lay (layoutlist)
(setvar "CTAB" lay) (command "CIRCLE" "0,0" 5)
(command "ZOOM" "E") ) ;foreach layout (setvar "NOMUTT" startNOMUTT) (princ) ) ;defun (princ)

 

Hello there,

 

After testing this command on a blank drawing with 2 layouts, the circles are placed differently depending on my current Layout tab (before using the LISP routine).

  1. If my current layout tab is on Model space, a circle is placed on the Model space and Layout1 tab.
  2. If my current layout tab is on Layout1, two circles are placed on Layout1 tab.
  3. If my current layout tab is on Layout2, a circle is placed on Layout1 and Layout2.

So my question is, what's up with this inconsistency? How can I make sure only one circle is placed on each layout (preferably excluding the Model space)?

 

Bonus Question: The NOMUTT variable doesn't seem to suppress the command messages. How come?

 

FYI, I'm using AutoCAD Civil 3D 2018.


You are changing the layout tab AFTER the first circle is drawn so it depends on which tab you are currently on.

See above, it need to be the first thing in the list. If you (princ (layoutlist)) you will see that the model tab is not a layout so should never get a circle.

 

Don't use (nomutt) it suppresses error messages, and if your lisp errors you are left without a command prompt. Set cmdecho  to 0 instead.

I am not one of the robots you're looking for

0 Likes
Message 4 of 6

oli-123
Contributor
Contributor

Don't use (nomutt). If your lisp errors you are left without a command prompt. Set cmdecho  to 0 instead


 

Thanks everyone! Regarding the cmdecho variable, it's able to suppress the (command) messages but not the regen messages. How would I suppress both of them? Would I have to use both (nomutt) and (cmdecho)?

0 Likes
Message 5 of 6

dlanorh
Advisor
Advisor

Why do you want to suppress everything? If something goes wrong you won't know why as nomutt supresses the error messages.

 

from @cadffm  post above, these steps

 

(command "CIRCLE" "0,0" 5) ; you create a circle in current space (=layout1)
(command "ZOOM" "E"); zoom extents in current space (=layout1)
(setvar "CTAB" "layout1"); set layout1 as current layout
(command "CIRCLE" "0,0" 5); create another circle in current layout (=layout1)
(command "ZOOM" "E"); zoom in....layout1
(setvar "CTAB" "layout2"); set layout current.

 

are carried out whilst "nomutt" is on. This means that even after "nomutt"  is successfully turned off, there is the potential to "undo" back into a state where "nomutt" is on, and no command line; since there are no group "undo" marks being set to avoid this. If you play with fire, without the correct equipment, you will eventually get burnt.

 

There is a reason why it was an undocumented system variable.

 

If you don't want to see the regen messages then stick a (princ"\n") after the zoom command to scroll everything up or make your command line window smaller

I am not one of the robots you're looking for

0 Likes
Message 6 of 6

oli-123
Contributor
Contributor

Huh, I didn't give much thought about the potential danger of using nomutt because I didn't know how dangerous it is. But I'll take your advice and avoid using it. Thanks all!

0 Likes