Solved! Go to Solution.
Solved by alanjt_. Go to Solution.
Quick and dirty...
(defun c:copypasteattribattribbytag ( / att tag str blk a ) (vl-load-com) (setq att (car (nentsel "\nPick attribute..."))) (setq tag (vla-get-tagstring (vlax-ename->vla-object att))) (setq str (vla-get-textstring (vlax-ename->vla-object att))) (while (setq blk (car (entsel "\nPick block to paste attribute value to - ENTER TO FINISH..."))) (setq a blk) (while (= (cdr (assoc 0 (entget (setq a (entnext a))))) "ATTRIB") (if (= (strcase tag) (strcase (vla-get-tagstring (vlax-ename->vla-object a)))) (vla-put-textstring (vlax-ename->vla-object a) str) ) ) ) (princ) )
M.R.
Hi Marko,
Thanks again for the quick reply. I gave the lisp a try and I works based on the rough description I gave you however I had a fellow coworker tweak the code for me a bit to make it work more for what I was looking for. Only issue I'm running into now is that I need to pick the actual source attribute vs picking the block that has that specific attribute within it. We can try and hack the code some more ( we are not lisp literate) but if you have any suggestions you may have would be greatly appreciated.
Regards,
Vince
How about something like this...
(defun c:MAV (/ AT:GetSel atts ss i ass) ;; Match Attribute Values ;; Alan J. Thompson, 2017.01.31 (defun AT:GetSel (meth msg fnc / ent) ;; meth - selection method (entsel, nentsel, nentselp) ;; msg - message to display (nil for default) ;; fnc - optional function to apply to selected object ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC"))) ;; Alan J. Thompson, 05.25.10 (while (progn (setvar 'ERRNO 0) (setq ent (meth (cond (msg) ("\nSelect object: ") ) ) ) (cond ((eq (getvar 'ERRNO) 7) (princ "\nMissed, try again.")) ((eq (type (car ent)) 'ENAME) (if (and fnc (not (fnc ent))) (princ "\nInvalid object!") ) ) ) ) ) ent ) (if (and (AT:GetSel entsel "\nSelect source attributed block: " (lambda (x / d) (if (and (eq (cdr (assoc 0 (setq d (entget (car x))))) "INSERT") (eq (cdr (assoc 66 d)) 1) ) (setq atts (mapcar (function (lambda (a) (cons (vla-get-tagstring a) (vla-get-textstring a)))) (vlax-invoke (vlax-ename->vla-object (car x)) 'GetAttributes) ) ) ) ) ) (progn (princ "\nSelect destination attributed block(s): ") (setq ss (ssget "_:L" '((0 . "INSERT") (66 . 1)))) ) ) (repeat (setq i (sslength ss)) (foreach a (vlax-invoke (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'GetAttributes) (if (setq ass (cdr (assoc (vla-get-tagstring a) atts))) (vla-put-textstring a ass) ) ) ) ) (princ) ) (vl-load-com) (princ)
Selecting the source attribute.
Partial code block for your investigation:
; (while (setq a (entsel "Select an ATTRIBUTE to globally update: ")) (if (= (cdr (assoc 0 (entget (car a)))) "INSERT") (progn (setq b (nentselp (cadr a))) (if (= (cdr (assoc 0 (entget (car b)))) "ATTRIB") (progn (setq bn (cdr (assoc 2 (entget (car a))))) ;block name (setq bt (cdr (assoc 2 (entget (car b))))) ;tag name (setq bv (cdr (assoc 1 (entget (car b))))) ;tag value ... ;
???
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
@marko_ribar wrote: "Quick and dirty...
(defun c:copypasteattribattribbytag ..."
Typing in "copypasteattribattribbytag" may be dirty but certainly not quick. :]
John F. Uhden
Alan,
dang.... Pretty spot on for what I need. Only thing was is that I was hoping to have it loop through so I did not have to hit enter to execute the lisp again. No biggie still works for what I need.
Thanks so much
Vince
@spartan_vng wrote:Alan,
dang.... Pretty spot on for what I need. Only thing was is that I was hoping to have it loop through so I did not have to hit enter to execute the lisp again. No biggie still works for what I need.
Thanks so much
Vince
You're welcome.
Swap out the first if statement for a while, and you'll be good.
(if (and (AT:GetSel entsel
TO
(while (and (AT:GetSel entsel
Would there be a way to enable this routine to set the attribute's layer to "0" and the color of the layer to "GREEN" during the evaluation?
What about providing an option to select similar once the first destination block was selected?
@alanjt_Is there a way to automatically repeat this on multiple sources and copy to multiple destinations? Example would be an old parts list where each line item is an attributed block and need to copy all of the line item attributes to a newer line item block. Would be nice not to have to manually run the command on each line.
Definitely. You would just need a list of old attributed blocks and a corresponding list of new attributed blocks.
This right here is one of the best things that I have found in this forum... 100 thank yous for this good sir.
John F. Uhden