Jump to content

HI ALL, I want to convert all attribute on block to ''by block'' and set a them to layer 0. Thank for your help !


Recommended Posts

Posted
(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)
)

 

Posted
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!!

Posted

Very strange, on my AutoCAD 2021 it works. Send a piece of drawing I check.

Posted (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 by rlx
Posted
5 hours ago, confutatis said:

Very strange, on my AutoCAD 2021 it works. Send a piece of drawing I check.

 

new block.dwg

Posted
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

Posted

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?

Posted (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 by confutatis
Posted
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

image.thumb.png.ae95970ed778a3104433320894d660a6.png

Posted
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

image.thumb.png.4ecc00ad48bf4b28141b44abc8ad584d.png

Posted
(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))

🐉

  • Thanks 1
Posted
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.

Posted
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 !!

Posted

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))

 

  • Thanks 1
Posted
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 !!!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...