See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: Autoload code for non-command functions

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

    Default Autoload code for non-command functions

    I use a lot of lisp in macros with arguments like:
    Code:
    ^C^C^P(or NewStyle (load "NewStyle.lsp"))(NewStyle "Arial" "arial.ttf")
    As they're not functions that can be entered at the command line without enclosing them in parenthesis () with arguments I cannot simply use the autoload (AutoLISP) function to load NewStyle.lsp.

    Does anyone have code that would autoload NewStyle.lsp and run the code (NewStyle "Arial" "arial.ttf") allowing me to shorten that macro to:
    Code:
    ^C^C^P(NewStyle "Arial" "arial.ttf")
    ?

    It would allow me to clean up a lot of macros.

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    1

    Default Re: Autoload code for non-command functions

    You could use a dummy Command to Autoload different groups of LISP Functions.

    Say your NewStyle function was part of group of various Style-related functions, you'd Autoload the dummy Command and include that Command call in your macros.

    AcadDoc.lsp:
    Code:
    (autoload "MyStyles.lsp" '("LoadMyStyles"))
    MyStyles.lsp:
    Code:
    (defun c:LoadMyStyles ()
    
         (defun NewStyle (name font / ) ())
         ;;<-- others as needed
    
         (princ)
    )
    Macro:
    Code:
    ^C^C^PLoadMyStyles;(NewStyle "Arial" "arial.ttf")
    This would allow you to launch a session without LOADing a bunch of code up front, but would Autoload several functions when the dummy Command is invoked the first time... You can break it up into as many (or as few) groups as you want to minimize the overhead

    HTH
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

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

    Default Re: Autoload code for non-command functions

    Sorry I didn't describe that as well as I should have. Busy at work today but needed to tweak a few macros.

    I wasn't really thinking of the autoload function exactly, just wanted to shorten all those macros without adding autoload code for every one of them.
    A "L&Run" lisp function that with the macro:
    Code:
    ^C^C^P(L&Run "NewStyle" "Arial" "arial.ttf")
    would load "NewStyle.lsp" if needed then run
    Code:
    (NewStyle "Arial" "arial.ttf")
    Much of the code I have has the same filename as the function. Some macros that call out multiple lisp functions to get something done can be rather large.

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    1

    Default Re: Autoload code for non-command functions

    Spitballing here.

    Maybe change the arguments to your "NewStyle" command into a list would allow the L&Run routine to have a consistent two argument list.
    Code:
    (defun L&Run (Func Args /)
      (if (or (car (atoms-family 1 (list Func)))
    	  (and
    	    (findfile (strcat Func ".lsp"))
    	    (load (findfile (strcat Func ".lsp"))
    		  "\nUnable to find file."
    	    )
    	  )
          )
        (apply (read Func) Args )
      )
    )
    Code:
    (L&Run "NewStyle" '("Arial" "arial.ttf"))
    Modify to fit your circumstances.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Similar Threads

  1. How autoload subroutines code
    By marco_antonio-77339780 in forum AutoCAD Customization
    Replies: 7
    Last Post: 2019-03-25, 04:24 PM
  2. Replies: 0
    Last Post: 2012-11-24, 07:38 PM
  3. AutoLOAD? From where?
    By methost in forum AutoCAD General
    Replies: 5
    Last Post: 2005-02-01, 08:10 PM
  4. error: no function definition: AUTOLOAD
    By dalej_k in forum AutoLISP
    Replies: 4
    Last Post: 2004-08-11, 11:58 PM
  5. autoload menu
    By inner69923 in forum VBA/COM Interop
    Replies: 5
    Last Post: 2004-07-16, 01:14 PM

Posting Permissions

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