Aftertouch Posted November 27, 2017 Share Posted November 27, 2017 Hello all, While trying to learn ALOT of Lee Mac's his coding, i came across this very 'simple' piece of code... ;; Active Document - Lee Mac ;; Returns the VLA Active Document Object (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (LM:acdoc) ) Why is this code so 'complex' and isnt it just defined as: (defun LM:acdoc ( / ) (vla-get-activedocument (vlax-get-acad-object)) ) Since it seems to return the same value?? Quote Link to comment Share on other sites More sharing options...
MURAl_KMD Posted November 28, 2017 Share Posted November 28, 2017 Hi Aftertouch If already a function LM:acdoc (may be some old function) is loaded, it will be replaced by Lee Mac's coding LM:acdoc (latest coding). Its my understanding. Quote Link to comment Share on other sites More sharing options...
Grrr Posted November 28, 2017 Share Posted November 28, 2017 (edited) Welcome to learn LeeSp I think Lee calls this a "run-time evaluation". The key is what happens when for the first time (LM:acdoc) is called. Here are some observations from the console: [s]_$ (defun printhello nil (eval (list 'defun 'printhello 'nil (print "Hello"))) (printhello) ) PRINTHELLO _$ (printhello) [color="red"]"Hello" "Hello"[/color] [color="green"]; !!![/color] _$ (printhello) [color="red"]"Hello"[/color] [color="green"]; now it exits cleanly?[/color] _$ (printhello) [color="red"]"Hello"[/color] _$ (printhello) [color="red"]"Hello"[/color][/s] [s]_$ (defun printhello nil (print "Hello") ) PRINTHELLO _$ (printhello) [color="red"]"Hello" "Hello"[/color] _$ (printhello) [color="red"]"Hello" "Hello"[/color] _$ (printhello) [color="red"]"Hello" "Hello"[/color][/s] Further than this my knowledge is restrained, so it would be nice if someone explained why he uses this. Edited November 29, 2017 by Grrr Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted November 28, 2017 Share Posted November 28, 2017 @Grrr: Maybe this helps to explain your 'clean exit' issue?: (type (print "Hello")) => STR When first called, Lee's LM:acdoc function redefines itself. The new definition directly returns the active document object and is therefore a (minute) bit faster than the less complex function proposed by Aftertouch. Quote Link to comment Share on other sites More sharing options...
Grrr Posted November 29, 2017 Share Posted November 29, 2017 Roy, Thanks - now I see that my observation brings more confusion to this. So no difference in the returns: _$ (defun test nil (eval (list 'defun 'test 'nil "return_this_string")) (test) ) TEST _$ (test) "return_this_string" _$ (test) "return_this_string" _$ (test) "return_this_string" _$ (defun test nil "return_this_string" ) TEST _$ (test) "return_this_string" _$ (test) "return_this_string" _$ (test) "return_this_string" And I'll stick to your message: When first called, Lee's LM:acdoc function redefines itself. The new definition directly returns the active document object and is therefore a (minute) bit faster than the less complex function proposed by Aftertouch. Quote Link to comment Share on other sites More sharing options...
Aftertouch Posted November 29, 2017 Author Share Posted November 29, 2017 Alright, We got this case solved. Thanks for the toughts! Quote Link to comment Share on other sites More sharing options...
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.