Help with LISP

Help with LISP

peterjwinberg
Advocate Advocate
1,247 Views
17 Replies
Message 1 of 18

Help with LISP

peterjwinberg
Advocate
Advocate

I'm new to LISP and can't figure this out. This is basically a copy-and-paste LISP I threw together because I don't know how to write them from scratch. It's supposed to end in model space, but it doesn't:

 

 

(defun C:LINEFIX ()
(command "LTSCALE" 48)
(foreach lay (layoutlist)(command "_LAYOUT" "_Set" lay "PSLTSCALE" 0))
(command "_LAYOUT" "_Set" "MODEL")
(princ)
)

 

 

 

After the last layout tab PSLTSCALE is updated to 0 it runs the layout command, but for some reason ends up switching to a layout instead of staying in model space. See attached command line screenshot. I've tried using tilemode but couldn't get that to work either.

 

Just not my area of expertise and need some help. I'm sure it's an easy fix.

0 Likes
Accepted solutions (1)
1,248 Views
17 Replies
Replies (17)
Message 2 of 18

DannyNL
Advisor
Advisor
Accepted solution

Try this one.

 

(defun C:LINEFIX ()
   (command "LTSCALE" 48)
   (foreach lay (layoutlist) (command "_LAYOUT" "_Set" lay "PSLTSCALE" 0))
   (setvar "CTAB" "MODEL")
   (princ)
)
0 Likes
Message 3 of 18

DannyNL
Advisor
Advisor

Or even better, remove all the commands and just use setvar

 

(defun C:LINEFIX ()
   (setvar "LTSCALE" 48)
   (foreach lay (layoutlist)
      (setvar "CTAB" lay)
      (setvar "PSLTSCALE" 0)
   )
   (setvar "CTAB" "MODEL")
   (princ)
)
0 Likes
Message 4 of 18

peterjwinberg
Advocate
Advocate

Same result 😞

0 Likes
Message 5 of 18

peterjwinberg
Advocate
Advocate

Oops, posted last reply before I saw this. Give me a minute...

0 Likes
Message 6 of 18

DannyNL
Advisor
Advisor

The routine seems to run fine in AutoCAD Vanilla in which I tested.

 

What are you using?

Plain AutoCAD Vanilla or an AutoCAD vertical like ie Plant 3D or Architecture?

 

 

0 Likes
Message 7 of 18

peterjwinberg
Advocate
Advocate

Still ends up in a paper space layout 😞

 

Maybe it's a bug in my system.

 

0 Likes
Message 8 of 18

peterjwinberg
Advocate
Advocate

Vanilla 2015.

0 Likes
Message 9 of 18

DannyNL
Advisor
Advisor

Just checked in AutoCAD 2014 (I only have 2014, 2016 & 2017 installed) but no errors and I end up in Model even if another layout is active when running the command.

 

Are there any active reactors that may switch to a predefined layout?

If you type (vlr-reactors) on the command line, does it return anything other than nil?

0 Likes
Message 10 of 18

peterjwinberg
Advocate
Advocate

Just nil.

0 Likes
Message 11 of 18

peterjwinberg
Advocate
Advocate

It seems to work in some drawings and not others. Good enough I suppose.

0 Likes
Message 12 of 18

DannyNL
Advisor
Advisor

Peter,

 

Would it be possible to post one of the drawings it doesn't work in, so I'm able to investigate why it doesn't work in that drawing?

You can erase everything in the drawing as long as the drawing still has the same problem of not switching to Model.

0 Likes
Message 13 of 18

peterjwinberg
Advocate
Advocate

No prob. See attached. I also included the lisp I went with.

0 Likes
Message 14 of 18

DannyNL
Advisor
Advisor

Mmhhh....strange.

I've tested your drawing in AutoCAD 2014 & 2017 with your LISP and everything seems to be working fine. All variables are being set and the Model tab is activated without any problems or messages.

 

However, when opening the drawing I got a message regarding a proxy object regarding an app VisionREZ from a company Ameri-CAD.

Any change you have this running on your system in AutoCAD and this is program is the cause of automatically switching between Model and a Paperspace layout?

0 Likes
Message 15 of 18

peterjwinberg
Advocate
Advocate

No, we're not running that.

 

We have a large catalog of plans, most of which (to my knowledge) were drawn primarily with AutoCAD. However, before my time (been here less than a year) the CAD standards and management were poor and I wouldn't be surprised if non-Autodesk products (like this VisionREZ) were used for various reasons. It's not the first bug I've stumbled across, and it's something we'll just have to deal with. After we cycle through all the plans we want updated (+/- 120) then it will be a non-issue anyways.

 

 

If you think of a fix then please let me know, otherwise thank you SO MUCH for your time!

0 Likes
Message 16 of 18

DannyNL
Advisor
Advisor

You're welcome but it still bugs me that you have the problem in some of your drawings Smiley Wink

 

If you are not using that app anymore, you might try to clean the drawing from the unused proxy objects and all other not used stuff by WBLOCK'ing your entire drawing to another drawing. If the LISP then runs without any problems, it might probably had to do with something inside the drawing combined with your PC/AutoCAD installation, although it's difficult to pinpoint the exact cause.

 

Wblock.png

0 Likes
Message 17 of 18

peterjwinberg
Advocate
Advocate

WBLOCK'd, recovered, purged... still happened. I don't know man... sometimes I just let AutoCAD win...

 

0 Likes
Message 18 of 18

DannyNL
Advisor
Advisor

Hahaha......well, that still doesn't change the fact that it still bugs me Smiley Wink

 

But I'm out of ideas at the moment as I'm unable to replicate the problem on my system with your drawing and code.

Although the *cancel* lines in your screenshot suggest there is something running in the background of AutoCAD that messes up the switching to model. But what it is will remain a mystery for now I guess.

0 Likes