Jump to content

Recommended Posts

Posted

I’m in the process of updating nearly 400 blocks. I have to change the layer and override the color of one attribute. My test on the first block failed. It's just been a while and I can't remember what I'm missing.

 

My attempt for changing the first one:

(progn
(setq e (car (entsel ))
 d (entget e)
 n_e (entnext e)
 n_d (entget n_e)))
 un_d (subst (cons 8 "SYM") (assoc 8 n_d) n_d)
 un_d (append un_d (list un_d (cons 62 141)))
)
(entmod un_d)
(entupd (cdr (assoc 330 un_d)))
)

 

I've also tried:

(command "_.attsync" "_select" n_e "" )"_Yes")

 

note: as I step through the block entities I will be testing to insure I've got the right block with:

(and 
(= (cdr (assoc 0 n_d)) "ATTRIB")
(= (cdr (assoc 2 n_d)) "SIZE")
(/= (cdr (assoc 8 n_d)) "SYM")
)

Posted

If you only want to change 1 block using name no matter where the block is maybe use block edit, BEDIT this will update all.

 

I would use VL code its a bit easier using get & put to change stuff.

 

You should post a dwg with this block.

  • Like 1
Posted

I'm getting closer to what I need with the code below. If I double click on the block, the attribute layer has been updated. But when I check the block defination it remains unchanged.

 

The commented out attsyncs didn't resolve the issue.

 

(progn
(defun get_ents ( ss / ents ss1 l cnt)
 (setq ents (list )
  ss1 ss
  l (sslength ss1)
  cnt  0
 )
 (while (< cnt l)
  (setq ent (ssname ss1 cnt)
   ents (append ents (list ent))
    cnt (1+ cnt)
  )
 )
 ents
)
(setq ss01 (ssget "x" (list (cons 0 "INSERT")))
 ents (get_ents ss01)
)
(foreach line ents
 (setq head_e line
  head_d (entget head_e)
  name (cdr (assoc 2 head_d))
 )
 (if (cdr (assoc 66 head_d))
  (progn
   (setq e (entnext head_e)
    d (entget e)
   )
   (if (and
     (= (cdr (assoc 0 d)) "ATTRIB")
     (= (cdr (assoc 2 d)) "SIZE")
     (/= (cdr (assoc 8 d)) "SYM")
    )
    (progn
     (setq d (subst (cons 8 "SYM")(assoc 8 d) d))
     (entmod d)
     (entupd (cdr (assoc 330 d)))
     (entupd (cdr (last (tblsearch "block" name))))
     ;(command "_attsync" "S" (cdr (last (tblsearch "block" name))) "Y")
     ;(command "_attsync" "S" head_e "Y")
    )
   )
  )
 )
)
)

Posted

BIGAL,

 

I don't have a lot of ex with VL. I have about 400 different blocks that each need to have the same update, so I'm not sure that bedit will work here. But I'll look into it.

 

Thank you.

 

--

I attached a file with three of the blocks that I need to update.

demo.dwg

Posted

Try the following:

(defun c:fixatts ( / d e i s x )
   (while (setq d (tblnext "block" (null d)))
       (if (= 2 (logand 2 (cdr (assoc 70 d))))
           (progn
               (setq e (tblobjname "block" (cdr (assoc 2 d))))
               (while (setq e (entnext e))
                   (if (and (setq x (entget e))
                            (= "ATTDEF" (cdr (assoc 0 x)))
                            (= "SIZE"   (cdr (assoc 2 x)))
                       )
                       (entmod (cons (cons -1 e) '((8 . "SYM") (62 . 141))))
                   )
               )
           )
       )
   )
   (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1))))
       (repeat (setq i (sslength s))
           (setq e (entnext (ssname s (setq i (1- i))))
                 x (entget e)
           )
           (while (= "ATTRIB" (cdr (assoc 0 x)))
               (if (= "SIZE"  (cdr (assoc 2 x)))
                   (entmod (cons (cons -1 e) '((8 . "SYM") (62 . 141))))
               )
               (setq e (entnext e)
                     x (entget  e)
               )
           )
       )
   )
   (princ)
)

The second half of the code could be replaced by a call to ATTSYNC, but bear in mind that such a call would cause the properties of all attributes to revert to those defined in the block definition, which may be undesirable.

  • Like 2
Posted

Brilliant!! Doeseverything I need!

Thank you Sir, you’re awesome!

  • 6 years later...
Posted

Thank's a lot for that code you save me from a lot of pain.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...