confutatis Posted July 28, 2021 Posted July 28, 2021 (defun C:CHATTLA (/ blockname) (setq blockname (vlax-ename->vla-object (car (entsel "\nSelect block: ")))) (vlax-for elem (vla-item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-EffectiveName blockname)) (if (equal (vla-get-ObjectName elem) "AcDbAttributeDefinition") (progn (vla-put-Color elem 0)(vla-put-Layer elem "0")) ) ) (vl-cmdf "_ATTSYNC" "N" (vla-get-EffectiveName blockname)) (princ) ) Quote
Trai Posted July 29, 2021 Author Posted July 29, 2021 22 hours ago, confutatis said: (defun C:CHATTLA (/ blockname) (setq blockname (vlax-ename->vla-object (car (entsel "\nSelect block: ")))) (vlax-for elem (vla-item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-EffectiveName blockname)) (if (equal (vla-get-ObjectName elem) "AcDbAttributeDefinition") (progn (vla-put-Color elem 0)(vla-put-Layer elem "0")) ) ) (vl-cmdf "_ATTSYNC" "N" (vla-get-EffectiveName blockname)) (princ) ) hi, i tried it , but it not working, please uppload for me again. many thank!! Quote
confutatis Posted July 29, 2021 Posted July 29, 2021 Very strange, on my AutoCAD 2021 it works. Send a piece of drawing I check. Quote
rlx Posted July 29, 2021 Posted July 29, 2021 (edited) maybe just some brute force? (all blocks in drawing) (defun c:t1 ( / l o) (vl-load-com) (vlax-for l (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))(vlax-for o (vla-get-block l) (if (and (eq "AcDbBlockReference" (vla-get-objectname o))(eq :vlax-true (vla-get-hasattributes o))) (mapcar '(lambda (x)(vla-put-Color x 0)(vla-put-Layer x "0"))(vlax-invoke o 'getattributes)))))) and if you want to use less force (just select one) (defun c:t2 ( / b) (vl-load-com) (if (and (setq b (entsel "\nSelect a block : "))(eq "AcDbBlockReference" (vla-get-objectname (setq b (vlax-ename->vla-object (car b)))))(eq :vlax-true (vla-get-hasattributes b))) (mapcar '(lambda (x)(vla-put-Color x 0)(vla-put-Layer x "0"))(vlax-invoke b 'getattributes)))(princ)) Edited July 29, 2021 by rlx Quote
Trai Posted July 30, 2021 Author Posted July 30, 2021 5 hours ago, confutatis said: Very strange, on my AutoCAD 2021 it works. Send a piece of drawing I check. new block.dwg Quote
Trai Posted July 30, 2021 Author Posted July 30, 2021 17 minutes ago, Trai said: new block.dwg 88.25 kB · 0 downloads Untitled Project.mp4 Quote
Trai Posted July 30, 2021 Author Posted July 30, 2021 4 hours ago, rlx said: maybe just some brute force? (all blocks in drawing) (defun c:t1 ( / l o) (vl-load-com) (vlax-for l (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))(vlax-for o (vla-get-block l) (if (and (eq "AcDbBlockReference" (vla-get-objectname o))(eq :vlax-true (vla-get-hasattributes o))) (mapcar '(lambda (x)(vla-put-Color x 0)(vla-put-Layer x "0"))(vlax-invoke o 'getattributes)))))) and if you want to use less force (just select one) (defun c:t2 ( / b) (vl-load-com) (if (and (setq b (entsel "\nSelect a block : "))(eq "AcDbBlockReference" (vla-get-objectname (setq b (vlax-ename->vla-object (car b)))))(eq :vlax-true (vla-get-hasattributes b))) (mapcar '(lambda (x)(vla-put-Color x 0)(vla-put-Layer x "0"))(vlax-invoke b 'getattributes)))(princ)) sorry, but it not working, you can see this fiel attached Untitled Project.mp4 Quote
rlx Posted July 30, 2021 Posted July 30, 2021 how about : my title was misleading because I said all attribute while what I realy want is to convert all objects inside a block / all blocks to color byblock and layer zero? Quote
confutatis Posted July 30, 2021 Posted July 30, 2021 (edited) No wonder it doesn't work! You said you only had to change the attributes... (defun C:CHATTLA () (vl-load-com) (vlax-for elem1 (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for elem2 elem1 (vla-put-Color elem2 0)(vla-put-Layer elem2 "0") ) ) (princ) ) Brute force version... Edited July 30, 2021 by confutatis Quote
Trai Posted July 30, 2021 Author Posted July 30, 2021 6 hours ago, confutatis said: No wonder it doesn't work! You said you only had to change the attributes... (defun C:CHATTLA () (vl-load-com) (vlax-for elem1 (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for elem2 elem1 (vla-put-Color elem2 0)(vla-put-Layer elem2 "0") ) ) (princ) ) Brute force version... Sorry for that, I want to convert all blocks when i sweep by mouse, all objects selected when I double click them will be convert to by block, and layer default is layer 0. This is image for that.. thank for your help Quote
Trai Posted July 30, 2021 Author Posted July 30, 2021 7 hours ago, rlx said: how about : my title was misleading because I said all attribute while what I realy want is to convert all objects inside a block / all blocks to color byblock and layer zero? Sorry for that so can you help me edit again. I want to convert all blocks when i sweep by mouse, all objects selected when I double click them will be convert to by block, and layer default is layer 0. This is image for that.. thank for your help Quote
rlx Posted July 30, 2021 Posted July 30, 2021 (vl-load-com) (defun c:t4 (/ d o c)(setq c (vla-get-Blocks (setq d (vla-get-ActiveDocument (vlax-get-acad-object))))) (if (and (setq o (entsel "\nSelect block: ")) (block-p (setq o (vlax-ename->vla-object (car o))))) (mapcar '(lambda (n) (vlax-for x (vla-item c n)(vla-put-Color x 0) (vla-put-linetype x "ByBlock") (vla-put-Layer x "0") (vla-put-Lineweight x -2)(vla-put-EntityTransparency x "ByBlock"))) (nb o))) (vla-regen d acAllViewports) (princ) ) ;;; test of object is a block (block-p (vlax-ename->vla-object (car (entsel)))) (defun block-p (o) (and (= 'vla-object (type o))(eq (vla-get-objectname o) "AcDbBlockReference"))) ;;; test if object is block and return name / effective name : (block-n (vlax-ename->vla-object (car (entsel)))) (defun block-n (o) (if (and (= 'vla-object (type o))(eq (vla-get-objectname o) "AcDbBlockReference")) (if (vlax-property-available-p o 'EffectiveName)(vla-Get-EffectiveName o)(vla-Get-Name o)) nil)) ;;; nested block names : test : (nb (vlax-ename->vla-object (car (entsel "\nSelect block: ")))) (defun nb ( b / c l n) (setq c (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))) (vlax-for o (vla-item c (block-n b)) (if (and (eq "AcDbBlockReference" (vla-get-ObjectName o)) (not (member (setq n (block-n o)) l)))(progn(setq l (cons n l))(nb o))))(cons (block-n b) l)) 1 Quote
Trai Posted July 31, 2021 Author Posted July 31, 2021 14 hours ago, rlx said: (vl-load-com) (defun c:t4 (/ d o c)(setq c (vla-get-Blocks (setq d (vla-get-ActiveDocument (vlax-get-acad-object))))) (if (and (setq o (entsel "\nSelect block: ")) (block-p (setq o (vlax-ename->vla-object (car o))))) (mapcar '(lambda (n) (vlax-for x (vla-item c n)(vla-put-Color x 0) (vla-put-linetype x "ByBlock") (vla-put-Layer x "0") (vla-put-Lineweight x -2)(vla-put-EntityTransparency x "ByBlock"))) (nb o))) (vla-regen d acAllViewports) (princ) ) ;;; test of object is a block (block-p (vlax-ename->vla-object (car (entsel)))) (defun block-p (o) (and (= 'vla-object (type o))(eq (vla-get-objectname o) "AcDbBlockReference"))) ;;; test if object is block and return name / effective name : (block-n (vlax-ename->vla-object (car (entsel)))) (defun block-n (o) (if (and (= 'vla-object (type o))(eq (vla-get-objectname o) "AcDbBlockReference")) (if (vlax-property-available-p o 'EffectiveName)(vla-Get-EffectiveName o)(vla-Get-Name o)) nil)) ;;; nested block names : test : (nb (vlax-ename->vla-object (car (entsel "\nSelect block: ")))) (defun nb ( b / c l n) (setq c (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object)))) (vlax-for o (vla-item c (block-n b)) (if (and (eq "AcDbBlockReference" (vla-get-ObjectName o)) (not (member (setq n (block-n o)) l)))(progn(setq l (cons n l))(nb o))))(cons (block-n b) l)) Thank you so much for your support!. This code worked. Quote
Trai Posted August 1, 2021 Author Posted August 1, 2021 On 7/31/2021 at 5:56 PM, Trai said: Thank you so much for your support!. This code worked. DEAR SIR, can you edit this code that post for me. this your code worked, but i want to a feature below: In drawing have many objectes, i wanna mouse sweep to take blockes . NOT choose click on to block one by one. THANK YOU FOR YOUR HELP !! Quote
rlx Posted August 2, 2021 Posted August 2, 2021 untested (defun c:t5 (/ ss l c d) (setq c (vla-get-Blocks (setq d (vla-get-ActiveDocument (vlax-get-acad-object))))) (princ "\nSelect blocks to reset props to ByBlock") (if (and (setq ss (ssget '((0 . "INSERT")))) (setq l (ss->ol ss))) (foreach o l (mapcar '(lambda (n) (vlax-for x (vla-item c n)(vla-put-Color x 0) (vla-put-linetype x "ByBlock") (vla-put-Layer x "0") (vla-put-Lineweight x -2)(vla-put-EntityTransparency x "ByBlock"))) (nb o)))) (vla-regen d acAllViewports) (princ) ) ;;; selectionset to (object) list (defun ss->ol (ss / i l) (setq i 0) (repeat (sslength ss) (setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) ;;; test if object is block and return name / effective name : (block-n (vlax-ename->vla-object (car (entsel)))) (defun block-n (o) (if (and (= 'vla-object (type o))(eq (vla-get-objectname o) "AcDbBlockReference")) (if (vlax-property-available-p o 'EffectiveName)(vla-Get-EffectiveName o)(vla-Get-Name o)) nil)) ;;; nested block names : test : (nb (vlax-ename->vla-object (car (entsel "\nSelect block: ")))) (defun nb ( b / c l n) (or c (setq c (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))) (vlax-for o (vla-item c (block-n b)) (if (and (eq "AcDbBlockReference" (vla-get-ObjectName o)) (not (member (setq n (block-n o)) l)))(progn(setq l (cons n l))(nb o))))(cons (block-n b) l)) 1 Quote
Trai Posted August 2, 2021 Author Posted August 2, 2021 6 hours ago, rlx said: untested (defun c:t5 (/ ss l c d) (setq c (vla-get-Blocks (setq d (vla-get-ActiveDocument (vlax-get-acad-object))))) (princ "\nSelect blocks to reset props to ByBlock") (if (and (setq ss (ssget '((0 . "INSERT")))) (setq l (ss->ol ss))) (foreach o l (mapcar '(lambda (n) (vlax-for x (vla-item c n)(vla-put-Color x 0) (vla-put-linetype x "ByBlock") (vla-put-Layer x "0") (vla-put-Lineweight x -2)(vla-put-EntityTransparency x "ByBlock"))) (nb o)))) (vla-regen d acAllViewports) (princ) ) ;;; selectionset to (object) list (defun ss->ol (ss / i l) (setq i 0) (repeat (sslength ss) (setq l (cons (vlax-ename->vla-object (ssname ss i)) l) i (1+ i))) l) ;;; test if object is block and return name / effective name : (block-n (vlax-ename->vla-object (car (entsel)))) (defun block-n (o) (if (and (= 'vla-object (type o))(eq (vla-get-objectname o) "AcDbBlockReference")) (if (vlax-property-available-p o 'EffectiveName)(vla-Get-EffectiveName o)(vla-Get-Name o)) nil)) ;;; nested block names : test : (nb (vlax-ename->vla-object (car (entsel "\nSelect block: ")))) (defun nb ( b / c l n) (or c (setq c (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))))) (vlax-for o (vla-item c (block-n b)) (if (and (eq "AcDbBlockReference" (vla-get-ObjectName o)) (not (member (setq n (block-n o)) l)))(progn(setq l (cons n l))(nb o))))(cons (block-n b) l)) THANK YOU SO MUCH , THIS CODE WORKED !!! 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.