cagorskij Posted July 18, 2024 Posted July 18, 2024 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. Quote
cagorskij Posted July 18, 2024 Author Posted July 18, 2024 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? Quote
fuccaro Posted July 18, 2024 Posted July 18, 2024 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? 1 Quote
exceed Posted July 19, 2024 Posted July 19, 2024 (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 July 19, 2024 by exceed 1 Quote
CyberAngel Posted July 19, 2024 Posted July 19, 2024 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. 1 Quote
Recommended Posts
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.