Edit Attributes

Edit Attributes

vercosa123
Explorer Explorer
903 Views
11 Replies
Message 1 of 12

Edit Attributes

vercosa123
Explorer
Explorer

Considering this code, I would like the Value of \85Tag to be pasted into the value of \76Tag and the Value of \84Tag to be pasted into the value of \75Tag.

(defun C:ListAttributes ()
   (setq baselist (list))      
   (setq ename (car (entsel "\nSelect Block:")))
   
   (while (not ename)
      (princ "\nNothing Picked")
      (setq ename (car (entsel "\nSelect Block:")))
   )

   (if (assoc 66 (setq elist (entget ename)))
       (progn
           (setq ename (entnext ename)
                 elist (entget ename))
           (while (= "ATTRIB" (cdr (assoc 0 elist)))
               (setq tag (cdr (assoc 2 elist))
                     val (cdr (assoc 1 elist)))
               (setq baselist (append (list (list tag val)) baselist))
               (setq ename (entnext ename)
                     elist (entget ename))
           )
           
           (foreach item baselist
               (setq tag (car item)
                     val (cadr item))
               
               (setq new_val (cond
                              ((= tag "\\85") (cdr (assoc "\\76" baselist)))
                              ((= tag "\\84") (cdr (assoc "\\75" baselist)))
                              (t val)
                            ))
               
               (setq target_ent (assoc tag elist))
               (setq elist (subst (cons 1 new_val) target_ent elist))
           )
           
           (entmod elist)
           (princ "\nAttributes rearranged successfully.")
       )
       (princ "\nNo attributes found in the selected block.")
   )
   (princ)
)
0 Likes
904 Views
11 Replies
Replies (11)
Message 2 of 12

komondormrex
Mentor
Mentor

and what is the question? 

0 Likes
Message 3 of 12

vercosa123
Explorer
Explorer

This code isn't working and I don't know why it doesn't work. Would you know any way to do that?

0 Likes
Message 4 of 12

komondormrex
Mentor
Mentor

check this one, untested thou.

updated.

 

 

(defun c:attributes_value_moving ();/  insert_sset target_attributes_list tag)
	(if (setq insert_sset (ssget '((0 . "insert"))))
	  	(foreach insert (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex insert_sset))))
			(setq target_attributes_list nil)
			(if (minusp (vlax-get insert 'hasattributes))
				(progn
			  		(foreach attribute (vlax-invoke insert 'getattributes)
						(if (member (setq tag (vla-get-tagstring attribute)) '("\\85" "\\84" "\\83" "\\76" "\\75" "\\74"))
								(setq target_attributes_list (append target_attributes_list (list (cons tag attribute))))
						)
					)
					(if target_attributes_list 
						(repeat 3
							(cond
								(
									(and (assoc "\\85" target_attributes_list) 
										 (assoc "\\76" target_attributes_list) 
									)
				        				(vla-put-textstring (cdr (assoc "\\76" target_attributes_list)) (vla-get-textstring (cdr (assoc "\\85" target_attributes_list))))
										(setq target_attributes_list (vl-remove (assoc "\\85" target_attributes_list) target_attributes_list)
											  target_attributes_list (vl-remove (assoc "\\76" target_attributes_list) target_attributes_list)
										) 
								)
								(
									(and (assoc "\\84" target_attributes_list) 
										 (assoc "\\75" target_attributes_list) 
									)
				        				(vla-put-textstring (cdr (assoc "\\75" target_attributes_list)) (vla-get-textstring (cdr (assoc "\\84" target_attributes_list))))
										(setq target_attributes_list (vl-remove (assoc "\\84" target_attributes_list) target_attributes_list)
											  target_attributes_list (vl-remove (assoc "\\75" target_attributes_list) target_attributes_list)
										) 
								)
								(
									(and (assoc "\\83" target_attributes_list) 
										 (assoc "\\74" target_attributes_list) 
									)
				        				(vla-put-textstring (cdr (assoc "\\74" target_attributes_list)) (vla-get-textstring (cdr (assoc "\\83" target_attributes_list))))
										(setq target_attributes_list (vl-remove (assoc "\\83" target_attributes_list) target_attributes_list)
											  target_attributes_list (vl-remove (assoc "\\74" target_attributes_list) target_attributes_list)
										) 
								)
								(
									t
								)
							)  
						)
				    )
				)
			)
		)
  	)
  	(princ)
)

 

 

0 Likes
Message 5 of 12

vercosa123
Explorer
Explorer

I think I didn't explain it right. I would like to edit the attribute values ​​of a block that has 85 tags. So that the attribute value 85 is pasted into 76, that 84 is pasted into 75 and that 83 is pasted into 74. To edit manually I double-click on the block that opens the ENHANCED ATTRIBUTE EDITOR window with the list of tags . Would it be possible to create a lisp to automate this?

0 Likes
Message 6 of 12

komondormrex
Mentor
Mentor

you wrote nothing on 74, 83 and what has to become with 8s values. check update.

0 Likes
Message 7 of 12

vercosa123
Explorer
Explorer

The changed code did not work. 

0 Likes
Message 8 of 12

komondormrex
Mentor
Mentor

you'd better post a sample of your block in here.

0 Likes
Message 9 of 12

vercosa123
Explorer
Explorer

Attached is the dwg with the block I want to edit. The position of the tags I want to edit are the same as the list.

0 Likes
Message 10 of 12

komondormrex
Mentor
Mentor

well, there are no attributes with "\8*" and "\7*" tags in a block posted. am i missing something or what do you mean exactly by saying there are?

0 Likes
Message 11 of 12

vercosa123
Explorer
Explorer

in this code I was able to list all the tags and values ​​and save the values ​​in a list but I can't edit the tag values ​​of the multiple attribute block.

(defun C:ListAttributesVariaveis ()
   (setq valores '())
   (setq baselist (list))      
   (setq ename (car (entsel "\nSelect Block:")))
   
   (while (not ename)
      (princ "\nNothing Picked")
      (setq ename (car (entsel "\nSelect Block:")))
   )

   (if (assoc 66 (setq elist (entget ename)))
       (progn
           (setq ename (entnext ename)
                 elist (entget ename))
           (while (= "ATTRIB" (cdr (assoc 0 elist)))
               (setq tag (cdr (assoc 2 elist))
                     val (cdr (assoc 1 elist)))
               (setq baselist (append (list (list tag val)) baselist))
               (setq ename (entnext ename)
                     elist (entget ename))
           )
           
           (foreach item baselist
               (setq tag (car item)
                     val (cadr item))
               (princ (strcat "\nTag: " tag " - Value: " val))
               
               (setq valores (cons val valores))
           )

           (if (>= (length valores) 4)
               (progn
                   (setq V85 (nth 84 valores))
                   (setq V84 (nth 83 valores))

                   (princ (strcat "\nV85: " V85))
                   (princ (strcat "\nV84: " V84))
               )
           )
       )
       (princ "\nNo attributes found in the selected block.")
   )
   (princ)
)
0 Likes
Message 12 of 12

vercosa123
Explorer
Explorer

the tags have the same names in some attributes, so I thought of using the position in the list where they appear.

0 Likes