Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: A routine that loads all of my other routines

  1. #1
    100 Club
    Join Date
    2006-12
    Posts
    145
    Login to Give a bone
    0

    Default A routine that loads all of my other routines

    Iv'e just read though all threads about loading routines but still didn't found an answer. The concept is to have 1 LISP (say, load.lsp) file which runs at AutoCAD startup and loads all of my LISP routines and some other routines (probably VBA). This would be as a common Startup Suite. If I want users to have a new routine I just add it to load.lsp file and they have it.

    What's the way to load another LSP or VLX file within LISP routine? I know (load "name of LSP or VLX"). Is there a way to point specific file in specific location, like (load "Z:\LISP\MyLispRoutine")?

    What's the way to load VBA routine file within LISP routine?

    I think I've already read about this concept before a while here in AUGI I just don't succeed to find the thread.

    Question to those who use acad.lsp, acaddoc.lsp or Start-up Suite to manage custom routines in multi-user environment: if you have 100 users and want to empower them with new super-time-saving-routine what do you do? Use shared acad.lsp, acaddoc.lsp or Start-up Suite? Or may be you use other methods how to empower your users with good tools?

  2. #2
    Active Member
    Join Date
    2015-12
    Location
    Utah
    Posts
    69
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    Quote Originally Posted by Yancka View Post
    Iv'e just read though all threads about loading routines but still didn't found an answer. The concept is to have 1 LISP (say, load.lsp) file which runs at AutoCAD startup and loads all of my LISP routines and some other routines (probably VBA). This would be as a common Startup Suite. If I want users to have a new routine I just add it to load.lsp file and they have it.

    What's the way to load another LSP or VLX file within LISP routine? I know (load "name of LSP or VLX"). Is there a way to point specific file in specific location, like (load "Z:\LISP\MyLispRoutine")?

    What's the way to load VBA routine file within LISP routine?

    I think I've already read about this concept before a while here in AUGI I just don't succeed to find the thread.

    Question to those who use acad.lsp, acaddoc.lsp or Start-up Suite to manage custom routines in multi-user environment: if you have 100 users and want to empower them with new super-time-saving-routine what do you do? Use shared acad.lsp, acaddoc.lsp or Start-up Suite? Or may be you use other methods how to empower your users with good tools?
    I use shared acad.lsp and acaddoc.lsp. Inside the acaddoc.lsp is the following code:
    Code:
    (vl-load-com)            ; Load COM just in case it's needed
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;  Routine: load_with_error       ;;;
    ;;;  Purpose: Load lisp files with error reporting and exit on error  ;;;
    ;;;  Arguments: FileList - list of lisp filenames to load   ;;;
    ;;;  Returns: Nothing of value      ;;;
    ;;;-----------------------------------------------------------------------------;;;
    ;;;  If any of the files fail to load this routine will raise an alert box with ;;;
    ;;;  the error and each file that failed, then will exit the calling routine. ;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun load_with_error (filelist / errors results)
      (setq
        results (mapcar (function
            (lambda (file) (vl-catch-all-apply 'load (list file)))
          )
          filelist
         )
      )
      (if (setq errors (vl-remove-if-not
           (function (lambda (f) (vl-catch-all-error-p f)))
           results
         )
          )
        (progn
          (alert
     (apply
       'strcat
       (mapcar (function
          (lambda (er) (strcat (vl-catch-all-error-message er) "\n"))
        )
        errors
       )
     )
          )
          (exit)
        )
      )
    )
     
    (load_with_error
      (list
        "Split"
        "logging"
        "QKeys"
        "Brd_ttlswap"
        )
      )
     
    (if (setq PersonalLisp (findfile (strcat (getvar "loginname") ".lsp")))
      (load_with_error (list personallisp))
      )
    There are two keys to this working well. First is the QKeys file. This is a lisp file that contains aliases to my lisp routines. Here is a snippet from that file:
    Code:
    (defun c:login () (load "log") (c:login)) ;   make an entry in tc.dat
    (defun c:logout () (load "log") (c:logout)) ;   make an entry in tc.dat
    (defun c:lli () (load "nlist") (c:lli)) ;   List nested entities
    (defun c:ltcp () (load "livetext tools.lsp") (c:ltcp)) ;LiveText Copy
    (defun c:ltd()(load "linetypescaledynamic.lsp")(c:ltd));LineType scale Dynamic
    (defun c:ltl () (load "r13ltscl") (c:ltl));lengthen ltscale factor of selected objects
    (defun c:lts () (load "r13ltscl") (c:lts));shorten ltscale factor of selected objects
    (defun c:lumberlayers()(load "lumber")(c:lumberlayers));set layers for lumber routines
    (defun c:mate()(load "attrib")(c:mate));Multiple attribute edit
    Note that each entry here loads a file then runs the routine. Demand loading in this way minimizes drawing load time while maximizing routine availability.

    The second section of code in my AcadDoc.lsp looks for a lisp file with the users login name and loads that file if found. this allows each individual user to create their own customizations and also allows me to build quick routines for the users on an individual basis for specific tasks.

    I do not specify a path to any of my lisp routines but rather add their path to the support search path.

  3. #3
    100 Club
    Join Date
    2008-11
    Location
    Fort Lewis, WA.
    Posts
    124
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    Quote Originally Posted by Yancka View Post
    Iv'e just read though all threads about loading routines but still didn't found an answer. The concept is to have 1 LISP (say, load.lsp) file which runs at AutoCAD startup and loads all of my LISP routines and some other routines (probably VBA). This would be as a common Startup Suite. If I want users to have a new routine I just add it to load.lsp file and they have it.

    What's the way to load another LSP or VLX file within LISP routine? I know (load "name of LSP or VLX"). Is there a way to point specific file in specific location, like (load "Z:\LISP\MyLispRoutine")?

    What's the way to load VBA routine file within LISP routine?

    I think I've already read about this concept before a while here in AUGI I just don't succeed to find the thread.

    Question to those who use acad.lsp, acaddoc.lsp or Start-up Suite to manage custom routines in multi-user environment: if you have 100 users and want to empower them with new super-time-saving-routine what do you do? Use shared acad.lsp, acaddoc.lsp or Start-up Suite? Or may be you use other methods how to empower your users with good tools?
    You can try something like this. This is a snippet of my ACADDOC.lsp

    Code:
    ;;;==============================================
    ;;;This will create a 12" break.
    ;;;
    (defun C:b12 ()
      (load "\\\\Flfile\\Fort\\Cad\\Acad Master Files\\Routines\\Lisp Files\\ACADDOC_gap.lsp")
      (c:break12)
    )
    
    ;;;==============================================
    ;;;This will create a 4" wide multiline.
    ;;;
    (defun C:M4 ()
      (load "\\\\Flfile\\Fort\\Cad\\Acad Master Files\\Routines\\Lisp Files\\ACADDOC_MLINE.lsp")
      (c:mline4)
    )

  4. #4
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    i have a '_Subs' folder that has frequently used subroutines i've written. i have this in my startup lisp to load everything in that folder. you are more than welcome to it.
    Code:
    ;loads all needed subroutines
    (if (findfile "C:\\AlanThompson\\LSP\\_Subs")
      (mapcar '(lambda (x)
                 (if (wcmatch (strcase x) "*.LSP")
                   (load
                     (strcat (findfile "C:\\AlanThompson\\LSP\\_Subs") "\\" x)
                   ) ;_ load
                 ) ;_ if
               ) ;_ lambda
              (vl-directory-files
                (findfile "C:\\AlanThompson\\LSP\\_Subs")
              ) ;_ vl-directory-files
      ) ;_ mapcar
    ) ;_ if
    as far as loading specific routines, i either use the (load "BLAH") or (autoload "BLAH" '("BL" "BLAH"))

    hope this helps.

  5. #5
    Active Member
    Join Date
    2007-03
    Posts
    57
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    Loads lsp files from the specified folder and all subfolders
    Code:
    (defun C:DWGRULL ( /              file_list      file&
                      z-files-in-directory          BrowseFolder
                      path           good           bad
                     )
    ;;; ==== EN ====
    ;;; DWGRU Load Lisp
    ;;; Command DWGRULL
    ;;; the Command for loading lisp (*.lsp) files from the specified folder, including all enclosed folders
    ;;; the Folder can be set obviously
    ;;; to Edit following lines in a code
    ;;; (setq path (BrowseFolder)); _ the Choice of a folder of loading
    ;;; the folder Task obviously 
    ;;; (setq path "G: \\Work \\4ACAD \\MIP \\WORK \\DwgRuLispLib")
    
    ;;;; ==== RUS =====
    ;;; DWGRU Load Lisp
    ;;; Команда DWGRULL
    ;;; Команда для загрузки  лисп (*.lsp) файлов с указанной папки, включая все вложенные папки
    ;;; Папку можно задать явно
    ;;; Редактировать следующие строчки в коде
    ;;; (setq  path (BrowseFolder)) ;_ ;Выбор папки загрузки
    ;;; Задание папки явно 
    ;;; (setq  path "G:\\Work\\4ACAD\\MIP\\WORK\\DwgRuLispLib")
    (vl-load-com)
      (defun z-files-in-directory (directory pattern nested /)
    ;| EN ============================================================================
    * function z-files-in-directory returns the list of files being in the set
    * directories
    * the Author: Zuenko Vitaly (ZZZ)
    * Parameters:
    * directory - a way to a folder for example "D: \\My documents \\ZEF \\Lisp"
    * pattern  - a template for example "*.lsp" or the list ' ("*.dwg" "*.dxf")
    * nested - to search in the enclosed folders: t (yes) or nil (is not present)
    * a call Example:
    (z-files-in-directory "D: \\My documents \\ZEF \\Lisp" "*.dwg" t)
    (z-files-in-directory "D: \\My documents \\ZEF \\Lisp" ' ("*.dwg" "*.dwt") t)
    ============================================================================= |;
      
    ;| RUS ===========================================================================
    *    функция z-files-in-directory возвращает список файлов находящаяся в заданной
    * директории
    *    Автор : Зуенко Виталий (ZZZ)
    *  Параметры:
    *    directory  путь к папке например "D:\\Мои документы\\ZEF\\Lisp"
    *    pattern    шаблон например "*.lsp" или список '("*.dwg" "*.dxf")
    *    nested    искать в вложенных папках: t (да) или nil (нет)
    * Пример вызова:
    (z-files-in-directory "D:\\Мои документы\\ZEF\\Lisp" "*.dwg" t)
    (z-files-in-directory "D:\\Мои документы\\ZEF\\Lisp" '("*.dwg" "*.dwt") t)
    =============================================================================|;
        
        (if (not (listp pattern))
          (setq pattern (list pattern))
        ) ;_ end of if
        (if nested
          (apply
            'append
            (append
              (mapcar '(lambda (_pattern)
                         (mapcar '(lambda (f) (strcat directory "\\" f))
                                 (vl-directory-files directory _pattern 1)
                         ) ;_ end of mapcar
                       ) ;_ end of lambda
                      pattern
              ) ;_ mapcar
              (mapcar
                '(lambda (d)
                   (z-files-in-directory
                     (strcat directory "\\" d)
                     pattern
                     nested
                   ) ;_ end of z-files-in-directory
                 ) ;_ end of lambda
                (vl-remove
                  "."
                  (vl-remove ".." (vl-directory-files directory nil -1))
                ) ;_ end of vl-remove
              ) ;_ end of mapcar
            ) ;_ end of append
          ) ;_ end of apply
          (apply 'append
                 (mapcar '(lambda (_pattern)
                            (mapcar '(lambda (f) (strcat directory "\\" f))
                                    (vl-directory-files directory _pattern 1)
                            ) ;_ end of mapcar
                          ) ;_ end of lambda
                         pattern
                 ) ;_ end of mapcar
          ) ;_ end of apply
        ) ;_ end of if
      ) ;_ end of defun
      (defun BrowseFolder (/ ShlObj Folder FldObj OutVal)
        (vl-load-com)
        (setq ShlObj (vla-getinterfaceobject
                       (vlax-get-acad-object)
                       "Shell.Application"
                     ) ;_ end of vla-getInterfaceObject
              Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "" 0)
        ) ;_ end of setq
        (vlax-release-object ShlObj)
        (if Folder
          (progn
            (setq FldObj (vlax-get-property Folder 'Self)
                  OutVal (vlax-get-property FldObj 'Path)
            ) ;_ end of setq
            (vlax-release-object Folder)
            (vlax-release-object FldObj)
          ) ;_ end of progn
        ) ;_ end of if
        OutVal
      ) ;_ end of defun
      (setq path (BrowseFolder)) ;_ Choice of a folder of loading
    ;;; The folder task obviously ( Задание папки явно )
    ;;;(setq  path "G:\\Work\\4ACAD\\MIP\\WORK\\DwgRuLispLib")
      (setq good 0
            bad 0
      ) ;_ end of setq
      (setq file_list
             (z-files-in-directory
               path
               "*.lsp"
               t
             ) ;_ end of z-files-in-directory
      ) ;_ end of setq
      (foreach file& file_list
        (grtext -1 (strcat "Load " (vl-filename-base file&)))
        (if (vl-catch-all-error-p
              (vl-catch-all-apply 'load (list file&))
            ) ;_ end of VL-CATCH-ALL-ERROR-P
          (progn
            (setq bad (1+ bad))
            (princ (strcat "\nError in file " file&))
          ) ;_ end of progn
          (setq good (1+ good))
        ) ;_ end of if
      ) ;_ end of foreach
      (vl-cmdf "_.Redraw")
      (princ (strcat "\nPath " path))
      (princ (strcat "\n Loaded "
                     (itoa good)
                     " Bad file "
                     (itoa bad)
             ) ;_ end of strcat
      ) ;_ end of princ
      (princ)
    ) ;_ end of defun
    (princ
      "\nType DWGRULL in command line"
    ) ;_ end of princ

  6. #6
    Active Member
    Join Date
    2007-03
    Posts
    57
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    Other exapmle: load lsp, fas, vlx, arx files from specified folder and all subfolders
    Functions BrowseFolder and z-files-in-directory in the previous post
    Code:
    (vl-load-com)
    (if (or (not (getenv "*z_root_dir*"))
    (= (getenv "*z_root_dir*") "")
    ) ;_ or
    (setenv "*z_root_dir*" (BrowseFolder))
    )
    ;_загрузка библиотеки лиспов и arx модулей с отловом ошибок
    ;_Library loading lisp and arx modules with catching of errors
    (foreach fil (z-files-in-directory
                   (getenv "*z_root_dir*")
                   '("*.lsp" "*.fas" "*.vlx" "*.arx")
                   t
                 ) ;_ end of z-files-in-directory
      (if (vl-catch-all-error-p
            (vl-catch-all-apply
              '(lambda ()
                 (if (= (strcase (vl-filename-extension fil)) ".ARX")
                   (arxload fil)
                   (load fil)
                 ) ;_ end of if
               ) ;_ end of lambda
            ) ;_ end of vl-catch-all-apply
          ) ;_ end of vl-catch-all-error-p
        (princ (strcat "\nError load file " fil))
      ) ;_ end of if
    ) ;_ end of foreach
    ;;(setenv "*z_root_dir*" "") ;_Clear *z_root_dir*
    If the way to a folder with programs is known
    Code:
    (vl-load-com)
    ;_загрузка библиотеки лиспов и arx модулей с отловом ошибок
    ;_Library loading lisp and arx modules with catching of errors
    (foreach fil (z-files-in-directory
                    "Z:\\LISP\\MyLispRoutine" ;_ Type path here
    		           ;_ To use a double slash (\\) 
                                 ;_instead of unary (\) in a way
                   '("*.lsp" "*.fas" "*.vlx" "*.arx")
                   t
                 ) ;_ end of z-files-in-directory
      (if (vl-catch-all-error-p
            (vl-catch-all-apply
              '(lambda ()
                 (if (= (strcase (vl-filename-extension fil)) ".ARX")
                   (arxload fil)
                   (load fil)
                 ) ;_ end of if
               ) ;_ end of lambda
            ) ;_ end of vl-catch-all-apply
          ) ;_ end of vl-catch-all-error-p
        (princ (strcat "\nError load file " fil))
      ) ;_ end of if
    ) ;_ end of foreach

  7. #7
    Active Member
    Join Date
    2002-12
    Posts
    77
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    For company stuff, use a <company>.mnl to load all of the custom company lisps.

    If you load a company.cui / .mnu then it will automatically load the accompanying .mnl. This is just a lisp and it will get loaded with the menu.

  8. #8
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    Dear Alan,

    I am a frequent user of your great lisps. Unfortunately I could not get the above to work. What I did was:
    Copy code to acaddoc.lsp as well as creating and running a runall.lsp file. In both I replaced your path "C:\\AlanThompson\\LSP\\_Subs" (all three instances) with "C:\Program Files\AutoCAD 2010\Support\custom_lisp". Of course custom_lisp is an existing folder with my favorite lisp routines. Since I know next to nothing about lisp I also tried to replace the single backslashes in my path wiht your double ones. Yet again without success.
    What do I do wrong? I really like the idea of such a "hot folder" (as these are called among adobe products) whose content is loaded upon acad startup (acaddoc.lsp) or running a single lisp (runall.lsp).

    Appreciating your response,
    Thanks and kind regards,
    Aurel

  9. #9
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,686
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    Quote Originally Posted by marcaureljensen357148 View Post
    Dear Alan,

    I am a frequent user of your great lisps. Unfortunately I could not get the above to work. What I did was:
    Copy code to acaddoc.lsp as well as creating and running a runall.lsp file. In both I replaced your path "C:\\AlanThompson\\LSP\\_Subs" (all three instances) with "C:\Program Files\AutoCAD 2010\Support\custom_lisp". Of course custom_lisp is an existing folder with my favorite lisp routines. Since I know next to nothing about lisp I also tried to replace the single backslashes in my path wiht your double ones. Yet again without success.
    What do I do wrong? I really like the idea of such a "hot folder" (as these are called among adobe products) whose content is loaded upon acad startup (acaddoc.lsp) or running a single lisp (runall.lsp).

    Appreciating your response,
    Thanks and kind regards,
    Aurel
    As a fellow fan of Alan's code two things you can check first enter
    Code:
     (findfile "C:\\Program Files\\AutoCAD 2010\\Support\\custom_lisp")
    at the command line and see if it finds your folder, second make sure
    Code:
    (vl-load-com)
    is loaded first. Most heavy lisp users have it as the first line in Acad.lsp, it only needs to be loaded once so most of us don't put it in every routine.

    Personally I add my custom_lisp folder to the support path. That makes it eaiser to make sure dcl and other support files load without having to include paths. I keep the folder in "C:\Users\%username%\AppData\Roaming\Autodesk\" so It's there for whatever versions I have installed instead of seperate folders for each version. I see Alan does about the same for probably the same reason.

  10. #10
    Login to Give a bone
    0

    Default Re: A routine that loads all of my other routines

    Thanks Tom, Problem solved

    I have to admit that I have no clue what "vl-load-com" actually is, but it works just fine!

    Just one more question. I didn´t really get your point in the following. Do you have different versions of acad (e.g. regular and architecture) running? I always use the program-based folders instead of roaming because then settings apply to all win users at once (3 accounts on our machines for admin, me and my employee). Are the two options maybe just two ways to beat around the bush with individual pros and cons?

    Quote Originally Posted by Tom Beauford View Post
    Personally I add my custom_lisp folder to the support path. That makes it eaiser to make sure dcl and other support files load without having to include paths. I keep the folder in "C:\Users\%username%\AppData\Roaming\Autodesk\" so It's there for whatever versions I have installed instead of seperate folders for each version. I see Alan does about the same for probably the same reason.
    Yet again thanks out of a (still!) snowy northern germany,
    Aurel

Page 1 of 2 12 LastLast

Similar Threads

  1. Breakline routine loads then closes??
    By cwjean76 in forum AutoLISP
    Replies: 1
    Last Post: 2009-11-30, 10:51 AM
  2. Warning Routine Before AutoCAD Loads
    By Kevin Janik in forum CAD Management - General
    Replies: 12
    Last Post: 2007-08-04, 06:17 AM
  3. Replies: 9
    Last Post: 2007-06-13, 01:22 PM
  4. Replies: 2
    Last Post: 2007-04-20, 09:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •