Using lisp to note all missing SHX and helping for company maintainance

Using lisp to note all missing SHX and helping for company maintainance

cyberflow
Advisor Advisor
71 Views
2 Replies
Message 1 of 3

Using lisp to note all missing SHX and helping for company maintainance

cyberflow
Advisor
Advisor

Hi all,

Was wondering if this was possible with lisp to create a code that writes to a .txt file the name of the missing SHX, the drawing name where it's missing and where it's excepted to be located ?

Would help monitor company users and when things go missing

Plus it's going to accelerate opening times and such

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
0 Likes
72 Views
2 Replies
Replies (2)
Message 2 of 3

cyberflow
Advisor
Advisor

Not sure if this snippet could do the trick .... 

I guess it depends at what time the lisp is executed cause if you run it before it acknowledge what is missing you won't ever have no feedback from the lisp.

Here's the code : 

 

(vl-load-com)

;; Function to log missing SHX details to a file
(defun LogMissingSHX (shxname / dwgname shxpath outfile)
  (if shxname
      (progn
        ;; Get drawing name
        (setq dwgname (getvar "DWGNAME"))
        ;; Get expected SHX path (AutoCAD Fonts folder)
        (setq shxpath (strcat (getvar "ACAD") "Fonts\\"))
        ;; Open file in append mode
        (setq outfile (open "C:\\MissingSHX_Log.txt" "a"))
        
        ;; Write details to file
        (if (and dwgname shxname outfile)
            (progn
              (write-line (strcat "Drawing: " dwgname) outfile)
              (write-line (strcat "Missing SHX: " shxname) outfile)
              (write-line (strcat "Expected Location: " shxpath) outfile)
              (write-line "------------------------" outfile)
              (princ (strcat "\nLogged missing SHX: " shxname " for drawing: " dwgname))
            )
            (princ "\nError: Could not gather all required information.")
        )
        
        ;; Close the file
        (if outfile (close outfile))
      )
  )
  (princ)
)

;; Reactor callback to detect missing SHX files
(defun MissingSHXReactorCallback (reactor command-list / shxname)
  ;; Check if the command is related to drawing open or font loading
  (if (member (car command-list) '("OPEN"))
      (progn
        ;; Simplified detection: Check if FONTALT is triggered or prompt occurs
        ;; In practice, you may need to parse command-line prompts or use (tblobjname "STYLE" ...)
        ;; This is a placeholder; customize based on AutoCAD's behavior
        (setq shxname (getvar "FONTALT"))
        (if (and shxname (not (findfile (strcat shxpath shxname))))
            (LogMissingSHX shxname)
        )
      )
  )
  (princ)
)

;; Set up the reactor
(if (not *MissingSHXReactor*)
    (setq *MissingSHXReactor*
          (vlr-command-reactor nil '((:vlr-commandWillStart . MissingSHXReactorCallback)))
    )
)

(princ "\nMissing SHX Logger reactor loaded. Open a drawing to detect missing SHX files.")
(princ)

 

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
0 Likes
Message 3 of 3

cyberflow
Advisor
Advisor

Is there a way in a command line or via lisp or .net to check which SHX are missing ?

Frank Freitas

CAE/CAD/BIM Coordinator & Support Specialist

LinkedIn
0 Likes