Jump to content

Recommended Posts

Posted

Hello everyone, I was just wondering how you guys organize your LISP routines. I currently have a file structure that looks like this.

\AutoLisp
----\lib
--------\libs
--------\...All My Lee-Mac files, thanks LEE :D
--------\lisp-loader.lsp (basically loads all the LEE-MAC routine so that I can use it in my LSP)
----\LM_functions
--------\...basically other Lee-Mac functions that are way too big by themselves.
----\MA_functions
--------\...my functions basically
----\NUMCOUNT.lsp (my own version of numeric counting for blocks, and multileaders)
----\...other projects basically
----\MA-load-lisp.lsp (loads my MA_functions)

 

Basically, for every major project that I have, by themselves without external loading of scripts that I use, the lsp file reaches thousands of lines of code. 

Also, this way, the codes are easier to manage and can be verified individually. 

In each project, I start with:

(vl-load-com)
(load (findfile "lisp-loader.lsp"))
(load (findfile "MA-load-lisp.lsp"))

 

Looking at MA-load-lisp, here's what it looks like:

(defun MA-load-lisp (/ lisp lisppath lisplist count) 
  (setq lisppath "~~AutoLISP\\MA_functions\\")
  (setq lisplist (vl-directory-files lisppath "*.lsp" 1))
  (setq count (length lisplist))
  (foreach lisp lisplist 
    (if (load (strcat lisppath lisp)) 
      (princ (strcat lisp " has been loaded.\n"))
      (princ (strcat lisp " didn't load.\n"))
    ) ;end if
  ) ;end foreach
  (princ 
    (strcat "There are " (itoa count) " pre-loaded scripts from " lisppath ".\n")
  )
  (princ)
); end function

(MA-load-lisp); and, run this function

 

the ~~ at the 2nd line is just short for C:\\---- to wherever the folder is.

 

 

However, here's the deal, whenever I load the scripts using APPLOAD, AutoCAD 2020 prompts a security check for each of the files.

I already have this folder \AutoLISP in the Support File Search Path and Trusted Locations in the Options Menu of AutoCAD.

I can't seem to find a way to get around this. Do I need to digitally sign each lsp file?

Posted

If all the lisp was in the folder \AutoLISP in the Support File Search Path and Trusted Locations you wouldn't have any issues.

You put it all in subfolders that were not added to Support File Search Path and Trusted Locations.

I've got about a 1000 lisp routines and keep them all in the same folder.

Posted

So apart from where you save them, so long as they get loaded all is good.

 

As a memory aid I name them similarly - ones beginning with txt are texts LISPs, Att for attributes, BLK to define a block and Block for other blocks and so on, then build up the name from there, other common things, 2 or t to mean "to", CB for clipboard, snap to snap to a grid point - so even when I can't remember exactly I can often work out what the name is. For example txt2cb - copies the text to the clip board, block2snap moves the block to a snap point. And Jeff which is a dimension LISP (usually dim + function) but so weirdly named I just remember it 

 

File naming is similar - some files have several LISPs, so linelisp.lsp might comntain line functions and so on

 

For saving, my file system is quite flat, just 1 folder and saved on the company one drive rather than default trusted location - we used to have hot desking with fixed tower PCs, using one drive I could load my LISPs wherever I sat. I have 1 LISP, appreload, that will load everything in that folder, all I need to do is load and run that from any desk and away I go (even LISPs to set up the CAD screen I like.... which annoyed some other users....).

 

Now with the laptop I still have the same folder and load the most frequent ones using appload and startup suit, seams to work for me

 

 

 

 

Posted

For any lisp that isn't loading use the findtrustedfile lisp function to see if that lisp file is actually in a trusted location.

Example (findtrustedfile "abc.lsp") will return the full file path if it's in a trusted location and nil if it is not.

Posted (edited)

If you don't want the prompts, another way of doing it (not recommended because it may be unsafe) is to set the SECURELOAD system variable to 0, and then trying it again. I'm not sure why it exists in the first place, but it does.

 

There's more information in the page, you may have a read-through: Secure Load

 

Plus, adding those directories to the list of trusted locations can be a good idea too.

Edited by Jonathan Handojo
Posted

I solved it by using something like this, referenced from Lee-Mac and BlackBox_:

;; Trusted Path - Adds working folders as trusted file path locations to AutoCAD.
;; This is to simplify the setup of loading LISP routines into AutoCAD
(vl-load-com)

;; reference: BlackBox_
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/setting-trusted-paths/m-p/4524143#M315916
(defun _CheckAddTrustedPath (newPath / trusted)
  ;; Example
  ;; (_CheckAddTrustedPath "\\\\Server\\Share\\Folder")
  (if (and  (setq trusted (getvar 'trustedpaths))
            (not (vl-string-search newPath trusted))
      )
    (setvar 'trustedpaths
      (strcat (vl-string-right-trim ";" trusted) ";" newPath)
    )
  )
)
;; Add Support File Search Paths  -  Lee Mac
;; Adds a list of Support File Search Paths, excluding duplicates and invalid paths.
;; lst - [lst] list of paths to add, e.g. '("C:\\Folder1" "C:\\Folder2" ... )
;; Returns: [str] "ACAD" Environment String following modification

(defun LM:sfsp+ ( lst )
    (   (lambda ( str lst )
            (if (setq lst
                    (vl-remove-if
                       '(lambda ( x )
                            (or (vl-string-search (strcase x) (strcase str))
                                (not (findfile x))
                            )
                        )
                        lst
                    )
                )
                (setenv "ACAD" (strcat str ";" (apply 'strcat (mapcar '(lambda ( x ) (strcat x ";")) lst))))
            )
        )
        (vl-string-right-trim ";" (getenv "ACAD"))
        (mapcar '(lambda ( x ) (vl-string-right-trim "\\" (vl-string-translate "/" "\\" x))) lst)
    )
)

(setq pathsToTrust (list 
              "Folder 1 path"
              "Folder 2 path"
              "Folder 3 path"
  )
)

;; Execute
(foreach item pathsToTrust
  (_CheckAddTrustedPath item)
)
(LM:sfsp+ pathsToTrust)

 

I basically just get a list of folders I want to include in the pathToTrust symbol. I just load this once and then forget about it. 

Posted

Rather than loading lots of Lee-mac programs that I use, like dynamic blocks edit, just use this in your program and load it when required, you can incorporate the correct path, so can keep programs in different directories. Like others I have a big working directory support path. Lots of lisps.

 

some examples a single line is all that is needed

(if (not AH:Butts)(load "Multi radio buttons.lsp"))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(if (not LM:getvisibilityparametername) (load "Lee-mac Dynamic block get-put"))

Look into Autoload in your autoloaded lisps this loads the lisp when you type the command name.

 

(autoload "COPY0" '("COPY0"))
(autoload "COPYCOMMAND" '("ZZZ"))
(autoload "DIMFLIP" '("DIMFLIP"))
(autoload "DRAWXFALL" '("DRAWXFALL"))

 

  • Agree 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...