TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Rustabout on February 13, 2020, 02:45:34 PM

Title: Very Noob Question: Running a defined function in AutoLisp
Post by: Rustabout on February 13, 2020, 02:45:34 PM
If I define a function, say (defun C:MYFUNCTION (/)..... , if I want to run the same function from within an AutoLISP function, I copy the entire function, and just paste it, and delete the "C:". Quick but (very) dirty. How do you guys go about doing this?

I'm basically making functions that I want to run from both dialog boxes and the command prompt.

Thanks all!
Title: Re: Very Noob Question: Running a defined function in AutoLisp
Post by: JohnK on February 13, 2020, 03:24:37 PM
Just call a command type function like so:
Code: [Select]
(C:MYFUNCTION)
Title: Re: Very Noob Question: Running a defined function in AutoLisp
Post by: Rustabout on February 13, 2020, 08:05:56 PM
Thanks John!! These little knowledge gaps are what's killing me with the LISP.
Title: Re: Very Noob Question: Running a defined function in AutoLisp
Post by: JohnK on February 13, 2020, 08:31:13 PM
No problem. We've all been there (and will be there; for every programming language you learn/use).
Title: Re: Very Noob Question: Running a defined function in AutoLisp
Post by: dgorsman on February 13, 2020, 11:52:58 PM
I usually build it so the command function is a bare wrapper for the function which does the work (and takes appropriate arguments).
Title: Re: Very Noob Question: Running a defined function in AutoLisp
Post by: Rustabout on February 14, 2020, 09:09:10 AM
I do this as well dgorsman. I have a standard function that will insert a block on a specific layer. And it will create the layer if the layer doesn't already exists. I use it for many different blocks, and always had to manually change things like the block definition's name, the layer, the layer's properties, etc... I finally got smart and realized I can just do what you've mentioned, and I can create new block insert routines in a matter of seconds.
Title: Re: Very Noob Question: Running a defined function in AutoLisp
Post by: JohnK on February 14, 2020, 10:01:01 AM
The below doesn't create new layers but you still may be able to glean some information from it for your current routine.

https://www.theswamp.org/index.php?topic=31324.0
Title: Re: Very Noob Question: Running a defined function in AutoLisp
Post by: Rustabout on February 16, 2020, 02:47:57 PM
Thanks John, there's definitely some neat stuff in there. Way more complex than my method. I tend to use the "command" functions quite a bit. Quick and easy, but they have their drawbacks.
Title: Re: Very Noob Question: Running a defined function in AutoLisp
Post by: BIGAL on February 18, 2020, 04:17:22 AM
Look into a library of common lisp defuns, they can be in 1 lisp or load when required, you hinted at does layer exist, its 1 line in any of your code.

(laymiss (setq lay "Mylayer") 12 "Dashed") so you would have a library defun that checks does layer exist I have hinted option color and line type.

I have library DCL routines they take 2-3 lines of code in any routine asking for values or as a replacement to Initget, they can have 1 input or up to screen limits alphabet works "A-Z" go yo Cadtutor, downloads, Multi Radio and getvals.

eg of initget as a dcl
(if (not AH:Butts)(load "Multi Radio buttons.lsp")) ; loads lisp if its not already loaded
(setq ans (ah:butts but "h"  '("Yes or No" "Yes" "No"))) ; ans holds the button picked value