lisp in script

lisp in script

R_Tweed
Advisor Advisor
958 Views
7 Replies
Message 1 of 8

lisp in script

R_Tweed
Advisor
Advisor

I'm working through a script to load and reload linetypes from multiple files. It seems to run fine except that expert stays set to 3.  I am very green regarding my understanding of lsp and programming in general.  Why would it stop at LTL?

 

(defun C:LTL( )
(command "_.linetype" "_load" "*" "Site.lin"); leaves in command
(command "_load" "*" "Streets.lin"); leaves in command
(command "_load" "*" "Utilities.lin"); leaves in command
(while (> (getvar 'cmdactive) 0) (command "")); Enters until finished
)
expert 3
LTL
expert 0

 

0 Likes
Accepted solutions (2)
959 Views
7 Replies
Replies (7)
Message 2 of 8

pendean
Community Legend
Community Legend

May I ask, why do you want to first-load your LISP every single time you need to use it in each single file instead of just autoloading it all the time when you first open and stay in autocad for a session?

 

EDIT: and why not include your desired EXPERT settings as part of the LISP too?

 

Check out other similar posts in this forum when you get a chance, I'll get you started with some here

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lsp-to-load-or-reload-all-linetypes-...

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lsp-to-load-or-reload-all-linetypes-... 

 

Message 3 of 8

TomBeauford
Advisor
Advisor

Good templates make AutoCAD more productive, having to add or reload linetypes, text styles, dimension styles, etc… on a regular basis sounds like a workflow issue. All layers and blocks in you templates should already have needed linetypes assigned to them. Creating a drawing from scratch without a template could easily take 20 times as much editing time. Having every linetype loaded that may ever be used in a drawing seems excessive. 

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 4 of 8

R_Tweed
Advisor
Advisor

Hi @pendean . This is a one off routine to fix something and maybe use parts for future.  The long version is that I recently combined several individual shape files into one master compiled file, re-wrote some linetype library files and this is causing an issue which reloading the linetypes resolves.

 

Honestly, I have no idea how to add the expert strings into the lisp routine. I get lost in the brackets and as it is the lsp part is taking from other posts.

 

I thought (while (> (getvar 'cmdactive) 0) (command "")); Enters until finished was the part that resolved the prompt for y to reload the linetype but that is not so as it is written as far as I can tell.  I addded the expert setting..

0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

[Those could all be collapsed into one LINETYPE command.]

 

The (while) function in there, in the source from which you copied/pasted stuff [which looks like my way of doing things], was there to supply an unknown quantity of Enters in answer to the question of whether to replace the definition(s) of any linetype(s) already in the drawing.  If you have EXPERT set to 3, those questions will not be asked, so there's no need for that (while) function -- an ordinary Enter "" will conclude the command:

(defun C:LTL ()

  (setvar 'expert 3)
  (command "_.linetype" "_load" "*" "Site.lin" "_load" "*" "Streets.lin" "_load" "*" "Utilities.lin" "")

  (setvar 'expert 0)
)

 

Or, with that included to feed in Enters, there's no need to set the EXPERT value.  I would think just this would work:

(defun C:LTL ()
  (command "_.linetype" "_load" "*" "Site.lin" "_load" "*" "Streets.lin" "_load" "*" "Utilities.lin")

  (while (> (getvar 'cmdactive) 0) (command "")); Enters until finished
)

 

[I agree with @pendean that there are better ways to do this than to have something entirely or almost entirely in AutoLisp code incorporated into a Script.]

Kent Cooper, AIA
0 Likes
Message 6 of 8

ronjonp
Advisor
Advisor

@R_Tweed 

Another way to load multiple files using FOREACH.

(defun c:ltl ()
  (setvar 'expert 3)
  (foreach f '("Site.lin" "Streets.lin" "Utilities.lin") (command "_.linetype" "_load" "*" f))
  (setvar 'expert 0)
)

 

Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

.... there are better ways to do this than to have something entirely or almost entirely in AutoLisp code incorporated into a Script.]


... including the pure-Script version, since the (while) function is needed only if EXPERT is not changed to 3, so if it is, there should be no need to involve AutoLisp at all:

 

expert 3
_.-linetype _load * Site.lin _load * Streets.lin _load * Utilities.lin

 

expert 0

 

Note the blank line, which is the final Enter concluding the Linetype command.

Kent Cooper, AIA
Message 8 of 8

R_Tweed
Advisor
Advisor

This is what I was looking for all along but took the long way to get there..  I am updating and organizing old linetypes and the shape files that are referenced.  Shape files are being combined into one library and shape names are changing to a more organized format. linetype definitions are being updated to point to a single compiled shape file "master.shx"

The reload script, loads shapes and linetypes then purges both for existing drawings that present the notification below.  It seems to work ok, although I'm not that sure of how xref linetype's are handled when visretain=1.

 

 

R_Tweed_1-1711555271684.png

 

0 Likes