Author Topic: Syntax for calling commands from autocad  (Read 4249 times)

0 Members and 1 Guest are viewing this topic.

SIDESHOWBOB

  • Guest
Syntax for calling commands from autocad
« on: February 23, 2012, 01:22:49 PM »
Yet another newbie question here, but if I define this

Code - Auto/Visual Lisp: [Select]
  1. (defun C:test (i) (* 2 i))

How do I pass the argument on the autocad command line?  Tried brackets, spaces, etc - no luck!

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Syntax for calling commands from autocad
« Reply #1 on: February 23, 2012, 01:25:49 PM »
Don't use "C:" with functions that have arguments.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Syntax for calling commands from autocad
« Reply #2 on: February 23, 2012, 01:26:32 PM »
eg.
Code: [Select]
Command: (defun test (i) (* 2 i))
TEST
Command: (test 5)
10
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

SIDESHOWBOB

  • Guest
Re: Syntax for calling commands from autocad
« Reply #3 on: February 23, 2012, 01:30:01 PM »
Ah, I see you are both right.  You can call functions from the command line with (test 2) same as you would from the lisp prompt.  But if you do so, autocad does not hide internal lisp functions from you!  I thought I was supposed to be able to hide anything without a C: ... never mind :)

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Syntax for calling commands from autocad
« Reply #4 on: February 23, 2012, 01:41:34 PM »
Not sure what you mean by "hiding". Are you talking about scope?

Just in cast you stumble upon...I'll add this (It's not "proper" so I wasn't going to mention it but you're a developer so you can add as many grains of salt to this as necessary):

Quote
Command: (defun C:test2 (i) (* 2 i))
C:TEST2

Command: (c:test2 2)
4

However, use this form instead (don't use the above).
Code - Auto/Visual Lisp: [Select]
  1. (defun test (i) (* 2 i))

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Syntax for calling commands from autocad
« Reply #5 on: February 23, 2012, 01:42:14 PM »
I thought I was supposed to be able to hide anything without a C: ... never mind :)

You can if you 'compile' the code to a VLX with a separate namespace, the function won't be available outside of the namespace (unless exported using vl-doc-export)

FYI, concerning the 'c:' prefix, it merely makes the function available at the command-line, but since 'c:test' is just another symbol, the following does work (though, its not good practice):

Code: [Select]
Command: (defun c:test ( i ) (* 2 i))
C:TEST

Command: (c:test 2)
4

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Syntax for calling commands from autocad
« Reply #6 on: February 23, 2012, 01:47:11 PM »
*lol* There's an echo in here!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Syntax for calling commands from autocad
« Reply #7 on: February 23, 2012, 02:09:51 PM »
*lol* There's an echo in here!
an echo in here!
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Syntax for calling commands from autocad
« Reply #8 on: February 23, 2012, 05:40:18 PM »
And what's wrong with this?
Code: [Select]
    (defun C:test (/ i)
      (if (setq i (getreal "\nEnter number:"))
        (* 2 i)
      )
    )
When you hit the space bar after test the prompt will appear, enter your number and hit enter.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Syntax for calling commands from autocad
« Reply #9 on: February 23, 2012, 05:51:02 PM »
And what's wrong with this?

Nothing at all :-)

Though I think the OP was enquiring as to how to pass arguments to LISP functions  :-)

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Syntax for calling commands from autocad
« Reply #10 on: February 23, 2012, 06:00:30 PM »
And what's wrong with this?
...

Procedurally or semantically?


I think the OP wanted to learn how to call another AutoLisp function.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Syntax for calling commands from autocad
« Reply #11 on: February 23, 2012, 06:09:51 PM »
[
Procedurally or semantically?

Yes.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Syntax for calling commands from autocad
« Reply #12 on: February 23, 2012, 08:14:10 PM »
*lol*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SIDESHOWBOB

  • Guest
Re: Syntax for calling commands from autocad
« Reply #13 on: February 24, 2012, 05:37:14 AM »
And what's wrong with this?

Nothing, in fact I see that's the answer I need.  While I may have been asking how to call lisp functions from the autocad command line, what I really wanted to know was how to package up my lisp scripts for users to run conveniently. Ta ;)