Lisp for updating drawing properties (Issue Date)

rosader
Enthusiast
Enthusiast

Lisp for updating drawing properties (Issue Date)

rosader
Enthusiast
Enthusiast

Forgive me for the noob question but I am self taught on lisp code and my skill level is not the best

I need a lisp that will go into drawing utilities, drawing properties, then change the value of the custom property "publish date" to today's date in the format of MON DD, YYYY

 

Our title block also has a "plot date" section with a formula to always display current date but the "publish date" only needs updated whenever published. Right now we go in and do it manually but would be nice to make it a simple lisp command. I tried asking chat gpt but the code it gave me is giving me errors and I don't know how to pinpoint where the problem(s) are.

0 Likes
Replies (2)

CodeDing
Advisor
Advisor

@rosader ,

 

Here are my functions for accessing Custom Drawing Properties:

;; key - string, representing key value of custom dwgprop to search for
;; returns - string, of dwgprop value if found, or nil
(defun CDP-Get (key / docProps return)
  (setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
  (vl-catch-all-apply 'vla-GetCustomByKey (list docProps key 'return))
  return
);defun

;; key - string, representing key value of custom dwgprop to search for
;; val - string, representing custom value to be used for the "key" custom dwgprop
;; returns - string, the string provided to "val" parameter if successful, otherwise nil
(defun CDP-Set (key val / docProps)
  (setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
  (if (not (vl-catch-all-apply 'vla-SetCustomByKey (list docProps key val)))
    val
  );if
);defun

;; Retrieves all Custom Drawing Properties for current drawing.
;; returns - list, as ((key . value) ...) of all custom drawing properties if any, or nil
(defun CDP-List ( / docProps cnt key val return)
  (setq docProps (vla-get-SummaryInfo (vla-get-ActiveDocument (vlax-get-acad-object))))
  (repeat (setq cnt (vla-NumCustomInfo docProps))
    (vla-GetCustomByIndex docProps (setq cnt (1- cnt)) 'key 'val)
    (setq return (cons (cons key val) return))
  );repeat
);defun

 

To Format the date, you can use this function:

(defun today ( / date months)
  (setq date (rtos (getvar 'CDATE) 2 0))
  (setq months '(
    ("01" . "JAN") ("02" . "FEB") ("03" . "MAR")
    ("04" . "APR") ("05" . "MAY") ("06" . "JUN")
    ("07" . "JUL") ("08" . "AUG") ("09" . "SEP")
    ("10" . "OCT") ("11" . "NOV") ("12" . "DEC")
  ))
  (strcat
    (cdr (assoc (substr date 5 2) months)) " "
    (substr date 7 2) ", "
    (substr date 1 4)
  );strcat
);defun

 

I've also been working on a useful AutoLISP AI bot that can hopefully return better results than normal ChatGPT (though still needs work, couldn't exactly answer your task proficiently). You can access it from this link if you use the paid version of ChatGPT:

https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace 

 

Best,

~DD


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
0 Likes

ronjonp
Advisor
Advisor

@CodeDing FWIW your 'today' function could be simplified to this: 

(menucmd "M=$(edtime, $(getvar,date),MON DD YYYY)")