Author Topic: How do you organize your lisp codes?  (Read 27557 times)

0 Members and 1 Guest are viewing this topic.

FengK

  • Guest
How do you organize your lisp codes?
« on: March 23, 2006, 12:56:20 AM »
Hello,

How do you organize your lisp codes?  Here is how I do it.
More than 90% of the codes I wrote, which are quite a lot, are in two files.  One defines all the commands, and the other contains all the subroutines.  Seems it has worked well for me.  At least it made the maintenance work must easier.  The rest codes belong to some rather bigger projects, each with a dozen or more commands.  I separated them into indidual files per project.

Thanks for your input.

Kelie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: How do you organize your lisp codes?
« Reply #1 on: March 23, 2006, 08:20:45 AM »
Small shortcut lisps (half dozen lines or less) are organized into a single file that is loaded at startup. Other larger lisp programs are written into their own file and stored in a lisp folder on the HD. The multitude of programs are set to autoload upon selection of the menu item (and I don't mean the autoload stub function defined by Autodesk) ...

Code: [Select]
(if (not c:myfunction)(load "myfunction"));myfunction
The remainder of the programs are loaded manually when I require them. This frees up memory and allows me to run a much leaner and thus faster system.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do you organize your lisp codes?
« Reply #2 on: March 23, 2006, 08:31:34 AM »
Welcome to theSwamp Kelie.

Most of my lisp routines are in individual files & are on demand loaded in the following lisp
which is called by the start up lisp. As you can see near the end of this routine I load the
subroutines & set ACAD variabled.

Code: [Select]
(setq *usermode* "CAB") ; turn on debug mode
;;  See Debug.lsp for use


;;; ===============================================
;;;    Lisp Routine Loader
;;;    AUTOLOAD only loads the routine when needed
;;; ===============================================
;;;------  Lisp name -- Function name -------  Discription  -----------------------
(AUTOLOAD "AreaPrt" '("AreaPrt")) ; Print the Area of "POLYLINE"  "LWPOLYLINE" "CIRCLE" "ELLIPSE"
(AUTOLOAD "arrow line" '("arw")) ; draw a arrow line on stairs, plan view
(AUTOLOAD "Block UnmirrorCAB" '("bum")) ; Unmirror blocks picked
(AUTOLOAD "BlockDel CAB" '("BlockDel")) ; Delete ALL matching blocks & purge the DWG
(AUTOLOAD "Copyb_layouts New" '("CopyB" "DeleteB")) ; Block copy or delete on all tabs
(AUTOLOAD "BlkInsert" '("blkinsert")) ; Block Menu Insert Routine
(AUTOLOAD "BLOCK Ent List CAB" '("BlockInfo")) ; Block Info 2 File
(AUTOLOAD "BrAt" '("brat")) ; Break Line @
(AUTOLOAD "BrkDbl-cab" '("DZ")) ; Double Break Symbol
(AUTOLOAD "BrkSym" '("BRK")) ; Single Break Symbol

<more stuff>
<then this stuff i need all the time>

(load "vl-SubRoutines.lsp")
(load "SlideDisplay")
(load "ACADSet_Variables CAB") ; loads & runs

(defun C:DOB() (setq ss (ssget)) (command "DRAWORDER" ss "" "B") (princ) )
(defun C:DOF() (setq ss (ssget)) (command "DRAWORDER" ss "" "F") (princ) )
(defun C:DOA() (setq ss (ssget)) (command "DRAWORDER" ss "" "A") (princ) )
(defun C:DOU() (setq ss (ssget)) (command "DRAWORDER" ss "" "U") (princ) )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CADaver

  • Guest
Re: How do you organize your lisp codes?
« Reply #3 on: March 23, 2006, 09:15:34 AM »
poorly, very poorly. :cry:

whdjr

  • Guest
Re: How do you organize your lisp codes?
« Reply #4 on: March 23, 2006, 09:25:58 AM »
I thought about making this a new thread because it is kind of a tangent but then I decided it actually was tied to this discussion pretty close.


So, how do you load your lisp files?

Keith eluded to not liking the Autodesk lisp method but did not not elaborate on his method of choice,

and

CAB uses 'autoload' to load his lisp files on demand,

and

I use a mnl file to load all my lisp files at once :oops:(I know it's not the correct way).


After researching CAB's method of using 'autoload' the Help files state that the 'autoload' command is to be used in the acad.lsp file.  Well if I was supporting a network with 10 users and I wanted to add a couple of new commands I wouldn't want to go to all 10 stations to edit their acad.lsp files.  That's why I like the mnl method where you set up each workstation initially to access that menu file and whenever you add to it the user just needs to restart AutoCad.  Wouldn't it be nice to have the best of both worlds - a mnl file that loaded on demand lisp files. :-)

Is that what you use Keith?  Did you create something that marries the two together?

If I am way off base here please speak up.  If this should be moved to its own thread that's ok.



Please comment on how you load your lisp files and why.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: How do you organize your lisp codes?
« Reply #5 on: March 23, 2006, 09:50:54 AM »
Many of the lisps are/can be loaded in the common mnl file. This is not always preferred as it really should be used exclusively for lisps that are required by the menu. All lisps not exclusively required as shortcuts are loaded in the manner I explained above ... i.e. if-not-then scenario.

Lisps that are used infrequently are manually loaded by the user. i.e. appload

Frequently used lisps that are used but not included in the startup lisp file (acad.lsp, acaddoc.lsp, menu.mnl etc..) are added to the startup suite on each of the respective stations. For me this is a simple task as I only have 6 stations to manage. At my previous place of employment I had 12 stations in 2 offices, but it was still fairly simple to manage as all I need to do is log into their system via the network and import a registry file in the respective system.

Of course this would necessitate that you have sufficient rights to do just that. I just happen to have that.

And the reason why is because with the vast amount of customization that I have, it would take a considerable amount of memory and time to load them all at startup. Consider if you had to load a hundred or more custom programs all at startup ... besides having to load your drawing, it also would have to find and load each program ... when I moved to this method about 5 years ago, it resulted in an immediate improvement on the start time of AutoCAD by about 30 seconds. (sometimes it took over a minute to load AutoCAD .. and that was without a drawing!!!!)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CADaver

  • Guest
Re: How do you organize your lisp codes?
« Reply #6 on: March 23, 2006, 09:56:32 AM »
Why isn't the MNL the "correct" way?  It's been working quite well for us for over a decade.

We use a combination of both the MNL and AutoLoad.  The mnl loads a few files that contain a multitude of functions that are relatively small, it also loads menu specific functions related to that clients requirements.  We also use autoload to load larger functions, or functions that we've "borrowed" from someone else.

vinnyg

  • Guest
Re: How do you organize your lisp codes?
« Reply #7 on: March 23, 2006, 10:02:58 AM »
Like CAB, I use 'autoload' but maybe not exactly the way he does?

vinnyg

GDF

  • Water Moccasin
  • Posts: 2081
Re: How do you organize your lisp codes?
« Reply #8 on: March 23, 2006, 10:13:53 AM »
That is a good question. I have gone down the dark path of creating one tied together united linked all for one program.
I call it "Arch Program" because I'm an Architect who tries to do lisp writing.<caugh>

This is my typical start up  <as seen from the command line display>
Code: [Select]
*** ---------- Begining Startup ---------- ***
*** -- Loaded Open File Command Reactor -- ***
*** New command: MSG    Arch Program© 2006 ***
*** ---- Architettura Customized File ---- ***
*** ----- Arch Program© for AutoCAD® ----- ***
*** --- Copyright 2006 - Gary D Fowler --- ***
*** ---- System Variables Initialized ---- ***
*** ---------- Mode Setup: <Ar> ---------- ***
*** ---------- Startup Complete ---------- ***

Once the program has been initilized <a one time event> these files are loaded:
;;; Key files to needed to run this program:
;;; 1. The "ACAD.lsp" file sets the path for the arch program along with the saved autocad
;;;     environment settings for a clean restore to generic autocad when the arch program
;;;     is unloaded. This is the only file that must be located at each workstation within
;;;     the autocad support directory. It only loads at AutoCAD startup.
;;; 2. The "ACADDOC.lsp" loads the "ARCH_INITIALIZE.fas" file.
;;; 3. The "ARCH_INITIALIZE.fas" initialize the setup.
;;; 4. Custom settings are controled by the "custom_xxx.lsp" file.
;;; 5. The "ARCH.mnc" loads the "ARCH.mnl" file automatically which contains many
;;;     misc functions required to operate this program.
;;; 6. The "ARCH_SUBROUTINES.fas" contains all of the subfunctions.
;;; 7. All bitmaps for the toolbars are compiled in the "ARCH.dll" which is loaded
;;;     automatically.
;;; 8. The "ARCH.dcl" file must be located in the acad support file search path
;;;     it contains all of the dialog box widgets for the arch program.
;;;     @include "..\\ARCH.dcl"

Here is a typical defun from the ARCH.mnl file:
(defun C:LFD  ()
  (if (not LFDIT)
    (ARCH:LOAD (strcat ARCH#LAYF "ARCH_LayerFiltersDelete.lsp")))
  (if LFDIT
    (LFDIT))
  (princ))

Is it organized, yes to the point being of one big headache.

Here is my startup:
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;; AutoCAD Drawing File STARTUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (< (distof (substr (getvar "acadver") 1 4)) 15.0)
  (alert "ARCH Program no longer supports this version of AutoCAD"))
;;;
(if (>= (distof (substr (getvar "acadver") 1 4)) 15.0)
  (defun-q
    ARCH::STARUP
    ()
    (if (not ARCH#DIAP)
      (setq ARCH#DIAP '(-1 -1)))
    (if ARCH:DOSLIBLOADER (ARCH:DOSLIBLOADER))
    (if ARCH:EXPRESS-TOOLS (ARCH:EXPRESS-TOOLS))
    ;;(ARCH:LOAD (strcat ARCH#SUPF "UTIL\\" "ARCH_ICONS.lsp")) 
    (if (/= (findfile (strcat ARCH#SUPF "UTIL\\" "ARCH_ICONS.lsp")) nil)
      (load (strcat ARCH#SUPF "UTIL\\" "ARCH_ICONS.lsp"))
      (ARCH:MsgBox
        " Arch Program© : Error"
        48
        "
     Arch Icons File could not be Found.
--------------------------------------------------------------------------------------------
     This Routine could not be found on the network...
     Please notify Gary D. Fowler to correct the problem."))
    (setq ARCH#CHKV (atoms-family 1))
    ;;(gc) ;Forces a garbage collection, which frees up unused memory   
    ;;(mem) ;Displays the current state of memory in AutoLISP   
    (progn (if (= (getvar "snapunit") 0)
             (progn (command "snapunit" "0.125,0.125")
                    (princ "\n*** - Snapunit reset from 0,0 to 1/8,1/8 - ***\n")))
    ;to fix bad snapunit value 
           (if (= (getvar "dimscale") 0)
             (progn (setvar "dimscale" 1)
                    (princ "\n*** -- dimscale value reset from 0 to 1 -- ***\n")))
    ;to fix bad dimscale value 
           )
    (if ARCH:STARTUP (ARCH:STARTUP)) ;Loaded from ARCH_SUBROUTINES
    (PlaceARCHMenu) ;Loaded from ARCH_INITIALIZE
    (ARCH:MENU-STARTUP) ;grayout menu controls
    (if ARCH:RESETVARS (ARCH:RESETVARS)) ;Loaded from Custom File standard setvars
    (if ARCH:RESETENVS (ARCH:RESETENVS)) ;Loaded from Custom File standard setenvs
    (if ARCH:CUSTOMIZED_HKEY-STARTUP (ARCH:CUSTOMIZED_HKEY-STARTUP)) ;Loaded from Custom File HKEY variables that must be set!
    ;;(ARCH:F_S-VAR) ;Loaded from ARCH_SUBROUTINES recording setvars to reset
    ;;(ARCH:COMMANDS) ;to record commands   
    ;;(ARCH:RECORDS)
    (C:MODE) ;modemacro line info
    (if (/= (findfile "C:\\Arch_Custom\\Support\\ARCH_DoubleClick.ini") nil)
      (progn
        (if (/= (findfile (strcat ARCH#UTIF "ARCH_DoubleClick.lsp")) nil)
          (load (strcat ARCH#UTIF "ARCH_DoubleClick.lsp"))
          (ARCH:MsgBox
            " Arch Program© : Error"
            48
            "
     DoubleClick File could not be Found.
--------------------------------------------------------------------------------------------
     This Routine could not be found on the network...
     Please notify Gary D. Fowler to correct the problem."))))
    ;;(ARCH:LOAD (strcat ARCH#UTIF "ARCH_SaveVariable.lsp"))
    (if (/= (findfile (strcat ARCH#UTIF "ARCH_SaveVariable.lsp")) nil)
      (load (strcat ARCH#UTIF "ARCH_SaveVariable.lsp"))
      (ARCH:MsgBox
        " Arch Program© : Error"
        48
        "
     SaveVariable File could not be Found.
--------------------------------------------------------------------------------------------
     This Routine could not be found on the network...
     Please notify Gary D. Fowler to correct the problem."))
    (ARCH:AxAcadStatusBarButton)
    ;;(ARCH:LOAD (strcat ARCH#SUPF "UTIL\\" "ARCH_AcadStatusBarButton45.lsp"))
    (if (/= (findfile (strcat ARCH#SUPF "UTIL\\" "ARCH_AcadStatusBarButton45.lsp"))
            nil)
      (load (strcat ARCH#SUPF "UTIL\\" "ARCH_AcadStatusBarButton45.lsp"))
      (ARCH:MsgBox
        " Arch Program© : Error"
        48
        "
     AcadStatusBarButton45 File could not be Found.
--------------------------------------------------------------------------------------------
     This Routine could not be found on the network...
     Please notify Gary D. Fowler to correct the problem."))
    ;;(ARCH:LOAD (strcat ARCH#SUPF "UTIL\\" "ARCH_AcadStatusBarButton111.lsp"))
    (if (/= (findfile (strcat ARCH#SUPF "UTIL\\" "ARCH_AcadStatusBarButton111.lsp"))
            nil)
      (load (strcat ARCH#SUPF "UTIL\\" "ARCH_AcadStatusBarButton111.lsp"))
      (ARCH:MsgBox
        " Arch Program© : Error"
        48
        "
     AcadStatusBarButton111 File could not be Found.
--------------------------------------------------------------------------------------------
     This Routine could not be found on the network...
     Please notify Gary D. Fowler to correct the problem."))
    ;;testing out ltscale reactor and layout update fix
    (if (not *LayoutLTS*)
      (setq *LayoutLTS*
             (VLR-Miscellaneous-Reactor
               nil
               '((:VLR-layoutSwitched . ARCH:ChangedLayout)))))
    (if (/= (findfile (strcat ARCH#CUSF "LAYS\\" "ARCH_LockDown.lsp")) nil)
      (load (strcat ARCH#CUSF "LAYS\\" "ARCH_LockDown.lsp"))
      (ARCH:MsgBox
        " Arch Program© : Error"
        48
        "
     ARCH_LockDown File could not be Found.
--------------------------------------------------------------------------------------------
     This Routine could not be found on the network...
     Please notify Gary D. Fowler to correct the problem."))
    (cond ((or (/= (getvar "loginname") "CAD_11")
               (/= (getvar "loginname") "cad_11"))
           (ARCH:SBBLOADER)))
    ;;(if (menugroup "EXPRESS")(ARCH:ExpressARXload))   
    (if (not ARCH:Rcmd-Enable)
      (ARCH:LOAD (strcat ARCH#DIMF "ARCH_StickTo-Dim.lsp")))
    (if ARCH:Rcmd-Enable
      (ARCH:Rcmd-Enable))
    (princ "\n*** ---------- Startup Complete ---------- ***")
    ;;(ARCH:endTimer)   
    (princ)))
(setq S::Startup (append S::Startup ARCH::STARUP))

Gary






« Last Edit: March 23, 2006, 10:34:09 AM by Gary Fowler »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

nivuahc

  • Guest
Re: How do you organize your lisp codes?
« Reply #9 on: March 23, 2006, 10:41:55 AM »
I have a personal LISP routine (Chuck.lsp) that autoloads on startup that's filled up like this:

Code: [Select]
(defun C:AT      () (command "-attedit" "" "" "" "" ))
(defun C:AR      () (command "-attedit" "N" "" "" "" "" ))
(defun C:CASE    () (prompt "\nLoading...") (load"C:/CLC/LISP/CASE")    (prompt "\nloaded.")(C:CASE))
(defun C:CL      () (prompt "\nLoading...") (load"C:/CLC/LISP/CL")      (prompt "\nloaded.")(C:CL))
(defun C:CLT     () (prompt "\nLoading...") (load"C:/CLC/LISP/CLT")     (prompt "\nloaded.")(C:CLT))
(defun C:CS      () (prompt "\nLoading...") (load"C:/CLC/LISP/CS")      (prompt "\nloaded.")(C:CS))
(defun C:CST     () (prompt "\nLoading...") (load"C:/CLC/LISP/CST")     (prompt "\nloaded.")(C:CST))
etc.....

That's how I've done it for years and don't see a reason to change. It works. My routines are loaded on demand. Also a handy place to put my little shortcuts.

GDF

  • Water Moccasin
  • Posts: 2081
Re: How do you organize your lisp codes?
« Reply #10 on: March 23, 2006, 10:51:23 AM »
One thing I have learned is to be sure you don't have conflicks between your lisp command names and AutoCAD's pgp file.
And the one thing I haven't learned is KISS <Keep It Simple Stupid>...

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

whdjr

  • Guest
Re: How do you organize your lisp codes?
« Reply #11 on: March 23, 2006, 10:59:00 AM »
Keith can you elaborate on your method of "customizing" each workstation?  I know with XP you have the option of utilizing 'Remote Desktop' to manually update the computer.  What is your prefered method?


What are other peoples methods?  What about an 'installation program' like AcadInstall...?  Anyone ever use something like that?

whdjr

  • Guest
Re: How do you organize your lisp codes?
« Reply #12 on: March 23, 2006, 11:02:13 AM »
CADAver,

How do you  use both mnl files and autoload togethor?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: How do you organize your lisp codes?
« Reply #13 on: March 23, 2006, 11:26:25 AM »
Keith can you elaborate on your method of "customizing" each workstation? I know with XP you have the option of utilizing 'Remote Desktop' to manually update the computer. What is your prefered method?


What are other peoples methods? What about an 'installation program' like AcadInstall...? Anyone ever use something like that?

I generally just connect to the computer as needed through the computer management console and make any changes there. The trick is that AutoCAD stores the startup suite in the HKCU section of the registry and it is not accessable unless you actually log in as the current user of the machine. It is somewhat inefficient, but it works .. and I don't generally have to leave my desk.

I have used AcadInstall for deployment of some applications and I find it very capable for most things. There were some glitches when I deployed an application that was designed for A2k6 and some vertical applications, but I think AcadInstall has been updated to deal with those, particularly AutoCAD not being able to find the acaddoc.lsp after installing a product using it.

As far as any more elaboration on my methods, I can't really explain it any better except that when I am working on the remote computer it is "almost" like I am sitting there.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: How do you organize your lisp codes?
« Reply #14 on: March 23, 2006, 11:29:07 AM »
And why not use this in the mnl file to run or load then run the lisp?

Code: [Select]
^C^C(if (not c:myfunction)(load "myfunction"));myfunction
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.