• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

replace default attribute value with value inserted in the block

  • Thread starter Thread starter 77marco77
  • Start date Start date

77marco77

Guest
Good morning.
in a drawing (which is used as a source of blocks for new designs) with over 6000 blocks I would like to replace the default value of the attribute tag with the already inserted value manually in the block.

I found this code of lee mac:
Code:
;; lee-mac - 2017
(defun c:defatt ( / bln def tag )
   (if (= "" (setq bln (strcase (getstring t "\nspecify block name filter (use * for all) <*>: "))))
       (setq bln "*")
   )
   (if (= "" (setq tag (strcase (getstring "\nspecify tag name filter (use * for all) <*>: "))))
       (setq tag "*")
   )
   (setq def (getstring t "\nspecify new default value: "))
   (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
       (if (and (= :vlax-false (vla-get-islayout blk) (vla-get-isxref blk)) (wcmatch (strcase (vla-get-name blk)) bln))
           (vlax-for obj blk
               (if (and (= "acdbattributedefinition" (vla-get-objectname obj))
                        (wcmatch (strcase (vla-get-tagstring obj)) tag)
                        (vlax-write-enabled-p obj)
                   )
                   (vla-put-textstring obj def)
               )
           )
       )
   )
   (princ)
)
(vl-load-com) (princ)
that does what I need but I have to enter the block name (I cannot select), the tag name and the new default value of the tag, but they are many blocks and each has between 12 and 20 attributes.. .
is it possible faster to make the block selection (or multiple blocks), the attribute (or multiple attributes), which reads the value already inserted and let it enter as a new default?
 
It is not the maximum, you have to select a block at a time, but a little speeds (I hope they are not 6000 blocks all with different names!). you have to click once on the block and once on the attribute.
Code:
(refun c:defatt2 ()
(setq blk (vlax-ename->vla object (car (entsel "\nselezionire blockco: ")))
tag
blk (fla-get-blocks (vla-get-active document (vla-get-acad object)))
)
(vlax-for elem blk
(if (and (= fla-get-objectname elem) "addbattributeddefinition")
(= bla-get-tagstring elem) (vla-get-tagstring tag)
)
(fla-put-textstring elem (fla-get-textstring tag))
)
)
)
 
It is not the maximum, you have to select a block at a time, but a little speeds (I hope they are not 6000 blocks all with different names!). you have to click once on the block and once on the attribute.
Code:
(refun c:defatt2 ()
(setq blk (vlax-ename->vla object (car (entsel "\nselezionire blockco: ")))
tag
blk (fla-get-blocks (vla-get-active document (vla-get-acad object)))
)
(vlax-for elem blk
(if (and (= fla-get-objectname elem) "addbattributeddefinition")
(= bla-get-tagstring elem) (vla-get-tagstring tag)
)
(fla-put-textstring elem (fla-get-textstring tag))
)
)
)
thank you so much now I will certainly be faster, unfortunately they are really 6358 blocks (all with different names...) and each with 12 up to 20 attributes ( fortunately I have to update only 4 or 5) but at least now I have the cable only by clicking instead of having to write :).
Thank you again! !
 
It is not the maximum, you have to select a block at a time, but a little speeds (I hope they are not 6000 blocks all with different names!). you have to click once on the block and once on the attribute.
Code:
(refun c:defatt2 ()
(setq blk (vlax-ename->vla object (car (entsel "\nselezionire blockco: ")))
tag
blk (fla-get-blocks (vla-get-active document (vla-get-acad object)))
)
(vlax-for elem blk
(if (and (= fla-get-objectname elem) "addbattributeddefinition")
(= bla-get-tagstring elem) (vla-get-tagstring tag)
)
(fla-put-textstring elem (fla-get-textstring tag))
)
)
)
I started doing about 56,000 clicks + enter, but the finger already stopped working. . .
if it is not too complicated do you think that you can add in the code the instructions so that the command is again launched and automatically selected the previously selected block? this would allow me to choose the block the first time to simply click in succession the only attributes to update, when finished I press esc and I relaunch it for the next block (they would become 28,000 clicks and without using the keyboard to re-enter the command for each attribute).
thanks in any case :)
 
so it should go. the program will ask you attributes until you press <enter>.
</enter>
Code:
(defun c:defatt3()
(setq blk (vlax-ename->vla-object (car (entsel "\nselezionare blocco:")))
(vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))
Listed "()
)
(while (setq tag (announcement)
(if taken
(progn
(setq tag (vlax-ename->vla-object))
(Setq listed)
)
)
)
(setq listed)
(Foreach Elem1 listed)
(vlax-for elem blk
(if (and = (vla-get-objectname elem) "acdbattributedefinition")
((vla-get-tagstring elem) (vla-get-tagstring elem1))
)
(vla-put-textstring elem (vla-get-textstring elem1))
)
)
)
)
 
Very good. But the sacker is the sacker. not the one you find in Italy in supermarkets. You have to eat there, it's all another planet. It's like comparing Parmesan
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top