Accessing lisp functions from another lisp file.

Accessing lisp functions from another lisp file.

davidlanesmith673
Enthusiast Enthusiast
2,859 Views
4 Replies
Message 1 of 5

Accessing lisp functions from another lisp file.

davidlanesmith673
Enthusiast
Enthusiast

I was wondering if there is a way to call functions written in one lisp file from another lisp file. Is there a way to import the functions from that file into the other one?

0 Likes
Accepted solutions (1)
2,860 Views
4 Replies
Replies (4)
Message 2 of 5

CodeDing
Advisor
Advisor
Accepted solution

@davidlanesmith673 ,

 

Imagine lisp functions as either being loaded into AutoCAD or Not. There are only those 2 options.

Once they have been loaded into AutoCAD they are essentially added to a large list of available functions.

When you call ANY function, the list gets checked to see if that function is available or not. If it is available (loaded) then the function will run. Otherwise it will not.

 

This is why it matters which order your lisps have to be loaded. If we run a command which calls a function from a file that has not been loaded yet, it will fail.

 

Run this in your Command Line, it will show all available functions:

(atoms-family 1)

 

EDIT:

With all that being said... It doesn't entirely matter what functions you write inside your file. Write away to your heart's desire. Just understand that once your file gets loaded & your function called.. you will need to be sure that all supporting functions are loaded also.

 

Best,

~DD

Message 3 of 5

davidlanesmith673
Enthusiast
Enthusiast

Ok that makes sense, thank you very much!!

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant

If the function you want to call is defined with:

  (defun something (A B C / d e f) ...

that is, not a command, but a function with arguments, with A, B and C being the arguments, then the way to call it from another function [assuring first that it is loaded] is in parentheses with the function name followed by the arguments:
  (something ValueForArgumentA ValueForArgumentB ValueForArgumentC)

 

If the function you want to call is defined with:

  (defun something (/ d e f) ...

that is, not a command, but a function, but without arguments, then the way to call it from another function [assuring first that it is loaded] is simply in parentheses:
  (something)

 

If the function you want to call is defined with:

  (defun C:something (/ d e f) ...

that is, a custom command definition, it's not supposed to have arguments, and the way to call it is in parentheses with the prefixed C:

  (C:something)

Kent Cooper, AIA
Message 5 of 5

Sea-Haven
Mentor
Mentor

A bit more I demand load a lot of Library lisps rather than paste all the code into the current lisp this is done easy using a couple of lines of code. An example it uses the check if a defun exists if not load the program.

 

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= but nil)(setq but 1))
(setq ans (ah:butts but "h"  '("Yes or No" "Yes" "No"))) ; ans holds the button picked value