LISP to update attribute field with current date

LISP to update attribute field with current date

pete592
Advocate Advocate
626 Views
3 Replies
Message 1 of 4

LISP to update attribute field with current date

pete592
Advocate
Advocate

I am still very new to LISP but I am attempting to deliver a program that will:

 

  1. Prompt the user to select either one (not not both) of the attribute blocks in the attached drawing file.
  2. Prompt the user to choose to update the DESNDATE field, the DRAWDATE field, or both.
  3. Update the chosen fields with the current date in MM/DD/YY  format.   

Quite literally, the only portion I have had success with is using the print function to prompt the user, and ssget for selecting the block.  But I am going in circles trying to figure out the rest.

 

I found the Attribute Functions on @Lee_Mac 's website, which from what I have seen are quite popular for this purpose, but after endless trial and error, I remained confused as to exactly which parts of the code I need to replace/update to fit my particular needs. 

 

;; Set Attribute Values  -  Lee Mac
;; Sets attributes with tags found in the association list to their associated values.
;; blk - [ent] Block (Insert) Entity Name
;; lst - [lst] Association list of ((<tag> . <value>) ... )
;; Returns: nil

(defun LM:setattributevalues ( blk lst / enx itm )
    (if (and (setq blk (entnext blk)) (= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk))))))
        (if (setq itm (assoc (cdr (assoc 2 enx)) lst))
            (progn
                (if (entmod (subst (cons 1 (cdr itm)) (assoc 1 (reverse enx)) enx))
                    (entupd blk)
                )
                (LM:setattributevalues blk lst)
            )
            (LM:setattributevalues blk lst)
        )
    )
)

 

I know it's a huge ask and frankly I wouldn't blame you if you'd rather I tough this out pouring over references for the learning experience, but I have users who would really appreciate having this functionality right now.

Kindest Regards and Deepest Gratitude,

Pete

0 Likes
Accepted solutions (1)
627 Views
3 Replies
Replies (3)
Message 2 of 4

ronjonp
Mentor
Mentor
Accepted solution

@pete592 

Give this a try:

 

(defun c:foo (/ d s)
  (setq d (menucmd "M=$(edtime, $(getvar,date),MO/DD/YY)"))
  (if (setq s (ssget ":L" '((0 . "INSERT") (66 . 1))))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
      (foreach tag '("DESNDATE" "DRAWDATE") (vl-catch-all-apply 'setpropertyvalue (list e tag d)))
    )
  )
  (princ)
)

 

Message 3 of 4

pete592
Advocate
Advocate

Thank you so much!  I'm going to dive into what you did and learn from this!

I had a feeling this could be done with only a few lines of code and you did not disappoint!

 

My coworkers and I thank you again.  🙂

 

0 Likes
Message 4 of 4

ronjonp
Mentor
Mentor

@pete592 wrote:

Thank you so much!  I'm going to dive into what you did and learn from this!

I had a feeling this could be done with only a few lines of code and you did not disappoint!

 

My coworkers and I thank you again.  🙂

 


@pete592  Glad to help. *cheers*

0 Likes