Using %USERPROFILE% to load lisp routines in acaddoc.lsp

Using %USERPROFILE% to load lisp routines in acaddoc.lsp

WeberThompson
Enthusiast Enthusiast
1,671 Views
9 Replies
Message 1 of 10

Using %USERPROFILE% to load lisp routines in acaddoc.lsp

WeberThompson
Enthusiast
Enthusiast

I am trying to load lisp routines using the %userprofile% variable but it is not working.

Here is the contents of my Acaddoc.lsp file.

 

(print "Printer setup started.")
(vl-load-com)
(vlax-for ps (vla-get-plotconfigurations
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-delete ps)
)
(setq expert (getvar "expert"))
(setvar "expert" 2)
(command "._-PSETUPIN"
(strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Library/Blocks/Templates/2018_Page_Setups.dwt"
"*"
)
(setvar "expert" expert)

(print "Printer setup completed.")

;; This loads custom WT Page Setups
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/WT_Pagesetups.lsp")

;; This loads custom Steel Lisp Routine
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/stl.lsp")

;; This loads custom Layer Director Lisp Routine
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/LayerDirectorV1-2.lsp")

;; This loads custom Fast Lisp Routine
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/Fast.lsp")

;; This loads custom Room Area Lisp Routine
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/Areas2FieldV1-3.lsp")

0 Likes
Accepted solutions (1)
1,672 Views
9 Replies
Replies (9)
Message 2 of 10

cadffm
Consultant
Consultant

Whats could be wrong at this point?

 

(setvar "expert" 2)
(command "._-PSETUPIN"
(strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Library/Blocks/Templates/2018_Page_Setups.dwt"
"*"
)
(setvar "expert" expert)

 

 

 

Sebastian

0 Likes
Message 3 of 10

WeberThompson
Enthusiast
Enthusiast

I do not see how that is any different.

Could you please not be sarcastic.

0 Likes
Message 4 of 10

cadffm
Consultant
Consultant

And 1-2 hints more:

Write and test your code step by step, not write 100 lines and then try if it works.

Use VLide debugging to find the problem.

 

And: Don't testing new code directly in acad(doc).lsp!

a) If you made one mistake and open one or twenty files, perhaps you kill the work.

b) Running code from a lispfile which is loaded by hand (well) don't must work inside the acad(doc).lsp,

it is possible that at this time where the file loaded not all functions works well.

But if you create&testing new code in this file, you never know if it is a code problem or a problem of timeing.

Create your code in VLide (or if you like pain in another editor) and load the the stuff in your ready opened (current) drawing.

If that works, try it inside the acad(doc).lsp. My2ct

 

 

Sebastian

0 Likes
Message 5 of 10

cadffm
Consultant
Consultant

@WeberThompson schrieb:

I do not see how that is any different.

Could you please not be sarcastic.


No sarcastic!, I only wanted that you find your mistake self and show you the important part of the code.

 

"(setvar "expert" 2)
(command "._-PSETUPIN"
(strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Library/Blocks/Templates/2018_Page_Setups.dwt"
"*"
)); You did not have one closing bracket for the (command statement here, I did not look at the rest
(setvar "expert" expert)"

Sebastian

0 Likes
Message 6 of 10

doaiena
Collaborator
Collaborator

You need to close the parenthesis for the "psetupin" command and the "load" statements at the bottom.

PS:

Paths should be written with a double backslash.
(strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Lisp\\LayerDirectorV1-2.lsp")

Message 7 of 10

WeberThompson
Enthusiast
Enthusiast

First of all, I know that everything except the path is correct because I use it for non-remoting users.

You need to GO AWAY.  I already reported you to the moderator.

 

It is people like you that make this forum suck.

Message 8 of 10

cadffm
Consultant
Consultant

@WeberThompson schrieb:

"I know that everything except the path is correct"


Not in your posted code, see above.

 

doaiena and I gave you a solution and good general hints, i am sorry that you don't liked my kind of the first answer, but please

a little more manners, thanks. An impudence to trample on you well-meaning help.

 

correct my typo above and completed:

(print "Printer setup started.")
(vl-load-com)
(vlax-for ps (vla-get-plotconfigurations
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-delete ps)
)
(setq expert (getvar "expert"))
(setvar "expert" 2)
(command "._-PSETUPIN"
(strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Library/Blocks/Templates/2018_Page_Setups.dwt"); missing bracket here
"*"
)
(setvar "expert" expert)

(print "Printer setup completed.")

;; This loads custom WT Page Setups
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/WT_Pagesetups.lsp")); missing bracket here

;; This loads custom Steel Lisp Routine
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/stl.lsp")); missing bracket here

;; This loads custom Layer Director Lisp Routine
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/LayerDirectorV1-2.lsp")); missing bracket here

;; This loads custom Fast Lisp Routine
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/Fast.lsp")); missing bracket here

;; This loads custom Room Area Lisp Routine
(load (strcat (getenv"userprofile") "/desktop/WT_AutoCAD/Lisp/Areas2FieldV1-3.lsp")); missing bracket here

 

Sebastian

0 Likes
Message 9 of 10

WeberThompson
Enthusiast
Enthusiast
Accepted solution

For anyone who is interested, here is the correct code:

 

(print "Printer setup started.")
(vl-load-com)
(vlax-for ps (vla-get-plotconfigurations
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-delete ps)
)
(setq expert (getvar "expert"))
(setvar "expert" 2)
(command "._-PSETUPIN"
(strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Library\\Blocks\\Templates\\2018_Page_Setups.dwt");
"*"
)
(setvar "expert" expert)

(print "Printer setup completed.")

;; This loads custom WT Page Setups
(load (strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Lisp\\WT_Pagesetups.lsp"));

;; This loads custom Steel Lisp Routine
(load (strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Lisp\\stl.lsp"));

;; This loads custom Layer Director Lisp Routine
(load (strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Lisp\\LayerDirectorV1-2.lsp"));

;; This loads custom Fast Lisp Routine
(load (strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Lisp\\Fast.lsp"));

;; This loads custom Room Area Lisp Routine
(load (strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Lisp\\Areas2FieldV1-3.lsp"));

 

 

0 Likes
Message 10 of 10

doaiena
Collaborator
Collaborator

I think a better solution would be to loop through the custom routines, instead of loading them one by one. Also you should get rid of the "expert" variable. It's never a good idea to leave unlocalized variables.

(print "Printer setup started.")
(vl-load-com)
(vlax-for ps (vla-get-plotconfigurations
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-delete ps)
)
(setq expert (getvar "expert"))
(setvar "expert" 2)
(command "._-PSETUPIN"
(strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Library\\Blocks\\Templates\\2018_Page_Setups.dwt")
"*"
)
(setvar "expert" expert)
(setq expert nil)
(print "Printer setup completed.")

;load custom routines
(mapcar '(lambda (lsp) (load (strcat (getenv"userprofile") "\\desktop\\WT_AutoCAD\\Lisp\\" lsp)))
(list "WT_Pagesetups.lsp" "stl.lsp" "LayerDirectorV1-2.lsp" "Fast.lsp" "Areas2FieldV1-3.lsp")
)
0 Likes