Jump to content

Get a list of used AutoLISP commands


Recommended Posts

Posted

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.

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

 

cmdsCargados.png

Edited by Nikon
Posted
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)

 

Posted (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 by GLAVCVS
Posted

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.

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