EzyG Posted February 19, 2017 Share Posted February 19, 2017 Hi Everyone Need help to modify some code or re-write........Struggling I would like to transfer the default attribute value of multiple blocks (say 3 max) into 1 single block by using a window selection. Attached is some awsome similar code by Lee Mac, Alan J Thompson & others which I am struggling to modify. Please Help & advise Thanks ATTCOPY.lsp demo.lsp demo2.lsp MB.lsp TEST.LSP TIP1045B.LSP Quote Link to comment Share on other sites More sharing options...
EzyG Posted February 19, 2017 Author Share Posted February 19, 2017 Sample drawing attached with description SAMPLE.dwg Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 20, 2017 Share Posted February 20, 2017 I would take a different direction pick the block to be updated make a list of attribute tag names then pick any other block get list of attribute tag names and compare to 1st block if match then update block 1 repeat above step for as many blocks as you like. It does require tag name matching but sometimes we need rules. The reason I suggest this is match tag string names would limit you to only one solution, what happens on next block combo. The code would have a couple of defuns getatttagnames compareatttagnames. (setq lst '()) (setq lst2 '()) (foreach att (vlax-invoke (vlax-ename->vla-object (car (entsel "Pick Block")) ) 'getattributes) (setq lst (cons (vla-get-tagstring att) lst) ) (setq lst2 (cons (vla-get-textstring att) lst2) ) ) Pick Block Command: !lst ("SECTION" "JOB" "QA" "QTY" "FINISH" "STOCK" "CUTLENGTH" "OALENGTH" "ID") Command: !lst2 ("75x75x6.0SHS" "" "" "1" "PTD" "PTD" "3000" "" "C1") Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 20, 2017 Share Posted February 20, 2017 Start of version 2, ran out of time ;(defun compareattnames (mblocklst lst lst2) ; do comparison and update here (defun getatttagnames (obj / ) (setq lst '()) (setq lst2 '()) (foreach att (vlax-invoke (vlax-ename->vla-object obj ) 'getattributes) (setq lst (cons (vla-get-tagstring att) lst) ) (setq lst2 (cons (vla-get-textstring att) lst2) ) ) ) (defun upattribs () (getatttagnames (car (entsel "Pick Master Block"))) (setq mblocklst lst) ; master block (while (car (entsel "Pick other Block")) (getatttagnames) ;(compareattnames mblocklst lst lst2) ) ) Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted February 20, 2017 Share Posted February 20, 2017 (edited) Try the code below. When selecting the source blocks you can include the target, it will be filtered out. (vl-load-com) (defun KGA_Conv_Pickset_To_ObjectList (ss / i ret) (if ss (repeat (setq i (sslength ss)) (setq ret (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) ret)) ) ) ) (defun c:CopyAttValues ( / doc enm srcLst ss sub trg trgAttLst) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-endundomark doc) (vla-startundomark doc) (if (and (setq enm (car (entsel "\nTarget block: "))) (setq trg (vlax-ename->vla-object enm)) (= "AcDbBlockReference" (vla-get-objectname trg)) (= :vlax-true (vla-get-hasattributes trg)) (princ "\nSource blocks: ") (setq ss (ssget '((0 . "INSERT") (66 . 1)))) (setq srcLst (vl-remove trg (KGA_Conv_Pickset_To_ObjectList ss))) ) (progn (setq trgAttLst (mapcar '(lambda (att) (cons (strcase (vla-get-tagstring att)) att)) (vlax-invoke trg 'getattributes) ) ) (foreach src srcLst (if trgAttLst (foreach att (vlax-invoke src 'getattributes) (if (setq sub (assoc (strcase (vla-get-tagstring att)) trgAttLst)) (progn (vla-put-textstring (cdr sub) (vla-get-textstring att)) (setq trgAttLst (vl-remove sub trgAttLst)) ) ) ) ) ) ) ) (vla-endundomark doc) (princ) ) Edited February 20, 2017 by Roy_043 Added (vl-load-com). Quote Link to comment Share on other sites More sharing options...
EzyG Posted February 21, 2017 Author Share Posted February 21, 2017 BigAl & Roy_43 Sincerely thanking you both for taking the time to help. Roy , the lisp works exactly as I wanted, really much appreciated. Wish I could take you both to the pub This was first lisp attempt. I've spent the week studying & trialing with mixed results. Defintely going to keep playing with Lisp. Guys thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.