Lisp

Lisp

Anonymous
Not applicable
1,372 Views
8 Replies
Message 1 of 9

Lisp

Anonymous
Not applicable
This lisp just modifies one title block in a drawing with multiple layouts. Could it be fixed to modify all title blocks in all layouts? (defun fix_title ( / ss blk atts tagname value ) ; place data into title block (vl-load-com) (setq ss nil) (setq ss (ssget "X" (list (cons 2 "STAMP")))) (if ss (progn (setq blk (vlax-ename->vla-object (ssname ss 0))) (if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk)))) (progn (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk)))) (foreach att atts (setq tagname (strcase (vla-get-tagstring att))); tagname (setq value (vla-get-textstring att)); value (if (= tagname "DATE")(vla-put-textstring att "2016")) ); foreach ); progn ); if (command "_regen") ); progn ); if ); function (princ) ;(Fix_Title)
0 Likes
Accepted solutions (1)
1,373 Views
8 Replies
Replies (8)
Message 2 of 9

john.uhden
Mentor
Mentor
Your code is acting only on one entity, the first one in the selection set (ssname ss 0). You should act on ALL of the items in the selection set, as in...
(setq i 0) ; index
(while (< i (sslength ss)
(setq blk (vlax-ename->vla-object (ssname ss i)))
;; Take your action
(setq i (1+ i)) ; increment the index
) ; end while

John F. Uhden

0 Likes
Message 3 of 9

Anonymous
Not applicable
Thanks! Sorry, can not get it work! Would you place these lines for me in the routine: (defun fix_title ( / ss blk atts tagname value ) ; place data into title block (vl-load-com) (setq ss nil) (setq ss (ssget "X" (list (cons 2 "NAMN PÅ DITT BLOCK")))) (if ss (progn (setq blk (vlax-ename->vla-object (ssname ss 0))) (if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk)))) (progn (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk)))) (foreach att atts (setq tagname (strcase (vla-get-tagstring att))); tagname (setq value (vla-get-textstring att)); value (if (= tagname "TAG I DITT BLOCK")(vla-put-textstring att "DITT VÄRDE")) ); foreach ); progn ); if (command "_regen") ); progn ); if ); function (princ) (fix_title)
0 Likes
Message 4 of 9

john.uhden
Mentor
Mentor
Accepted solution
(defun fix_title ( / ss i blk atts tagname value )
   ; place data into title block
   (vl-load-com)
   ;; (setq ss nil) DELETE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
   (setq ss (ssget "X" (list (cons 2 "NAMN PÅ DITT BLOCK"))))
   (if ss
     (progn
       (setq i 0) ;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       (while (< i (sslength ss)) ;;<<<<<<<<<<<<<<<<<<<<
         (setq blk (vlax-ename->vla-object (ssname ss 0)))
         (if (safearray-value (setq atts (vlax-variant-value (vla-getattributes blk))))
           (progn
             (setq atts (vlax-safearray->list (vlax-variant-value (vla-getattributes blk))))
             (foreach att atts
               (setq tagname (strcase (vla-get-tagstring att))) ; tagname
               (setq value (vla-get-textstring att)); value
               (if (= tagname "TAG I DITT BLOCK")
                 (vla-put-textstring att "DITT VÄRDE")
               )
             ); foreach
           ); progn
         ); if
         (setq i (1+ i)) ;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       ) ; while  ;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       (command "_regen")
     ); progn
   ); if
   (princ)
); function
(princ)
(fix_title)

In the future, please do not use the Quick Reply.  The regular Reply shows an icon in the menu ribbon to "Post Code" which is the only way to preserve indentation.  I had to copy, paste, and reformat your routine to make it legible (with indentation).  I hope this works for you.

John F. Uhden

Message 5 of 9

Anonymous
Not applicable
Thanks a lot! Bcount tells me there are more then one titleblock but the routine still fix just the first instance of that block! I do not get any error massages! Best regards A
0 Likes
Message 6 of 9

john.uhden
Mentor
Mentor
Then add a line after (ssget ...)
(princ (strcat "\nFound " (itoa (sslength ss)) " insertions."))

Maybe you just didn't see the others, maybe because they are in other layouts?

John F. Uhden

0 Likes
Message 7 of 9

Anonymous
Not applicable
Yes, there are several layouts each with a titleblock. But this lisp just handles the first layout! The routine now just tells me how many instances there are but handles just first layout! BR Akmah
0 Likes
Message 8 of 9

john.uhden
Mentor
Mentor
My mistake. That should be i not 0...
(setq blk (vlax-ename->vla-object (ssname ss i)))

John F. Uhden

0 Likes
Message 9 of 9

Anonymous
Not applicable
Thanks a lot! Now it runs perfectly! BR
0 Likes