- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've come across a few posts discussing this topic but can't seem to find a solution for when you're running a LISP routine in the script. It's a very basic script, opens a file, runs the LISP routine, saves and closes. The LISP routine was created to swap out attribute values in our drawings for updating part numbers. The script and LISP routine work fine as is (when I hard code the attribute values anyway), but I was hoping to allow the user to enter the old and new attribute values rather than edit the LISP routine every time. Here's the LISP routine with my attempt at getting a user input:
;
; A LISP routine to replace an old part number attribute with a new part number
; This is intended to be used with a script for mass changes
;
(defun c:ReplaceParts ()
; Part Numbers
(if (or (= (vl-bb-ref 'OLDPART) nil) (= (vl-bb-ref 'NEWPART) nil))
(progn
(vl-bb-set 'OLDPART (getstring nil "Enter the old part number: "))
(vl-bb-set 'NEWPART (getstring nil "Enter the new part number: "))
)
)
; Attributes
(SETQ attblock "ATT") ; keep this line in here, needed for the attribute extract
(SETQ attnm "ITEM") ; keep this line in here
; Verify Attribute Exists
(setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 attblock))))
(setq i 0) ; was 0
(IF (/= ss nil)(PROGN ; if there is a selection set
(setq n_ent (sslength ss)) ; then set n_ent = length of selection set
(wHILE (< i n_ent)
(setq en (SSNAME ss i)) ;- Get the entity name of the block
(setq enlist (entget en)) ;- Get the DXF group codes
(if(= (cdr(assoc 66 enlist)) 1)(PROGN ;- See if the attribute flag equals one (if so, attributes follow)
(setq en2(entnext en)) ;- Get the next sub-entity
(setq enlist2(entget en2)) ;- Get the DXF group codes
(IF (/= (assoc 1 enlist2) NIL)(SETQ ATTITEM (cdr (assoc 1 enlist2))))
(while (/= (cdr(assoc 0 enlist2)) "SEQEND") ;- Start the while loop and keep
(setq en2 (entnext en2)) ;- Get the next sub-entity
(setq enlist2 (entget en2)) ;- Get the DXF group codes
) ; end while
)) ; end prog
(if (= ATTITEM (vl-bb-ref 'OLDPART))
(COMMAND "ATTEDIT" "N" "N" attblock attnm "*" (vl-bb-ref 'OLDPART) (vl-bb-ref 'NEWPART))
)
(setq i (+ 1 i)) ; up the counter
)
))
; Attributes
(SETQ attblock "ITEM") ; keep this line in here, needed for the attribute extract
(SETQ attnm "PART") ; keep this line in here
; Verify Attribute Exists
(setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 attblock))))
(setq i 0) ; was 0
(IF (/= ss nil)(PROGN ; if there is a selection set
(setq n_ent (sslength ss)) ; then set n_ent = length of selection set
(wHILE (< i n_ent)
(setq en (SSNAME ss i)) ;- Get the entity name of the block
(setq enlist (entget en)) ;- Get the DXF group codes
(if(= (cdr(assoc 66 enlist)) 1)(PROGN ;- See if the attribute flag equals one (if so, attributes follow)
(setq en2(entnext en)) ;- Get the next sub-entity
(setq enlist2(entget en2)) ;- Get the DXF group codes
(IF (/= (assoc 1 enlist2) NIL)(SETQ ATTITEM (cdr (assoc 1 enlist2))))
(while (/= (cdr(assoc 0 enlist2)) "SEQEND") ;- Start the while loop and keep
(setq en2 (entnext en2)) ;- Get the next sub-entity
(setq enlist2 (entget en2)) ;- Get the DXF group codes
) ; end while
)) ; end prog
(if (= ATTITEM (vl-bb-ref 'OLDPART))
(COMMAND "ATTEDIT" "N" "N" attblock attnm "*" (vl-bb-ref 'OLDPART) (vl-bb-ref 'NEWPART))
)
(setq i (+ 1 i)) ; up the counter
)
))
)
I should also add, this version of the LISP routine works as intended outside of the script, but within the script it just opens and closes the drawings without doing anything. Is this possible or should I just go back to hard coding the values?
Solved! Go to Solution.