Jump to content

Quick question regarding c:


Recommended Posts

Posted (edited)

I have been just starting to delve into the world of autoLISP, and have seen snippets of code that have, for example

defun c:

I was able to find out that this makes it so that the user is able to run the function from the command line. Now, the part where I get confused is when I see things like

defun rh:

What does this line do? I've seen variants in Lee Mac's code that have LM:

 

Is the ':' some sort of a namespace, or scope resolution operator? Can someone point me in the direction of where I can learn more about its use?

 

Thanks in advance!

Edited by brandalf_the_semiGray
Posted

[SEE COLON] simply means that the function name following can be used at the command line, like a core function (i.e.: Line, Circle, Pline). 

 

If you omit the prefix, or use your own like KW:Fun, then you have to include that part when you call the function name, along with enclosing it in parenthesis

(KW:Fun)

 

Some authors do this to their functions for identification purposes.

  • Thanks 1
Posted

In addition to @rkmcswain excellent answer above, look at these two functions, and spot the differences

 

(defun function_name (passed vars / local_vars)
   expressions
)

(defun C:function_name ( / local_vars)
   expressions
)

 

 

 

 

 

  • Thanks 2
Posted
3 hours ago, dlanorh said:

In addition to @rkmcswain excellent answer above, look at these two functions, and spot the differences


(defun function_name (passed vars / local_vars)
   expressions
)

(defun C:function_name ( / local_vars)
   expressions
)

 

 

Note that the "c:" prefix has no bearing on whether or not the function may accept arguments -

_$ (defun c:foo ( x ) (+ x 2))
C:FOO
_$ (c:foo 2)
4

The "c:" prefix is solely use to make a function available as a command which may be executed directly at the AutoCAD command line. Of course, evaluating a function which requires arguments as a command directly at the command line will result in a "too few arguments" error, but these two properties of a function are not related.

  • Thanks 1
Posted (edited)
3 hours ago, dlanorh said:

In addition to @rkmcswain excellent answer above, look at these two functions, and spot the differences

 


(defun function_name (passed vars / local_vars)
   expressions
)

(defun C:function_name ( / local_vars)
   expressions
)

 

 

 

 

 

The differences that catch my eye are the c : prefix to allow command line invocation, as well as one of the functions having passed variables.

 

25 minutes ago, Lee Mac said:

You may wish to refer to my explanation here.

This was precisely what I was looking for. Thank you very much to all three of you.

Edited by brandalf_the_semiGray
  • Like 1
Posted (edited)

You can call c defuns or plain defuns in code I often add run code on a (load "mylisp") to run straight away 1st time.

 

(c:function_name) put this as last line of code

also (moblk) as last runs my move block code which is wrapped in a defun called moblk but no need for keyboard input use when really only want to run once.

 

(function_name 12 22) normal function call

 

check to see if lisp is loaded looks for the defun

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))

(setq ans (AH:getvalsm (list "This is heading" "Line 1" 5 4 "11" "Line2" 8 7 "22" "Line3" 8 7 "33" "Line4" 8 7 "4")))

 

in a menu these are the same

^c^c(load "mover") mover

^c^c(load "mover")(c:mover)

 

 

 

Edited by BIGAL

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...