See the top rated post in this thread. Click here

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

Thread: AutoLISP

  1. #1
    Member
    Join Date
    2013-04
    Posts
    5
    Login to Give a bone
    0

    Default AutoLISP

    I have an AutoLISP routine that i use APPLOAD to load. Then once it is loaded, I must use a command line command to initiate the lisp routine. I need to figure out a way so that I can have this routine autoload every time autocad is opened (presumably by placing it in the startup suite) and then not need to physically type the initiation command on the command line. Reason being is I need to make it idiot proof so I can roll it out to all users in our office and not have to make sure they load it and initiate it each time.

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

    Default Re: AutoLISP

    The old-school way I learned was to employ an AUTOLOAD call within AcadDoc.lsp, which expedites time to open a document, and demand loads the LISP when the command(s) specified are invoked by user.

    If you're up for the shiny new alternative, consider the Autoloader mechanism (for 2012+).

    Cheers
    "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
    Member
    Join Date
    2013-04
    Posts
    5
    Login to Give a bone
    0

    Default Re: AutoLISP

    So that would be in leiu of making any physical changes to my current command .lsp that i have placed into my startup suite. Additionally, can you tell me more about the autoloader? I am unfamiliar with that.

  4. #4
    Member
    Join Date
    2013-04
    Posts
    5
    Login to Give a bone
    0

    Default Re: AutoLISP

    To continue with this thought. Is there a way to "auto-load" the command itself so that the user does not have to invoke the command for it to initiate the features of the lisp routine? I need this to be an automatic process so this happens behind the scenes of my end users. The routine I have will autolayer items such as dims and text so I need this to fire up all by itself once the end user begins each autocad session.

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

    Default Re: AutoLISP

    Quote Originally Posted by dderr368271 View Post
    So that would be in leiu of making any physical changes to my current command .lsp that i have placed into my startup suite. Additionally, can you tell me more about the autoloader? I am unfamiliar with that.
    Autoloader is quite useful and supports LISP, VBA, .NET, ObjectARX, etc. APIs, but does have some limitations, so be sure you understand this new mechanism prior to investing a great deal of time rolling it out. To learn more about Autoloader, see the link in my signature.

    I use Autoloader quite a bit, especially as it is a requirement for all apps submitted to Autodesk Exchange Apps store... At work (I'm a CAD production guy, who does programming as a hobby), I use both Acad[Doc].lsp and Autoloader.

    Quote Originally Posted by dderr368271 View Post
    To continue with this thought. Is there a way to "auto-load" the command itself so that the user does not have to invoke the command for it to initiate the features of the lisp routine? I need this to be an automatic process so this happens behind the scenes of my end users. The routine I have will autolayer items such as dims and text so I need this to fire up all by itself once the end user begins each autocad session.
    Aha - I did not understand that from your initial post. Apologies.

    Yes - What you would do is first LOAD the desired LISP routine, and then call it within your AcadDoc.lps, for example:

    Code:
    ;; load the routine, include file path for files not found in SFSP
    (load "Foo.lsp")
    
    ;; call the command just loaded
    (c:FOO)
    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

  6. #6
    Active Member
    Join Date
    2013-07
    Posts
    66
    Login to Give a bone
    1

    Default Re: AutoLISP

    Yes, to further explain blackBox's post

    Within any folder that is within your support file search paths
    Tools->options->Files
    or
    by typing (findfile "acaddoc.lsp") into your autocad and browsing to the folder it tells you

    there's a file called acaddoc.lsp
    or if (findfile "acaddoc.lsp") returns "nil"
    that means that it has yet to be created.

    But you'd either create within a folder in your SFSP or browse to the existing acaddoc.lsp file
    and you'd add the lines to automatically load your routine (we're going to continue to call it "foo")

    Code:
    (if (not foo)(load "foo.lsp"))  ;this does a simple check to see if the command "foo" is available, if not it loads the "foo.lsp"
    
    ....get to the end of the acaddoc.lsp file and...
    
    (C:FOO)
    just almost exactly like blackbox explained it.
    You will want to ensure that acaddoc.lsp is within your search paths and that "load acad lsp with every drawing" is checked in the options for autocad.
    This will load your "foo" routine into each drawing, and if placed at the very bottom to where there's nothing beyond (C:FOO)
    it will invoke the routine upon opening each drawing or new instance of autocad, which should pre-set items to your layers as intended.
    It will also make the command available for anytime anyone needs to run it manually by simple typing "foo" into autocad without the quotes.

    Hope this wasn't too redundant I just wanted to explain the usage of acaddoc.lsp a little more

  7. #7
    Member
    Join Date
    2013-04
    Posts
    5
    Login to Give a bone
    0

    Default Re: AutoLISP

    Thank you guys for the direction. Things are working famously now!

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: AutoLISP

    Just a couple of nit-picks:
    Quote Originally Posted by bhull1985403354 View Post
    Code:
    (if (not foo)(load "foo.lsp"))  ;this does a simple check to see if the command "foo" is available, if not it loads the "foo.lsp"
    
    ....get to the end of the acaddoc.lsp file and...
    
    (C:FOO)
    That should be
    Code:
    (if (not c:foo) (load "foo.lsp"))  ;... rest of the code is fine

    Quote Originally Posted by bhull1985403354 View Post
    ... and that "load acad lsp with every drawing" is checked in the options for autocad.
    Not needed for ACADDOC.LSP. It simply makes ACAD.LSP act as if it's an ACADDOC.LSP file (i.e. gets loaded for each DWG opened) as opposed to how an ACAD.LSP normally works (i.e. only loaded when acad starts).

    It's an old setting which was only useful for those who upgraded from the single-document-interface ACads (i.e. R10/R11) to the multi document interface ACads in the early to mid-90s. That was so they didn't need to rename their ACAD.LSP files to ACADDOC.LSP. IMO more trouble than it's worth.

    Actually, depending on the reason the OP wants the command to start every time - it might be "wrong" to issue the command every time a DWG is opened. E.g. if he's opening a non-modal OpenDCL dialog it might actually close the dialog if the 2nd DWG is opened. For these you might want to leave that setting turned off, and load & call the command inside ACAD.LSP (you can use vl-load-all to ensure the LSP file is loaded to all DWG opened and yet to be opened).

  9. #9
    Active Member
    Join Date
    2013-07
    Posts
    66
    Login to Give a bone
    0

    Default Re: AutoLISP

    Well thanks for clearing a few things up for me Irneb,
    especially with the not-needed second options mention, the load acad.lsp into every dwg. Simply said, if i'm running with acaddoc.lsp then the acad.lsp isn't irrelevant, just irrelevant to keeping custom functions loaded into each session- the acaddoc.lsp takes care of that. I wasn't sure if it was dependent on the switch being toggled within the options but as per your explination it is not. Thanks for clearing that up.

    Also, for the logical not statement.... in which cases is there a difference between placing the C: in front or issuing the logical not without the C:, like so (that im using in a macro):
    Code:
    ^C^C(if (not doublebub)(load "doublebub.lsp"));doublebub;
    Not that I believe my method to be the more correct, i'm just noticing that my method if wrong was still satisfying the conditional correctly and the code was executing as intended- just wondering what's the difference, specifically? I understand that one is basically saying (command "doublebub") and the other is just saying (doublebub) but they both apparently satisfy the conditional so I'm seeing if there's any functional difference.

    Thanks for sharing Irneb, I love to learn!

  10. #10
    100 Club
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    116
    Login to Give a bone
    0

    Default Re: AutoLISP

    I think the point was that you need to check for the function by it's name, rather than by the name of the lisp file. The "foo.lsp" file mentioned above contains a function named "c:foo", so it is "c:foo" that needs to be checked for. If the function has the exact same name as the file, as in your "doublebub" example, this is not an issue.

Page 1 of 2 12 LastLast

Similar Threads

  1. Autolisp
    By thechinaman in forum AutoCAD General
    Replies: 7
    Last Post: 2011-05-23, 04:07 AM
  2. autolisp help
    By sam_ctlim in forum AutoCAD General
    Replies: 9
    Last Post: 2008-06-11, 11:51 AM
  3. Autolisp
    By bulalakaw80 in forum AutoCAD Customization
    Replies: 6
    Last Post: 2007-11-15, 07:32 PM
  4. AutoLisp or VBA
    By red2002yzfr1 in forum ACA General
    Replies: 6
    Last Post: 2006-05-22, 02:36 PM
  5. autolisp help
    By guyogordo in forum AutoLISP
    Replies: 9
    Last Post: 2004-09-20, 12:15 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
  •