pmxcad Posted May 9, 2019 Posted May 9, 2019 Hello everyone, Question, I have found a lisp to attsyncate attributes without moving them to the block attributes default location. With this lisp you have to select the block. How can this be adjusted so that all blocks are selected? (defun c:attsync2 (/ _name _gettatts _lst atts e name ss) (defun _lst (ss / e n out) (setq n -1) (if (= (type ss) 'pickset) (while (setq e (ssname ss (setq n (1+ n)))) (setq out (cons (vlax-ename->vla-object e) out))) ) ) (defun _attpositions (block / att result) (foreach att (vlax-invoke block 'getattributes) (setq result (cons (list (vla-get-handle att) (vlax-get att 'insertionpoint) (vlax-get att 'textalignmentpoint) ) result ) ) ) ) (defun _name (b) (cond ((vlax-property-available-p b 'effectivename) (vla-get-effectivename b)) ((vlax-property-available-p b 'name) (vla-get-name b)) ) ) (if (and (setq e (car (entsel "\nSelect block to sync: "))) (setq name (_name (vlax-ename->vla-object e))) (setq ss (ssget "_x" (list (cons 0 "insert")))) ) (progn (foreach x (_lst ss) (and (eq (_name x) name) (setq atts (cons (_attpositions x) atts)))) (command "._attsync" "_s" e "_yes") (foreach x (apply 'append atts) (if (and (setq e (handent (car x))) (setq e (vlax-ename->vla-object e))) (progn (vl-catch-all-apply 'vlax-put (list e 'insertionpoint (cadr x))) (vl-catch-all-apply 'vlax-put (list e 'textalignmentpoint (caddr x))) ) ) ) ) ) (princ) ) Thanks in advance, Jaap Quote
BIGAL Posted May 10, 2019 Posted May 10, 2019 You should be able to apply attsync to the Block table name list, rather than 1 block so much quicker, but this list does have a couple you need to leave out but may still work. It really should check each block definition for attributes. It will display lots of errors but continues. (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (command "attsync" "n" (vla-get-name blk)) ) Quote
Emmanuel Delay Posted May 10, 2019 Posted May 10, 2019 I think this works I commented out this line, that asks the client to select an entity (setq e (car (entsel "\nSelect block to sync: "))) Instead I select all blocks with ssget, and provide each block as a parameter to attsync2 (defun attsync2 (e / _name _gettatts _lst atts name ss) (defun _lst (ss? / e n out) (setq n -1) (if (= (type ss) 'pickset) (while (setq e (ssname ss (setq n (1+ n)))) (setq out (cons (vlax-ename->vla-object e) out))) ) ) (defun _attpositions (block / att result) (foreach att (vlax-invoke block 'getattributes) (setq result (cons (list (vla-get-handle att) (vlax-get att 'insertionpoint) (vlax-get att 'textalignmentpoint) ) result ) ) ) ) (defun _name (b) (cond ((vlax-property-available-p b 'effectivename) (vla-get-effectivename b)) ((vlax-property-available-p b 'name) (vla-get-name b)) ) ) (if (and ;; (setq e (car (entsel "\nSelect block to sync: "))) ;; instead e is a parameter now (setq name (_name (vlax-ename->vla-object e))) (setq ss (ssget "_x" (list (cons 0 "insert")))) ) (progn (foreach x (_lst ss) (and (eq (_name x) name) (setq atts (cons (_attpositions x) atts)))) (command "._attsync" "_s" e "_yes") (foreach x (apply 'append atts) (if (and (setq e (handent (car x))) (setq e (vlax-ename->vla-object e))) (progn (vl-catch-all-apply 'vlax-put (list e 'insertionpoint (cadr x))) (vl-catch-all-apply 'vlax-put (list e 'textalignmentpoint (caddr x))) ) ) ) ) ) (princ) ) (defun c:attsync2 ( / ss i) ;; select all blocks with attributes (setq ss (ssget "_x" (list (cons 0 "insert") (cons 66 1)))) (setq i 0) (repeat (sslength ss) ;; for each block we invoke attsync2 (attsync2 (ssname ss i)) (setq i (+ i 1)) ) (princ "\nBlocks synced: ") (princ (sslength ss)) (princ) ) Quote
ronjonp Posted May 10, 2019 Posted May 10, 2019 @Emmanuel Delay FWIW .. I'd take the attsync out of the loop otherwise it will sync multiple times for the same block name. (defun c:attsync2 (/ _name _attpositions _lst atts e nm nms ss) (defun _lst (ss / e n out) (setq n -1) (if (= (type ss) 'pickset) (while (setq e (ssname ss (setq n (1+ n)))) (setq out (cons (vlax-ename->vla-object e) out))) ) ) (defun _attpositions (block / att result) (foreach att (vlax-invoke block 'getattributes) (setq result (cons (list (vla-get-handle att) (vlax-get att 'insertionpoint) (vlax-get att 'textalignmentpoint) ) result ) ) ) ) (defun _name (b) (cond ((vlax-property-available-p b 'effectivename) (vla-get-effectivename b)) ((vlax-property-available-p b 'name) (vla-get-name b)) ) ) (if (setq ss (ssget "_x" '((0 . "insert") (66 . 1)))) (progn (foreach x (_lst ss) ;; Gather attribute positions (setq atts (cons (_attpositions x) atts)) ;; Gather names to sync (or (vl-position (setq nm (_name x)) nms) (setq nms (cons nm nms))) ) ;; Attsync the block names first (foreach x nms (command "._attsync" "_n" x)) ;; Now move the atttributes back to their original locations (foreach x (apply 'append atts) (if (and (setq e (handent (car x))) (setq e (vlax-ename->vla-object e))) (progn (vl-catch-all-apply 'vlax-put (list e 'insertionpoint (cadr x))) (vl-catch-all-apply 'vlax-put (list e 'textalignmentpoint (caddr x))) ) ) ) ) ) (princ) ) Quote
pmxcad Posted May 10, 2019 Author Posted May 10, 2019 ronjonp, works perfectly. BIGAL, Emmanuel Delay and ronjonp ..... thanks for your time. Jaap 1 Quote
ronjonp Posted May 10, 2019 Posted May 10, 2019 9 minutes ago, pmxcad said: ronjonp, works perfectly. BIGAL, Emmanuel Delay and ronjonp ..... thanks for your time. Jaap Glad to help. Quote
3dwannab Posted October 12, 2023 Posted October 12, 2023 (edited) Am I missing something? To attsync all blocks in a drawing. (command "._ATTSYNC" "_N" "*") EDIT: Nevermind, silly me. Edited October 12, 2023 by 3dwannab Wrong answer again Quote
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.