Jump to content

Adding block attributes from one to another while keeping the same Geometry


Recommended Posts

Posted

Dear All,

 

After spending a lot of time in different groups, i am starting a new tread hoping i will get a solution, actually i have hundreds of blocks without block attributes, however i have the blocks defined already from another project with different block names, now all i want to do is to add the block attributes to the blocks from the defined blocks, however i want to keep the geometry, insertion point and the X,Y,Z values same as original, since i have so many drawings to revise and so many different blocks to be updated, i am looking for some lisp of script so it can be done quickly, any help in this regard will highly appreciated. 

 

Please find attached CAD file containing both the blocks.

Block attributes to be added.dwg

Posted

It can be done, but would have several limitations

 

The base engine could look like this

(defun c:att-snag (/ sn sd sp an ad sl ss i tn td tp
                     a10 a11 n10 n11)

  (while (not sn)
         (and (princ "\nSelect 1 SOURCE Insert...")
              (setq ss (ssget '((0 . "INSERT")(66 . 1))))
              (= (sslength ss) 1)
              (setq sn (ssname ss 0)
                    sd (entget sn)
                    sp (cdr (assoc 10 sd))
                    an (entnext sn)
                    ad (entget an))))

  (while (= "ATTRIB" (cdr (assoc 0 ad)))
         (setq sl (cons ad sl)
               an (entnext an)
               ad (entget an)))

  (and (princ "\nSelect TARGET Inserts...")
       (setq ss (ssget '((0 . "INSERT")(66 . 0))))
       (setq i 0)
       (while (setq tn (ssname ss i))
              (setq td (entget tn)
                    tp (cdr (assoc 10 td)))
              (setq td (append td (list (cons 66 1))))
              (entmake td)
              (foreach a (reverse sl)
                (setq a10 (mapcar '- (cdr (assoc 10 a)) sp))
                (setq n10 (mapcar '+ tp a10))
                (setq a11 (mapcar '- (cdr (assoc 11 a)) sp))
                (setq n11 (mapcar '+ tp a11))
                (setq a (subst (cons 10 n10) (assoc 10 a) a))
                (setq a (subst (cons 11 n11) (assoc 11 a) a))
                (entmake a))
              (entmake (list (cons 0 "SEQEND")(cons 8 "0")))
              (entdel tn)
              (redraw (entlast))
              (setq i (1+ i))))
  (prin1))

 

This simply adds the source ATTRIButes to the the target INSERT

 

It does not:

  • Redefine the target BLOCK definition
  • Deal with source INSERT rotations, scale, OCS
  • Erase the ATTRIBute value ( it copies the source ATTRIBute values )
  • Retain the ATTRIBute prompt

It does:

  • Match the ATTRIB offset from the source insert point to the attribute

I'm sure there are several more quirks that you may have to deal with.

 

-David

 

Posted (edited)

Here's a bit different approach using the COPY command and referencing the sources geometry.

(defun c:att-snac (/ sn ss sd sp tn td tp ss i ed)
  (while (not sn)
         (and (princ "\nSelect 1 SOURCE Insert...")
              (setq ss (ssget '((0 . "INSERT")(66 . 1))))
              (= (sslength ss) 1)
              (setq sn (ssname ss 0)
                    sd (entget sn)
                    sp (cdr (assoc 10 sd)))))

  (and (princ "\nSelect TARGET Inserts...")
       (setq ss (ssget '((0 . "INSERT")(66 . 0))))
       (setq i 0)
       (while (setq tn (ssname ss i))
              (setq td (entget tn)
                    tp (cdr (assoc 10 td)))
              (command "_.COPY" sn "" sp tp)
              (setq ed (entget (entlast)))
              (entmod (subst (assoc 2 td) (assoc 2 sd) ed))
              (entdel tn)
              (redraw (entlast))
              (setq i (1+ i))))
  (prin1))
Edited by David Bethel
  • Thanks 1
Posted

Thanks David for your support,

Actually it works but as you said with some limitations, one of them is that, it changes the Scale, (X,Y) values, then it copies the attributes, however i cant see them in the block editor and even in the Battman i can't see that block in the list. and more thing can we rename the block as source and then delete the source as well?

 

 

Posted

Glad it worked some.  It is no surprise block editors and Battman do not work as I did not modify the target's block table definition.  The copy routine

should deal with the scale and rotations.  Rename is fraught with issues.  You could simple add the source INSERT to the selection set

 

-David

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...