Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Building a commands analyzer (suggestions required)

7 REPLIES 7
Reply
Message 1 of 8
The_Caddie
461 Views, 7 Replies

Building a commands analyzer (suggestions required)

I want to create a lisp or short VBA program for AutoCAD, which simply lists the commands being executed by that user. Ideally I would like the list to be compiled into an excel sheet so that I can work out percentages.

 

The idea is required to analyse which commands are use most, less, or least With this data then collected I am able to build a much better interface clearing command buttons that are never or hardily ever used.

 

Obviously the easiest way would be to ask staff what the use the most, but answers are manipulated (tailored) to their opinions of how the world should turn.

 

Is this possible?

7 REPLIES 7
Message 2 of 8
Ken.Krupa
in reply to: The_Caddie

Can be done using command reactors to append each command used to a text file. Here is code to do it:

 

(vl-load-com)

;; Look for reactors already present
;; (prevents accumulation when using SDI)
(if (= (getvar "sdi") 1)
  (foreach rtype (vlr-reactors)
    (foreach react (cdr rtype)
      (setq temp (cdar (vlr-reactions react)))
      (if (= temp 'MY_CMDSTART)(setq my#reactors T))
    )
  )
)

(if (null my#reactors)(progn
  (vlr-command-reactor nil '((:vlr-commandWillStart . my_cmdStart)))
  (vlr-command-reactor nil '((:vlr-commandEnded . my_cmdEnd)))
  (vlr-command-reactor nil '((:vlr-commandCancelled . my_cmdEnd)))
))

(defun my_cmdStart (reactor cmdlist)
  (setq cmd$start T) ; leave global (do not localize)
)

(defun my_cmdEnd (reactor cmdlist / file fp cmd)
  (if cmd$start (progn
    ;(princ "\n***** CmdEnd ***** ")(princ)
    (setq
      file "c:\\cmdusage.txt" ; REVISE TO SUIT
      fp (open file "a")
      cmd (car cmdlist)
    )
    (write-line cmd fp)
    (close fp)
    (setq cmd$start nil)
  ))
  (princ)
)

You could then take that file into Excel to get your statistics somehow.

 

If it seems like the code takes more steps than necessary, it's because I found it to necessary to prevent two entries for each command used.

 

 

Ken Krupa
Krupa CADD Solutions
http://www.krupacadd.com
Message 3 of 8
The_Caddie
in reply to: Ken.Krupa

Is it possible to save the txt file in a format suffixed by the users logon variable? Examples being:

 

Cmd_user logon 1.txt

Cmd_user logon 2.txt

 

The_Caddie

Message 4 of 8
scottbolton
in reply to: The_Caddie

Amend

 

file "c:\\cmdusage.txt" ; REVISE TO SUIT

 

to

 

file (strcat "C:\\" (getvar "LOGINNAME") "_cmdusage.txt") ; REVISE TO SUIT

 

S

Message 5 of 8
The_Caddie
in reply to: Ken.Krupa

I have a question in relation, is it possible to have the reactor set to/for layers instead??

 

The lisp in combination with excel was a great success it turns out that only 62% of our current workspace is actually used and that tools previously not considered are better candidates then those found on the current workspace.

 

Layers seams to be another disaster area amongst our drafters, discussions on what should and should not be present as a standard have left the system with 100's of inactive, or barely used junk layers.

 

One comment though on the original lisp is that no sub functions are recorded example being -regapps in the purge command.

Message 6 of 8
scottbolton
in reply to: The_Caddie

This (cheap and cheerful) code creates a tab-separated txt file of layer names and the number of objects on each layer. You could attach it to a close or open reactor or just put it at the bottom of your acaddoc.lsp...

 

S

 

;;; Create a dotted list of layers and the number of objects on each layer ;;
(setq layertemp (tblnext "LAYER" T))
(setq layerlist (list (cdr (assoc 2 layertemp))))
(while (setq layertemp (tblnext "LAYER"))
  (setq layerlist (cons (cdr (assoc 2 layertemp)) layerlist))
  )
(setq layerlist (reverse layerlist)
      layercontents nil
      )
(foreach layer_nth layerlist
  (setq ss (ssget "X" (list (cons 8 layer_nth))))
  (if ss
    (setq ss (sslength ss))
    (setq ss 0)
    )
  (setq layercontents (cons (cons layer_nth ss) layercontents))
  )
(setq layercontents (reverse layercontents))
;;; Open the existing log file (if it exists) and sum the number of objects ;;
(if (setq layerfile (findfile "D:\\layerusage.txt"))
  (progn
    (setq filecheck (open layerfile "r")
   oldlayercontents nil
   )
    (while (setq line (read-line filecheck))
      (setq pos (vl-string-search "\t" line)
     layer (substr line 1 pos)
     objects (substr line (+ 2 pos))
     )
      (setq oldlayercontents (cons (cons layer (atoi objects)) oldlayercontents))
      )
    (close filecheck)
    (setq oldlayercontents (reverse oldlayercontents))
    (foreach layer_nth layercontents
      (setq layer (car layer_nth)
     objects (cdr layer_nth)
     )
      (if (assoc layer oldlayercontents)
 (setq oldlayercontents (subst
     (cons
       layer
       (+
         (cdr (assoc layer oldlayercontents))
         (cdr (assoc layer layercontents))
         )
       )
     (assoc layer oldlayercontents)
     oldlayercontents)
       )
 (setq oldlayercontents (append oldlayercontents (list (assoc layer layercontents))))
 )
      )
    (setq layercontents oldlayercontents)
    )
  )
;;; Write the list to a file ;;
(if layercontents
  (progn
    (setq filecheck (open "D:\\layerusage.txt" "w"))
    (foreach layer_nth layercontents
      (setq layer (car layer_nth)
     objects (cdr layer_nth)
     )
      (write-line (strcat layer "\t" (itoa objects)) filecheck)
      )
    (close filecheck)
    )
  )

Message 7 of 8
jggerth1
in reply to: The_Caddie

Interesting thought -- although I believe Autodesk already has such a tool.  Or at any rate had one that they used for similar purposes.  Perhaps contacting your reseller could put you in touch with the people in Autodesk who could provide that?

 

That aside -- It would be a better idea to also incorporate your people's personal opinions -- after all, you're looking for patterns of usage to tailor your interface, and  results from such a tool would logically _already_ be biased by the current user interface the users see.

 

Quite likely your more experienced & productive users are heavy keyboard junkies, and only access the ribbon/menus/.toolbar interface for the things they occasionally use.  Putting the most common commands there, and hiding the occasional ones, could easily turn out counter-productive.

Message 8 of 8
caddzone
in reply to: The_Caddie

You might want to keep in mind a Command reactor that tracks

command usage will not discriminate between commands that

are issued by the user directly, and commands that are issued

by scripting.  You really don't want to know about the latter, as

that is encapsulated by/within other user-initiated actions.

 

For example, Autodesk has begun modifying many of their

modeless UI's (like the floating layer palette and the ribbon) to

do things via the command line, solely because it makes the

actions that you take in those UIs 'recordable' by the Action

Regurgitator err... I mean recorder.

 

 



AcadXTabs for AutoCAD
Supporting AutoCAD 2000-2011


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost