General question about using custom commands in other programs

General question about using custom commands in other programs

Anonymous
Not applicable
798 Views
6 Replies
Message 1 of 7

General question about using custom commands in other programs

Anonymous
Not applicable

I'm teaching myself LISP and I have been trying to find an answer to a question I have but I can't seem to find a clear explanation, so I figured I would ask here:

 

If I write a LISP program that I can begin by entering the shortcut at the command line, can I call that LISP program from another custom LISP program or do I have to include the code in the new programs text file?

 

Example:

I wrote a program (C:DC - DimCentermark.lsp) that adds centermarks to all selected circles at 125% the diameter of its circle. Can I write another program that calls program "DC" before adding ordinate dimensions to selected lines? Or do I need to include the code from program "DimCentermark.lsp" in the code for the ordinate dimension program?

 

Thanks,

Chris

0 Likes
Accepted solutions (1)
799 Views
6 Replies
Replies (6)
Message 2 of 7

Satoews
Advocate
Advocate
Accepted solution

Yes you can, calling a command in lisp like this

 

(c:command)

 

in your instance

 

(defun c:yournextcommand ()
(c:dc)
(the rest of your code)

 

should work

Shawn T
0 Likes
Message 3 of 7

Satoews
Advocate
Advocate
(DEFUN C:BAD ()
  (IF
    (/=(STRCASE(GETVAR "CTAB")T) "model")
      (SETVAR "CTAB" "model")
  )
  (c:breakselected)
  (c:breakAndJoin)
  (c:fdm)
)

Just another example, I have a lisp that calls on three different lisps i use in a arrangment that suits me at times.

Shawn T
0 Likes
Message 4 of 7

scot-65
Advisor
Advisor

Calling a lisp from within another lisp is possible, but be aware

that the lisp that is being called *might* not be loaded.

 

One method to ensure that this will not be a issue is to make a "Menu Function"

of the lisp that is being called. This means no "c:" prefix to the name and the

block of code is located in the MNL (of the same name as the CUIX).

 

As a simple example (and borrowing your nomenclature)...

 

Inside the MNL:

(defun DIMCENTERMARK ( / )

 ...

)

 

Inside your "Utility.LSP" file:

(defun c:DC () (DIMCENTERMARK)) ;adds centermarks to circles

Notice here that a non-command lisp is called from inside a command lisp.

 

Inside another program [could be a stand-alone file]:

(defun c:WHATEVER ( / )

 ...

 (DIMCENTERMARK)

 ...

)

 

I will add a comment in the header section of the "stand-alone" that

"This program makes reference to the XXX Menu Functions". Where

"XXX" is the name of your menu system.

 

???

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 5 of 7

dbroad
Mentor
Mentor

Scott has a valid point but I generally avoid putting anything in MNL files that is not related to menus.  Instead, if one program depends on another program being loaded, this sequence should be in the dependent program file.

 

(if (null symbol_in_source_program) (load "File_containing_source_program"))
Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 6 of 7

Anonymous
Not applicable

Thanks for all the info guys, thats a huge help!

0 Likes
Message 7 of 7

dgorsman
Consultant
Consultant

If you set up a command as an abbreviated name (defun c:WHY ...) you'll quickly run into naming conflicts.  Instead use verbose naming ie. (defun c:WhyIsThisACommand ...).  If you have to change that (defun ...) later on to avoid a naming conflict you'll have to track down all instances which call that function by name and update those as well.

 

Instead, use the PGP file to establish WhyIsThisACommand as "WHY", or "WHYNOT", or whatever with no impact on the code.  This becomes even more useful when you are providing commands for multiple users who each may want their own alias.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.