Author Topic: Very Noob Question: Running a defined function in AutoLisp  (Read 1845 times)

0 Members and 1 Guest are viewing this topic.

Rustabout

  • Newt
  • Posts: 135
Very Noob Question: Running a defined function in AutoLisp
« 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!

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Very Noob Question: Running a defined function in AutoLisp
« Reply #1 on: February 13, 2020, 03:24:37 PM »
Just call a command type function like so:
Code: [Select]
(C:MYFUNCTION)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Rustabout

  • Newt
  • Posts: 135
Re: Very Noob Question: Running a defined function in AutoLisp
« Reply #2 on: February 13, 2020, 08:05:56 PM »
Thanks John!! These little knowledge gaps are what's killing me with the LISP.

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Very Noob Question: Running a defined function in AutoLisp
« Reply #3 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).
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Very Noob Question: Running a defined function in AutoLisp
« Reply #4 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).
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Rustabout

  • Newt
  • Posts: 135
Re: Very Noob Question: Running a defined function in AutoLisp
« Reply #5 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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Very Noob Question: Running a defined function in AutoLisp
« Reply #6 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
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Rustabout

  • Newt
  • Posts: 135
Re: Very Noob Question: Running a defined function in AutoLisp
« Reply #7 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.

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: Very Noob Question: Running a defined function in AutoLisp
« Reply #8 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

« Last Edit: February 18, 2020, 04:24:12 AM by BIGAL »
A man who never made a mistake never made anything