GLAVCVS Posted 3 hours ago Posted 3 hours ago I need you to explain a little more. Did you use multiple Lisp commands or just load files? Take a screenshot of the code you pasted into the "acad2021Doc.lsp" file. Quote
Nikon Posted 3 hours ago Author Posted 3 hours ago (edited) 13 minutes ago, GLAVCVS said: I need you to explain a little more. Did you use multiple Lisp commands or just load files? Take a screenshot of the code you pasted into the "acad2021Doc.lsp" file. I load programs and use them. Edited 3 hours ago by Nikon Quote
Lee Mac Posted 3 hours ago Posted 3 hours ago On 9/27/2025 at 12:33 PM, Nikon said: LISPLogV1-0.lsp is a very convenient program. Thanks @Lee Mac. Is it possible to get a list of lisp commands in the drawing? That is, when saving a drawing, a request appears: "Save a list of lisp commands?" and the text with the commands is inserted into the drawing? Here's a quick & dirty version - it's not advisable to prompt the user for any input as part of a reactor callback. (defun init ( ) (foreach grp (vlr-reactors :vlr-command-reactor :vlr-lisp-reactor) (foreach rtr (cdr grp) (if (= "lisp-commands" (vlr-data rtr)) (vlr-remove rtr) ) ) ) (setq lisp-command-list nil) (vlr-command-reactor "lisp-commands" '((:vlr-commandwillstart . onsave))) (vlr-lisp-reactor "lisp-commands" '((:vlr-lispwillstart . onlisp))) (princ) ) (defun onsave ( rtr arg / idx lyr sel str ) (setq lyr "lisp-commands") (cond ( (not arg)) ( (not (wcmatch (setq arg (strcase (car arg))) "SAVE,QSAVE,SAVEAS"))) ( lisp-command-list (if (setq sel (ssget "_X" (list (cons 8 lyr)))) (repeat (setq idx (sslength sel)) (entdel (ssname sel (setq idx (1- idx)))) ) ) (setq str "") (foreach itm (vl-sort lisp-command-list '(lambda ( a b ) (> (cdr a) (cdr b)))) (setq str (strcat str "\\P" (car itm) "\t\t" (itoa (cdr itm)))) ) (makelayer lyr) (entmakex (list '(0 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") '(010 0.0 0.0) (cons 1 (substr str 3)) (cons 8 lyr) ) ) ) ) (princ) ) (defun onlisp ( rtr arg / fun itm ) (cond ( (not arg)) ( (wcmatch (setq arg (strcase (car arg))) "~(C:*)")) ( (setq fun (substr arg 4 (- (strlen arg) 4)) itm (assoc fun lisp-command-list) ) (setq lisp-command-list (subst (cons (car itm) (1+ (cdr itm))) itm lisp-command-list)) ) ( (setq lisp-command-list (cons (cons fun 1) lisp-command-list))) ) (princ) ) (defun makelayer ( lay ) (if (not (tblobjname "layer" lay)) (entmake (list '(0 . "LAYER") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbLayerTableRecord") '(070 . 0) (cons 2 lay) '(062 . 8) '(290 . 0) ) ) ) ) (vl-load-com) (init) 1 Quote
GLAVCVS Posted 2 hours ago Posted 2 hours ago (edited) Great code, as always, Mr. Lee As for mine, I think I forgot that some reactors are persistent. So, Nikon, the problem is that you must have opened the same drawing several times in the same AutoCAD session, and several prompts have accumulated, repeating the request several times. That problem shouldn't occur anymore with this new code. Also, you'll be able to see the text inserted before confirming the closing of the drawing. Simply replace the "fota" function in your "acad2021Doc.lsp" with this new one. (defun fota (/ arch cad cmd mens) (defun pregunta (a b / cad) (cond ((= (car b) "CLOSE") (if (and *lstCmds* (setq mens (cmdsCargados)) (= (vlax-invoke-method (vlax-create-object "wscript.shell") 'popup "驴Dejar en el dibujo un MTEXT con todos los comandos utilizados?" 0 "Guardar comandos usados" 4) 6) ) (progn (vlr-remove-all) (vla-AddMText (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3d-point (getpoint "\nInsertion point...")) 100 mens) (vlax-invoke-method (vlax-get-acad-object) 'Update) ) (vlr-remove-all) ) ) ((= (type a) 'VLR-Lisp-Reactor) (if (not (member (setq cad (substr (car b) 4 (- (strlen (car b)) 4))) *lstCmds*)) (setq *lstCmds* (cons (substr (car b) 4 (- (strlen (car b)) 4)) *lstCmds*)) ) ) ) ) (vlr-remove-all) (foreach sim (atoms-family 0) (if (wcmatch (setq cmd (strcase (vl-princ-to-string sim) T)) "c:*") (setq *afI* (cons sim *afI*)) ) ) (setq *r* (vlr-command-reactor nil '((:vlr-commandwillStart . pregunta)))) (setq *r1* (vlr-lisp-reactor nil '((:vlr-lispwillstart . pregunta)))) ) Edited 2 hours ago by GLAVCVS 1 Quote
Lee Mac Posted 1 hour ago Posted 1 hour ago Thanks @GLAVCVS I would advise against (vlr-remove-all), as this will remove all reactors defined within the session, not only those defined by your program. Quote
Nikon Posted 1 hour ago Author Posted 1 hour ago 1 hour ago, Lee Mac said: Here's a quick & dirty version - it's not advisable to prompt the user for any input as part of a reactor callback. Please explain how to use it correctly, which command to call? Quote
Nikon Posted 1 hour ago Author Posted 1 hour ago 1 hour ago, GLAVCVS said: As for mine, I think I forgot that some reactors are persistent. So, Nikon, the problem is that you must have opened the same drawing several times in the same AutoCAD session, and several prompts have accumulated, repeating the request several times. That problem shouldn't occur anymore with this new code. Also, you'll be able to see the text inserted before confirming the closing of the drawing. Simply replace the "fota" function in your "acad2021Doc.lsp" with this new one. Yes, I may have opened the same drawing several times. I noticed that if I use 2 lisps, then close the file, but cancel closing it and continue working in this file with new codes, when I close it again, the suggestion to save the list of commands does not appear... Quote
Steven P Posted 7 minutes ago Posted 7 minutes ago 2 hours ago, Lee Mac said: Here's a quick & dirty version - it's not advisable to prompt the user for any input as part of a reactor callback. Lee it is a rare day when I find an improvement for you, and it might be today... might be... In your onsave would it be preferable to take any strings that 'sel' finds in the ssget and append the new commands to them? Maybe put some sort of delimitator between old and new strings? Reason I ask, it is not unusual for me to complete a drawing over a few sessions - end of day into the next day being most common - which means the reactors will be reset... but the commands used will still need to be listed. 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.