Copy Attribute definition default Value to an other Attribute definition default value

Copy Attribute definition default Value to an other Attribute definition default value

Hans_Knol
Advocate Advocate
511 Views
9 Replies
Message 1 of 10

Copy Attribute definition default Value to an other Attribute definition default value

Hans_Knol
Advocate
Advocate

Hi All,

 

I have a Lisp file (attached) that is be able to copy a default value from an attribute definition to an other default value. But because I must change a lot of blocks, I like to have a routine that is be able to do it automaticly for me. I copy into a existing drawing a default block and move the right attributes to the right locations, after that the new tool must make a selection (by Window) from all the extisting attributen definitions, copy the default values and the user must select the second window, so the tool can place all the default values to the right attribute definitions.

 

Old tool (one by one)

(defun c:CopyAttDefDefaultValue ()
(setq ent1 (car (entsel "Select first Attribute Definition: ")))
(if (and ent1 (eq (cdr (assoc 0 (entget ent1))) "ATTDEF"))
(progn
(setq ent1Data (entget ent1))
(setq tagName (cdr (assoc 2 ent1Data)))
(setq defaultVal (cdr (assoc 1 ent1Data)))
(setq ent2 (car (entsel "Select second Attribute Definition: ")))
(if (and ent2 (eq (cdr (assoc 0 (entget ent2))) "ATTDEF"))
(progn
(setq ent2Data (entget ent2))
(if (equal tagName (cdr (assoc 2 ent2Data)))
(progn
(setq ent2Data (subst (cons 1 defaultVal) (assoc 1 ent2Data) ent2Data))
(entmod ent2Data)
(princ "\nDefault Value copied."))
(princ "\nDe Attribute Definitions has not the same tagname.")))
(princ "\nNo second Attribute Definition selected.")))
(princ "\nNo first Attribute Definition selected."))
(princ))

 

Hans Knol
0 Likes
Accepted solutions (1)
512 Views
9 Replies
Replies (9)
Message 2 of 10

komondormrex
Mentor
Mentor

@Hans_Knol 

hey,

are these intend to be same name blocks with same tags attributes?

0 Likes
Message 3 of 10

Hans_Knol
Advocate
Advocate
Hi, the Attribute definitions in both selections are the same, it just must change add the right default values. I must change a lot of blocks before they will be used, so it are just drawings (exploded blocks)
I will copy a new standard to the existing and want to update the new with the old info.
Hans Knol
0 Likes
Message 4 of 10

Moshe-A
Mentor
Mentor

@Hans_Knol  hi,

 

we are talking on attributes definition (ATTDEF) - yes?

i do not understand the logic in doing that, cause if you are talking about existing blocks, how do you plan to populate these new values? with attsync? are you sure it update attribute values?!

only if you insert a new instance of the block the default values will appear.

am i wrong here?

 

or you are using ATTDEF instead of MTEXT\TEXT?

 

Moshe

 

0 Likes
Message 5 of 10

paullimapa
Mentor
Mentor

Could you share a dwg showing these 2 groups of attribute definitions perhaps one group on right that you want to retrieve the default values to place onto the group on the left?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 10

Sea-Haven
Mentor
Mentor

I recently did this pick a block and dcl pops up with the tagnames and a blank value, you fill in what ever values you want and can then apply to all blocks.

 

This is one version it updates title blocks in layouts, can be changed to update selected blocks. Replace the foreach with a loop of a selection.

 

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/is-there-a-gatte-equivalent-for-lt2025/td-p/13344776/page/2

; update a block atts in multiple layouts
; By AlanH March 2025

(defun c:upatts ( / ans atts bent bname lay lst lst2 obj ss x)

(setq obj (vlax-ename->vla-object (car (entsel "\nPick block object "))))
(setq bname (vlax-get obj 'name))
(setq atts (vlax-invoke obj 'Getattributes))

(setq lst '())
(foreach att atts
  (setq lst (cons (vlax-get att 'Tagstring) lst))
)
(setq lst2 '())
(foreach val lst
  (setq lst2 (cons "" lst2))
  (setq lst2 (cons 20 lst2))
  (setq lst2 (cons 21 lst2))
  (setq lst2 (cons val lst2))
)
(setq lst2 (cons "Please choose " lst2))

(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq ans (AH:getvalsm lst2))

(foreach lay (layoutlist)
(setq ss (ssget "X" (list (cons 0 "INSERT")(cons 2 bname)(cons 410 lay))))
(setq x 0)
(setq bent (vlax-ename->vla-object (ssname ss 0)))
(setq atts (vlax-invoke bent 'Getattributes))
(repeat (length atts)
  (if (= (nth x ans) "")
  (princ)
  (vlax-put (nth x atts) 'textstring (nth x ans))
  )
  (setq x (1+ x))
)
)

(princ)
)

 

 

 

0 Likes
Message 7 of 10

Hans_Knol
Advocate
Advocate

I must work in a drawing like attached and change the attribute vallues from the old to the new. Hope this helps

Hans Knol
0 Likes
Message 8 of 10

Hans_Knol
Advocate
Advocate

Hi Moshe,

yes we tals about Attribute definitions and I must copy the default values from the old to the new. after we have done this we remove the old ond and set the new insertionpoint and we can use the new block, see attached file

Hans Knol
0 Likes
Message 9 of 10

Moshe-A
Mentor
Mentor
Accepted solution

@Hans_Knol ,

 

check this

 

 

(defun c:cpyattdef (/ ss0 ss1 ename0 ename1 elist0 elist1)

 (if (and
       (not (prompt "\nSelect source attdef..."))
       (setq ss0 (ssget '((0 . "attdef"))))
       (not (prompt "\nSelect target attdef..."))
       (setq ss1 (ssget '((0 . "attdef"))))
     )
  (foreach ename0 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0)))
   (setq elist0 (entget ename0)) 
   (foreach ename1 (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss1)))
    (setq elist1 (entget ename1))

    (if (eq (strcase (cdr (assoc '2 elist0))) (strcase (cdr (assoc '2 elist1))))
     (progn
      (if (and (assoc '1 elist0) (assoc '1 elist1))
       (setq elist1 (subst (cons '1 (cdr (assoc '1 elist0))) (assoc '1 elist1) elist1))
      )

      (if (and (assoc '3 elist0) (assoc '3 elist1))
       (setq elist1 (subst (cons '3 (cdr (assoc '3 elist0))) (assoc '3 elist1) elist1)) 
      )

      (entmod elist1)
     ); progn
    ); if
   ); foreach
  ); foreach
 ); if

 (princ)
); c:cpyattdef

 

 

0 Likes
Message 10 of 10

Hans_Knol
Advocate
Advocate

That works fine, thanks Moshe!

Hans Knol
0 Likes