Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Automatically load lisp programs on program startup

 I see where to load Lisp programs manually.  I've got the appropriate directories in the search path.  Everything works - except I don't see how to load these programs automatically on program startup.  Is this possible?

Comments

  •  Look in folder "c:\Program Files (x86)\Bricsys\BricsCAD V13\Support\". There are files "on_doc_load_default.lsp" and "on_start_default.lsp". You must duplicate it and remove "_defaults" to ie. "on_doc_load.lsp". I use only "on_doc_load.lsp".

    There is described automaticaly loading: http://bricsys.com/common/knowledge/topic.jsp?id=222

    After editation, it may look like my "on_doc_load.lsp":

    [code];this file will run once when the program starts.
    ;please do not edit. For custom actions on starting the program please create a file on_start.lsp.

    ;(alert "*** on_doc_load.lsp ***")

    (setvar "ACADLSPASDOC" 1)
    (setvar "HPNAME" "SOLID")
    (setvar "OSMODE" 695)


    (load "hladiny.lsp")
    (load "spiro.lsp")
    (load "kanal.lsp")[/code]

    ...etc

    Where path to *.lsp is defined in "Support path search file" or you must define *.lsp file with fill path.

    In this file you can enter more then automatic lisp load.
  •  Thanks very much, Juraj.  That worked just fine.  In looking at the knowledge base article, it looks like there is another file which could be edited to achieve the same result - autoload.rx?  It can be opened in Notepad and edited.  I assume it would work the same.
  • William,

    autoload.rx isn't intended for LISP. Its used to automatically load applications developed using ARX/BRX TX at start-up. So Juraj advice is correct.

    An alternative could be to use _APPLOAD. This allows you to create a list of routines that you want to load, storing the list in a file called appload.dfs. However for routines that you want loaded with every drawing, I think using on_doc_load.lsp is more robust.

    With LISP You can use demand load to load the LISP routine on first use, rather than having them all loaded every time, which requires more memory. e.g. you may have a lisp file called "MyLisp.lsp" which has a commands defined called "MyFunction" & "MyOtherFunction".

    Instead of this:
    [code](load "MyLisp.lsp")[/code]

    You would do this:
    [code](autoload "MyLisp" '("MyFunction" "MyOtherFunction"))[/code]

    Regards,

    Jason Bourhill

    CAD Concepts



  •  Jason, thanks for your followup comments.  I understand autoload.rx won't work for my purposes.  I didn't follow the rest of your comments that well as my tinkering ability with this type of thing is limited by choice.  

    What I would say is this - there are many people out there, including myself, who find themselves seeking an alternative to Autodesk World.   Therefore, it would be nice if Bricscad recognized that many of us have these old, standby Lisp routines that we have used for years because they work quite well, and, as such, we would like to continue to use them with our AutoCAD alternative program of choice.  Therefore, why not simplify the response to this common situation by employing a "Startup Suite" or something similarly named, in which we plug in these lisp routines we use, after having put them in the Support path, and be done with it.  

    Naturally, most people would want these programs available with every drawing file they work on and so would appreciate being able to have the routines available for use without taking up too much memory.  I would assume, however, that the memory these programs require is pretty small compared to the Gigabits of memory now installed on newer computers.   I know the Lisp programs I use are pretty lightweight.

    Anyhow, thanks again - I just wish that accomplishing the loading of Lisp programs was more straightforward with Bricscad. 
  • Hi William,

    BricsCAD doesn't have a start up suite manager, however there is an command called _APPLOAD, which is its predecessor. The main difference is that _APPLOAD retains a list of selected routines, but does not automatically load them. You have to run APPLOAD and manually trigger the loading step.

    If you can bare they pain of working through some LISP you can get BricsCAD to automatically load LISP routines from a specified folder. To do this you would include this function in your on_doc_load.lsp

    [code]; LOAD-LISP
    ; Loads all LISP routines found in the given folder
    (defun LOAD-LISP ( folder / LispList Lisp2load)
    ; Make sure the visual lisp extensions are available. Required by AutoCAD
    ; Bricscad will work fine without
    (vl-load-com)
         (if (findfile folder) ; if the path is valid
            (progn
                ; THEN Collect a list of files from the given folder
                (setq LispList (vl-directory-files folder "*.lsp" 1))
                ; if LISP files found
                (if LispList
                    ;THEN Load each of the LISP files found
                     (foreach Lisp LispList
                         (setq Lisp2load (strcat folder "\\" Lisp))
                         (princ (strcat "\nLoading: " Lisp2load "\t"))
                      (load Lisp2load)
                     ); end foreach
                     (princ (strcat "\nNo LISP routines found in:" folder)) ; ELSE prompt user
                 ); end if
            ); end progn
            (princ (strcat "\nFolder Not Found: " folder)) ; ELSE prompt user
         ); end if
    (princ); make a quiet exit
    ); end DEFUN LOAD-LISP[/code]

    To use you would then create a bit of code in on_doc_load.lsp to call the function with your preferred folder

    e.g.
    to load all the LISP routines found in a folder called "My documents\LISP"

    [code]; MYLISP
    ; Loads lisp from a folder in the users area
    (defun C:MYLISP ()
     (LOAD-LISP (strcat (getenv "USERPROFILE") "\\My Documents\\Lisp" )) ; Load any Lisp routines found
     (princ) ; make a quiet exit
    ); end DEFUN C:MYLISP

    (C:MYLISP) ; autorun on loading[/code]

    To load all the LISP routines in a folder relative to your current drawing
    [code]; PROJECTLISP
    ; Loads lisp from a folder relative to the current drawing
    ; Use to load project specific lisp routines
    (defun C:PROJECTLISP ()
        ; Load LISP from a sub folder relative to the current drawing file folder
        (LOAD-LISP (strcat (getvar "dwgprefix") "Lisp" ))
        ; Load LISP from a sub folder relative to the parent folder of the current drawing file
        ;(LOAD-LISP (strcat (getvar "dwgprefix") "..\\Lisp" ))
        (princ) ; make a quiet exit
    ); end DEFUN C:PROJECTLISP

    (C:PROJECTLISP) ; autorun on loading[/code]

    The above will autoload any lisp routines found in the specified folder each time you start a new drawing session. You can also manually load during a drawing session by entering MYLISP / PROJECTLISP on the command line.

    Regards,

    Jason Bourhill

    CAD Concepts


    Load-Lisp.lsp

  • Hello everybody,

    when I open "on-start-default.lisp" with Notepad or something there is nothing but this line :

    quote :

    ;this file will run once when the program starts. ;please do not edit. For custom actions on starting the program please create a file on_start.lsp.    end quote. When I try to copy the sentense to load an application, it does not work. I am not sure what is wrong with my files for my version of Bricscad 13. Can someone help me ? Thanks. Jan Boodts

  • Dag Roy, bedankt voor de uitgebreide uitleg. Maar ik denk dat mijn probleem hiermee niet opgelost zal geraken omdat de on_start_default.lsp uit de folder "support" geen inhoud bevat, enkel de reeds getoonde regels in mijn eerste schrijven.

    Mijn vraag eigenlijk is ; Is het normaal is dat er in de on-start-default.lsp geen code staat ?

    Met vriendelijke groeten,

    Jan

  • @ Jan,
    Het standaard 'on_start_default.lsp' bestand ziet er inderdaad uit zoals jij aangeeft. Alle regels beginnen met een puntkomma. Daarmee zijn deze regels commentaar en geen uitvoerbare code. Volgens deze commentaarregels is het de bedoeling dat een gebruiker zelf een eigen Lisp bestand 'on_start.lsp' aanmaakt. Het bestand 'on_start_default.lsp' is blijkbaar gereserveerd voor BricsCAD zelf, maar in de huidige vorm een 'dummy' bestand. Als BricsCAD wordt gestart dan wordt eerst 'on_start_default.lsp' geladen en daarna 'on_start.lsp'. Standaard worden de genoemde Lisp bestanden NIET in elke volgende tekening opnieuw geladen. Maar dit gedrag is met de variabele ACADLSPASDOC te wijzigen. De bestanden 'on_doc_load_default.lsp' (ook gereserveerd voor BricsCAD) en 'on_doc_load.lsp' worden wel in elke tekening geladen.
  • Mr. Gebbinck,  I know this is an old thread, so things may have changed when BricsCAD 14 was released.  Your web page says;
    • Type  (load "C:\\SomeFolder\\NameOfSomeOtherLispFile.lsp") . On Windows® you can use double backslashes or single forward slashes as the path separator. On Linux® you can only use single forward slashes.

    However, on my system, double back slashes don't work. An interesting note is that the error message converts the double back slashes into a single back slash. 

    Also, note that if you copy a path from a Windows window, you end up with single backslashes.   I found that to make this work, I had to put single forward slashes for the path.

    -Joe
  • Hi Joe,

    Roys advice is still valid. I would double check the separators for your path, and that you have enclosed in speech marks. You can make use of getfiled to build the path and filename for you:

    [code](getfiled "Select LISP file" "" "lsp" 8)[/code]

    This will return the full path and file name of the selected file to the text screen. For files that are on the support file search path (SRCHPATH) it will just return the filename. Generally I try to avoid using absolute paths when loading files. Instead would either add to the support file search path, or use a relative reference.

    You can test to see whether a file is on the search path by using findfile
    [code](findfile "mylispfile.lsp")[/code]
    If it returns nil, then it hasn't found your file.

    For casual use and testing you can simply Drag and Drop the file onto your drawing. http://bricsys.tv/m/?drag-and-drop-m156

    Regards,

    Jason Bourhill

    CAD Concepts

  • Joe, I suspect that you have misunderstood (the scope of) the statement: 'On Windows® you can use double backslashes or single forward slashes as the path separator.'

    In many programming languages, including Lisp, the backslash character has a special meaning: it is used as an escape character. To get a literal backslash you have to type '\\'. When you type '(load ...)' on the BricsCAD command line you are in fact entering Lisp code and therefore you have to use double backslashes (or single forward slashes).

    But this does not mean that you should, or can, use double backslashes whenever you are prompted for a path.
This discussion has been closed.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam