Block Replace not working

Block Replace not working

Joe.Gio
Advocate Advocate
710 Views
1 Reply
Message 1 of 2

Block Replace not working

Joe.Gio
Advocate
Advocate

Hi All,

 

I have a lisp that use to work but it's now not doing anything. It use to replace our old border with the new one then run 'ATTSYNC' to update the attributes. Since then our borders have changed and the location. I thought I had update them all correctly but now I get the following issue:

 

Specify sheet to redefine [A0/A1/A2/A3/A3P/A4/A4P] <all>:
_.-INSERT Enter block name or [?]: A3 Drawing Sheet=C:\CAD\A3 Drawing Sheet.dwg Block A3 Drawing Sheet references itself
Regenerating layout.
Regenerating model.
*Invalid*
; error: Function cancelled

 

The old and new borders have the same block name and the new border is saved as a WBLOCK. No idea what is causing the issue myself. The only difference is that we use to be on Windows 7 and now Windows 10 but I doubt that would be causing this issue. Does anyone have an idea?

 

Thanks,

 

Joe

 

(defun c:TitleBlockRedefine ( / path blks key name)
  
  (setq path "C:\\CAD\\" 	;; see double backslash 
        blks '(("A4" . "A4 Drawing Sheet") 		;; file name == block name !!!
               ("A4P" . "A4P Drawing Sheet")
	       ("A3P" . "A3P Drawing Sheet")
	       ("A3" . "A3 Drawing Sheet")
               ("A2" . "A2 Drawing Sheet")
               ("A1" . "A1 Drawing Sheet")
               ("A0" . "A0 Drawing Sheet")
               ))
  
  (initget "A0 A1 A2 A3 A3P A4 A4P")					;; list off all numbers to be selected
  (if (setq key (getkword "\nSpecify sheet to redefine [A0/A1/A2/A3/A3P/A4/A4P] <all>: "))    ; selection by numbers
    (setq blks (list (assoc key blks))))
  (foreach e blks
    (setq name (cdr e))
    (if (setq ss (ssget "_X" (list '(0 . "INSERT"))))
      (repeat (setq i (sslength ss))
        (if (/= (strcase (vla-get-effectivename (vlax-ename->vla-object (setq ent (ssname ss (setq i (1- i)))))))
                (strcase name))
          (ssdel ent ss))))
    (if (and ss
             (> (sslength ss) 0))
      (progn
        (command "_.-INSERT" (strcat name "=" path name ".dwg"))
        (command)
        (command "_.ATTSYNC" "_Name" name))))
  (princ)
  )

 

0 Likes
711 Views
1 Reply
Reply (1)
Message 2 of 2

Joe.Gio
Advocate
Advocate

Ok looks like it was the way I was creating the WBLOCK using the entire drawing rather than just the Block I wanted. Looks like it works now. I'd like to add the following code into it though to rename tags before it replaces the block rather than having to run the 2 lisps. Does anyone know the best way to merge them? I've tried a few things but nothing seems to work.

Thanks.

(defun c:attr_rename_list (  / x_en enn edd ss slen ix atnam 
          namelist hit blk_ent
          matchname newed x) 
 ; Process all block instances on active drawing. Check each 
 ; attribute for match on first element in list below. On any
 ; match, rename the attribute to the new name given in the
 ; second element. 

 ; ***********   ATTRIBUTE OLD versus NEW names list   ******************
 (setq namelist (list
     ; list old name and new name. Old name can contain wild cards.
     (list "REVD1" "CHK1")  ; list old name and new name. 
     (list "REVD2" "CHK2")
     (list "REVD3" "CHK3")
     (list "REVD4" "CHK4")
     (list "REVD5" "CHK5")
     (list "REVD6" "CHK6")
     (list "REVD7" "CHK7")
 ) )  
 ; **********************************************************************

 ; Extract selection set of all block inserts on active drawing  
 (setq ss (ssget "_X" '((0 . "INSERT"))))
 (if (/= ss nil)
   (progn
     (setq slen (sslength ss))
     (setq ix 0)
     (while (< ix slen)
       (setq blk_ent (ssname ss ix)) ; get next block insert to process        
       (setq ix (1+ ix)) ; increment for next time
       (setq enn (entnext blk_ent)) 
       (setq edd (entget enn))  
       (while (AND enn (/= (cdr (assoc 0 edd)) "SEQEND") 
                           (/= (cdr (assoc 0 edd)) "INSERT") )
         (if (= (cdr (assoc 0 edd)) "ATTRIB")
           (progn
             (setq atnam (cdr (assoc 2 edd)))
             (setq hit nil)
             (foreach x namelist
               (if (not hit)
                 (progn ; no match yet, keep processing
                   (setq matchname (car x))                
                   (if (wcmatch atnam matchname) 
                     (progn ; found exact match or wild-card match
                       ; Change name now. Substitute in new name.
                       (setq newed (subst (cons 2 (cadr x)) (assoc 2 edd) edd)) 
                       (entmod newed) ; update the title block instance
                       (entupd blk_ent) 
                       (princ "\n")
                       (princ atnam)
                       (princ " --> ")
                       (princ (cadr x))
                       (setq hit 1) ; flag that found
               ) ) ) )
             )
           )
         )     
         ; go to next sub ent in block instance and loop back up
         (if (setq enn (entnext enn)) (setq edd (entget enn))) 
     ) ) 
     (setq ss nil) ; release the selection set
   )
 )
 (princ) ; prettier
)
0 Likes