Jump to content

Recommended Posts

Posted

Hiya o/

Just wondering how to make it so that when you load a lisp file into CAD, that it spits out the function's name & not some other sub-function within the lisp file (i.e. if there's 2 'defun's, it usually echos the last defun)

What I've been doing is ordering the defuns so the main function appears last, but that feels wrong/messy.

Posted

Try adding a (princ) as very last line.

  • Like 1
Posted

Thank you!
It seems to simply return nothing when loading, and if I add a string it'll output twice, like this:
(princ "Function loaded.")
: Function loaded."Function loaded."
I assume because it's running the princ as well as outputting the return value?

Posted

You could try to define the second function *inside* the first function. Something like:

(defun c:function1()
  (defun function2(position)
    (entmake (list
	       '(0 . "POINT")
	       (cons 10 position))
	     )
    )

  (setq ang 0.0 ang1 0.1)
  (repeat 1000
    (setq x (sin (* 5.0 ang))
	  y (cos (* 7.0 ang))
	  z (* (cos ang) (sin ang))
	  ang (+ ang ang1)
	  )
    (function2 (list x y z))
    )
)

If you load this, AutoCAD will report only "function1 loaded".

Does this help you?

  • Like 1
Posted (edited)
19 hours ago, cagorskij said:

Thank you!
It seems to simply return nothing when loading, and if I add a string it'll output twice, like this:
(princ "Function loaded.")
: Function loaded."Function loaded."
I assume because it's running the princ as well as outputting the return value?

(defun c:foo ( / )
  ;~~~~  
  (princ)  ;<- this one
)
               
(defun subfunc1 ( / ) 
  ;~~~~
)
               
(defun subfunc2 ( / ) 
  ;~~~~
)
               
(princ "\n function FOO loaded.")
(princ)

 

like this

Edited by exceed
  • Like 1
Posted

Thank you both ^_^

Posted
On 7/17/2024 at 9:08 PM, cagorskij said:

What I've been doing is ordering the defuns so the main function appears last, but that feels wrong/messy.

 

In some languages you have to do it that way. If the subfunctions haven't loaded, you can't call them.

  • Like 1

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...