Tool palettes and lisp loading

Tool palettes and lisp loading

Buzz0m
Collaborator Collaborator
2,018 Views
7 Replies
Message 1 of 8

Tool palettes and lisp loading

Buzz0m
Collaborator
Collaborator

Hi,

I'm trying to follow the example given in this AU handout by Paul Munford (AU2015, IT10856).

 

The basic idea is to create a ACAD.lsp, which loads another lisp which in turn loads the necessary settings and profiles. For some reason, I cannot get the second lisp to load. The code line is simply

 

(load "B:\\Autodesk\\AutoCAD\\scripts_and_lisps\\testfile.lsp" "Load Failed")

The "load failed" -string is supposed to print on the console if the load failed, right? And if it succeeds it should run all the code in the second lisp-file, right? I placed a (printc "test1")-line right in the beginning of both lisps just to check if they run. The second "test" doesn't show up on the console when I place the ACAD.lsp in the support folder.

 

Do I need to set some variables to allow the ACAD to load from outside trusted locations? I tried setting "Secureload" to 0... still nothing...

 

@PaulMunford can you elaborate?

 

Btw, should one of the strings on page 21 have an extra "\\" in the beginning or end (where the ***-strings are below)?

 

(setq lisp_path “U:\\Support_2016***”) ; sets the path 
(if (findfile (strcat lisp_path "***init.lsp")) ;If you can find a file called 
‘init.lsp’ 
(load (strcat lisp_path "***init.lsp")) ) ;Load the file called ‘init.lsp’

 

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

ambrosl
Autodesk
Autodesk

Make sure AutoCAD is able to locate your ACAD.LSP file, this can be tested by entering the following in the Command Window:

(findfile "acad.lsp")

 

If successful, it should return the path.

 

ACAD.LSP should also be in a trsuted location, which you can test with the following statement:

(findtrustedfile "acad.lsp")

 

Additionally, ACAD.LSP is only loaded in the first drawing by default.  You really should use ACADDOC.LSP to load any LSP files into each drawing they are needed or instruct AutoCAD to load ACAD.LSP each time a drawing is created or opened.  Use the ACADLSPASDOC system variable with a value of 1 to instruct AutoCAD to load ACAD.LSP each time a drawing is created or opened.



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
Message 3 of 8

pbejse
Mentor
Mentor

@Buzz0m wrote:

 

 

The basic idea is to create a ACAD.lsp, which loads another lisp which in turn loads the necessary settings and profiles. For some reason..


I prefer to stay away from any lisp off the out-of-the-box Autocad installation, might it be ACAD or ACADDOC*** .

 

I find Autoloader to be the less troublesome than the other alternatives  As far as i can tell, i don't even need to modify any of the existing Autocad support files for simple loading of lisp/vlx/cuix and what not. nor the system registry.

 

I would suggest you begin to dig into Autlooader. .. for light reading  ---> Autodesk Autoloader White Paper 

 

0 Likes
Message 4 of 8

dgorsman
Consultant
Consultant

ACAD.LSP and ACADDOC.LSP aren't OOTB, strictly speaking.  They are not provided with the standard install and it's up to the user to create and manage them.

 

I'll also point out that the second argument of the (load ...) function isn't printed to the command line.  The value is returned when the function chucks a wobbly.  It's up to the code to decide what to do with that value.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 5 of 8

pbejse
Mentor
Mentor

@dgorsman wrote:

ACAD.LSP and ACADDOC.LSP aren't OOTB, strictly speaking.  They are not provided with the standard install and it's up to the user to create ...


I stand corrected 🙂

 

0 Likes
Message 6 of 8

Buzz0m
Collaborator
Collaborator
Accepted solution

Hi,

first of all a big thanks to all you guys for your replies and tips! Turns out I had a syntax error  in the code. The if statement has to have an else expression in order to work(?)! If I'm wrong please correct me (I'm trying to learn here Smiley Happy ). Here's a simplification of the code:

 

(if (findfile "<filepath>") 
	(
		(load "<filepath>" "loading failed")
	)
	(
		(princ "The file was not found")
	)
)

All the tips you gave me are most likely good and valid, but did you check out the handout? I'm trying to implement company standards and setting up a "easy to use" workspace and tool palette system for my coworkers... can this be done with autoloader @pbejse? How easy is it to maintain and update and deploy to multiple users? Are there any AU sessions that cover the steps of setting up a system like this?

 

@ambrosl my goal is to load (on startup) a profile (with toolpalettes and sup paths), some CUIx-files and set some variables. The goal is to have as little as possible on the users's computers. The idea is to have ACAD.lsp load the other files/settings from network. This way acad.lsp would be the only thing a user has to copy to his support folder. Is there something I'm missing or unaware of? Do you see problems in this way of deploying ACAD (and C3D)?

 

- F

 

 

 

Message 7 of 8

Buzz0m
Collaborator
Collaborator

Thanks guys for the input... I got the code to work by adding a elseexpression to the if statement... according to:

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-AutoLISP/file...

the if-statement shouldn't need one, but this way I got it to run through... another lesson in paying more attention to parentheses and syntaxes...

 

My aim is to have as little as possible on the local drives of the users. ACAD.lsp would be the only file that the IT-department or the users themselves will place in the support path. This file would load the lsp located on a network. This second lisp will load the necessary files etc... is there a smoother way of doing this with autoloader? I'm talkin about toolpalettes, cuix, and settings...

 

- F

0 Likes
Message 8 of 8

ambrosl
Autodesk
Autodesk
Accepted solution

If your goal is to have as few files as possible on the local drive, that can be achieved with or without using ACAD.LSP especially if you are using a CUIx file.  All files are best placed on the network no matter their type, even ACAD.LSP could be on a network drive.  Place the ACAD.LSP file on a network drive and make sure it is in the first path under the Support File Search Path on the Files tab of the Options dialog box, from there it should be the first instance AutoCAD locates and it will be loaded.  It might also be best to create ACADDOC.LSP instead of ACAD.LSP since ACADDOC.LSP will load with each new drawing file created or opened.  ACAD.LSP will only load upon the startup of AutoCAD unless ACADLSPASDOC is set to 1.

 

As an alternative to using ACAD.LSP, you could using an MNL file that has the same name as your CUIx file.  Upon loading of the CUIx file, AutoCAD will look for and attempt to load an MNL file with the same name automatically each time a drawing is created or opened.

 

Another thing that I noticed, while technically fine you have a few extra pairings of parens that are not needed in your AutoLISP code around your LOAD and PRINC statements.  I would also recommend using PROMPT as opposed to PRINC in this case as well.

 

(if (findfile "<filepath>")
  (load "<filepath>" "loading failed")
  (prompt "\nThe file was not found")
)

 

If you are loading multiple LSP files, you might want to consider creating a custom function that contains the statements to simplify the loading of those files.

 

(defun myLSPLoader (filePath / )
  (if (findfile filePath)
    (load filePath "loading failed")
    (prompt "\nThe file was not found")
  )
 (princ)
)

 

(myLSPLoader "L:\\LSPFiles\\blocks.lsp")
(myLSPLoader "L:\\LSPFiles\\revisioncloud.lsp")

 

Just some things to consider, there are many ways to achieve what you are trying to do.  The best of luck with your implementation.

 

The IF function shouldn't need an ELSEIF statement, but it needs to be structured correctly as an IF function will only state two AutoLISP expressions and that is why the PROGN function is often used in combination with the IF function.

 



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation