Set all entities "Transparency" and "Material" inside blocks to "ByBlock"

Set all entities "Transparency" and "Material" inside blocks to "ByBlock"

Anonymous
Not applicable
5,527 Views
16 Replies
Message 1 of 17

Set all entities "Transparency" and "Material" inside blocks to "ByBlock"

Anonymous
Not applicable

Hello,

 

I've already tried to find a similar LISP in here forum to change all entities "Transparency" and "Material" properties inside ALL blocks to "ByBlock", but I can't find anything to accomplish this task. It should change the entities in nested blocks (blocks inside other blocks) aswell.

 

Is there avaiable any routine to do that task? Wouldn't be necessary to specify or select any block as I want to do that to all entities of all blocks. Is it possible to do without going into each block, using the CHPROP command and then selecting all entities to change "Transparency" and "Material" to "ByBlock"?

 

Thanks.

0 Likes
Accepted solutions (2)
5,528 Views
16 Replies
Replies (16)
Message 2 of 17

dlanorh
Advisor
Advisor

I don't think it's possible to change entity transparency, only layer transparency. If you open a block in the block editor, select an entity right click and select properties you will find the transparency is not changeable, unless it is a hatch.
Are all the objects within the blocks on layer "0" (zero)? If they are, this allows the block to take on the transparency of the layer it is inserted on.

I am not one of the robots you're looking for

Message 3 of 17

Anonymous
Not applicable

@dlanorh wrote:

I don't think it's possible to change entity transparency, only layer transparency. If you open a block in the block editor, select an entity right click and select properties you will find the transparency is not changeable, unless it is a hatch.
Are all the objects within the blocks on layer "0" (zero)? If they are, this allows the block to take on the transparency of the layer it is inserted on.


 

Yes, all entities inside blocks are always on layer "0".

 

Please, see the gif bellow to check what I mean:

 

byblock.gif

 

As you can see in the example above, if I go to the block editor I can change Transparency and Material properties of all entities by using the "CHPROP" command. But imagine when you have to do that for 500 blocks for example.

 

Thanks.

0 Likes
Message 4 of 17

dlanorh
Advisor
Advisor
If you run these on the command line
(vl-load-com)
(vlax-dump-object (vlax-ename->vla-object (car (entsel "\nSelect object : "))))
If the dump object list on the text screen (F2) contains a transparency property then it is changeable using lisp. If It doesn't, it's not.

I am not one of the robots you're looking for

Message 5 of 17

Anonymous
Not applicable

@dlanorh wrote:
If you run these on the command line
(vl-load-com)
(vlax-dump-object (vlax-ename->vla-object (car (entsel "\nSelect object : "))))
If the dump object list on the text screen (F2) contains a transparency property then it is changeable using lisp. If It doesn't, it's not.

 

Please, can't I use the same principle of this one to set all colors to "Bylayer" but to set "Transparency" and "Material to "ByBlock"? Are you able to modify the routine bellow (from forum), so it works as planned:

 

(defun c:test (/ ss e blk doc)
 (if (setq ss (ssget ":L" '((0 . "INSERT"))))
  (repeat (setq i (sslength ss))
   (setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
    
   (setq doc (vla-get-activedocument (vlax-get-acad-object)))
   (setq blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename e)))
   (vlax-for x blk
    (if (eq (vla-get-objectname x) "AcDbBlockReference")
     (color->byblock doc x) 
     (vla-put-color x 0)
    )
   )
  )
 )
  
 (vla-regen doc acAllViewports)
 (princ)
)

(defun color->byblock (doc x / doc blk)
 (setq blk (vla-item (vla-get-blocks doc) (vla-get-Effectivename x)))
  
 (vlax-for x blk
  (if (eq (vla-get-objectname x) "AcDbBlockReference")
   (color->byblock doc x) ; recursion
   (vla-put-color x 0)
  )
 )
) 

 Thanks!

0 Likes
Message 6 of 17

dlanorh
Advisor
Advisor
It would seem there is an undocumented property that may allow this. I'll get back to you in a couple of hours.

I am not one of the robots you're looking for

Message 7 of 17

Anonymous
Not applicable
; (NestedPutProp "MyBlk" 'entitytransparency "BYBLOCK")
; (NestedPutProp "MyBlk" 'color 3)
(defun NestedPutProp (nme prop val / blk)
 (if
   (and
     (not
       (vl-catch-all-error-p
         (setq blk
           (vl-catch-all-apply
             'vla-item
             (list
               (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
               nme
             )
           )
         )
       )
     )
     (= :vlax-false (vla-get-islayout blk))
     (= :vlax-false (vla-get-isxref blk))
   )
   (vlax-for obj blk (vlax-put obj prop val))
 )
)

(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:TRBB ( / doc doneLst ss)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc)
 (vla-startundomark doc)
 (if (setq ss (ssget '((0 . "INSERT"))))
   (foreach obj  (KGA_Conv_Pickset_To_ObjectList ss)
     (if (not (vl-position (strcase (vla-get-name obj)) doneLst))
       (progn
         (NestedPutProp (vla-get-name obj) 'entitytransparency "BYBLOCK")
         (setq doneLst (cons (strcase (vla-get-name obj)) doneLst))
       )
     )
   )
 )
 (vla-regen doc acactiveviewport)
 (vla-endundomark doc)
 (princ)
)

 

I've found this routine on Internet and I don't know if it can help you too. From what I've read, this LISP works by selecting blocks one by one, changing "Transparency" to "ByBlock" of all entities of a selected block. I would like something similar to this, but that puts "Material" properties to "ByBlock" aswell and that applies for ALL blocks of the drawing, without needing to select one by one.

 

Yet, the above LISP only works for normall blocks and it does not work for Dynamic Blocks. Man Sad

 

Hope it helps!

0 Likes
Message 8 of 17

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... LISP .... to change all entities "Transparency" and "Material" properties inside ALL blocks to "ByBlock....


 

You don't want something that is insertion-based [the various offerings above look for INSERT objects, i.e. Block references ], because that will unnecessarily run those property assignments on nested entities more than once  for any Block that's Inserted more than once.  You want one that steps through the Block table, and for each definition  there [that isn't an Xref or a Dimension, which also show up there], gives those properties to all the pieces it's made of.  Try this:

 

(defun C:BETMBB ; = Block Entities Transparency & Material to ByBlock
  (/ blkdata ent obj)
  (while (setq blkdata (tblnext "block" (not blkdata))); still any Block definitions left?
    (if
      (and
        (not (assoc 1 blkdata)); not an Xref [no path]
        (not (wcmatch (cdr (assoc 2 blkdata)) "`*D*")); not a Dimension
      ); and
      (progn ; then -- process it
        (setq ent (tblobjname "block" (cdr (assoc 2 blkdata)))); Block definition as entity
        (while (setq ent (entnext ent)); still something left in definition?
          (setq obj (vlax-ename->vla-object ent))
          (vla-put-EntityTransparency obj "ByBlock")
          (vla-put-Material obj "ByBlock")
        ); while
      ); progn
    ); if
  ); while
  (princ)
); defun
Kent Cooper, AIA
Message 9 of 17

Anonymous
Not applicable

@Kent1Cooper wrote:

@Anonymous wrote:

.... LISP .... to change all entities "Transparency" and "Material" properties inside ALL blocks to "ByBlock....


 

You don't want something that is insertion-based [the various offerings above look for INSERT objects, i.e. Block references ], because that will unnecessarily run those property assignments on nested entities more than once  for any Block that's Inserted more than once.  You want one that steps through the Block table, and for each definition  there [that isn't an Xref or a Dimension, which also show up there], gives those properties to all the pieces it's made of.  Try this:

 

(defun C:BETMBB ; = Block Entities Transparency & Material to ByBlock
  (/ blkdata ent obj)
  (while (setq blkdata (tblnext "block" (not blkdata))); still any Block definitions left?
    (if
      (and
        (not (assoc 1 blkdata)); not an Xref [no path]
        (not (wcmatch (cdr (assoc 2 blkdata)) "`*D*")); not a Dimension
      ); and
      (progn ; then -- process it
        (setq ent (tblobjname "block" (cdr (assoc 2 blkdata)))); Block definition as entity
        (while (setq ent (entnext ent)); still something left in definition?
          (setq obj (vlax-ename->vla-object ent))
          (vla-put-EntityTransparency obj "ByBlock")
          (vla-put-Material obj "ByBlock")
        ); while
      ); progn
    ); if
  ); while
  (princ)
); defun

 

DAM! That was exactly what I was looking for, sir. I've forgot to mention that mostly of the blocks wouldn't be inserted in drawing, only having their "block definition" inside it. PERFECT! It works for all dynamic blocks aswell. Can't thank you enough for this awesome solution. Kudos! Smiley Very Happy

0 Likes
Message 10 of 17

dlanorh
Advisor
Advisor

OK, changing the material & transparency properties of all items in all block definitions (block table) doesn't affect the block references in the drawing(the blocks themselves are still bylayer for both). These need to be changed seperately. So my question is do you want this applying to all block references, a selection of references or something else?

I am not one of the robots you're looking for

0 Likes
Message 11 of 17

Anonymous
Not applicable

@dlanorh wrote:

OK, changing the material & transparency properties of all items in all block definitions (block table) doesn't affect the block references in the drawing. These need to be changed seperately. So my question is do you want this applying to all block references, a selection of references or something else?


 

To all block references @dlanorh.  Thanks again!

0 Likes
Message 12 of 17

Kent1Cooper
Consultant
Consultant

@dlanorh wrote:

OK, changing the material & transparency properties of all items in all block definitions (block table) doesn't affect the block references in the drawing(the blocks themselves are still bylayer for both). These need to be changed seperately. So my question is do you want this applying to all block references, a selection of references or something else?


 

It doesn't apply to Block references, but to Block definitions.  Yes, each reference would have its own assignment of such properties separately, which can be different from those of other references of the same Block -- that's the whole point  of assigning "ByBlock " for those properties to the pieces inside the Block definitions.  What they would apply to Block references [whether all or a selection of them] would not  be "this," but would be particular transparency and material values.

Kent Cooper, AIA
Message 13 of 17

Anonymous
Not applicable

@Kent1Cooper wrote:

@dlanorh wrote:

OK, changing the material & transparency properties of all items in all block definitions (block table) doesn't affect the block references in the drawing(the blocks themselves are still bylayer for both). These need to be changed seperately. So my question is do you want this applying to all block references, a selection of references or something else?


 

It doesn't apply to Block references, but to Block definitions.  Yes, each reference would have its own assignment of such properties separately, which can be different from those of other references of the same Block -- that's the whole point  of assigning "ByBlock " for those properties to the pieces inside the Block definitions.  What they would apply to Block references [whether all or a selection of them] would not  be "this," but would be particular transparency and material values.


 

You routine just did what I was asking and it worked perfectly! For this particular task, I need to change all them to "ByBlock" because I'm importing entities from other softwares.

But inside AutoCAD, what would you advice me? To leave "CETRANSPARENCY" variable set to "ByLayer" or "ByBlock"? By default, when you create new entities, AutoCAD puts "Transparency" and "Materials" both on "ByLayer" state.

 

For creating blocks, materials and transparency should be setted to "ByLayer" or to "ByBlock"? From my knowledge, "ByBlock" gives you an "extra layer" of display control, being possible to set "Transparency" and "Materials" using layers AND using the properties pallete, which will not happen if those properties are setted to "ByLayer". Is there any good practice advice on this?

 

Thanks again! for sharing a little of your knowledge with a noob. 🙂

0 Likes
Message 14 of 17

dlanorh
Advisor
Advisor
Accepted solution

I see Kent beat me to it. But try this

 

(defun c:test (/ *error* c_doc c_blks c_lyrs ll_lst)

  (defun *error* ( msg )
    (if ll_lst (foreach lyr ll_lst (vlax-put-property lyr 'lock :vlax-true)))  
    (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred."))) (princ) );_end_*error*_defun (setq c_doc (vla-get-activedocument (vlax-get-acad-object)) c_blks (vla-get-blocks c_doc) c_lyrs (vla-get-layers c_doc) );end_setq (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (vla-startundomark c_doc) ;get list of locked layers and unlock all (vlax-for lyr c_lyrs (cond ( (= :vlax-true (vlax-get-property lyr 'lock)) (setq ll_lst (cons lyr ll_lst)) (vlax-put-property lyr 'lock :vlax-false)))) (vlax-for blk c_blks (cond ( (and (not (wcmatch (vlax-get-property blk 'name) "'*")) (= :vlax-false (vlax-get-property blk 'islayout)) (= :vlax-false (vlax-get-property blk 'isxref)) );end_and (vlax-for x blk (if (vlax-property-available-p x 'entitytransparency T) (vlax-put-property x 'entitytransparency "BYBLOCK")) (if (vlax-property-available-p x 'material T) (vlax-put-property x 'material "BYBLOCK")) );end_for ) );end_cond );end_for (ssget "_X" '((0 . "INSERT") (410 . "MODEL"))) (vlax-for r_blk (vla-get-activeselectionset c_doc) (if (vlax-property-available-p r_blk 'entitytransparency T) (vlax-put-property r_blk 'entitytransparency "BYBLOCK")) (if (vlax-property-available-p r_blk 'material T) (vlax-put-property r_blk 'material "BYBLOCK")) );end_for (if ll_lst (foreach lyr ll_lst (vlax-put-property lyr 'lock :vlax-true))) (vla-regen c_doc acAllViewports) (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc)) (princ) );end_defun

 

All Block Definitions and all Block References in Modelspace have Transparency and Material set to ByBlock

I am not one of the robots you're looking for

0 Likes
Message 15 of 17

Anonymous
Not applicable

@dlanorh wrote:

All Block Definitions and all Block References in Modelspace have Transparency and Material set to ByBlock


 

I've tested your routine and it works great so far. I've accepted as solution aswell. It could help someone else who is looking for this same task. Thanks a LOT @dlanorhSmiley Very Happy

0 Likes
Message 16 of 17

dlanorh
Advisor
Advisor

@Kent1Cooper wrote:

 

It doesn't apply to Block references, but to Block definitions.  Yes, each reference would have its own assignment of such properties separately, which can be different from those of other references of the same Block -- that's the whole point  of assigning "ByBlock " for those properties to the pieces inside the Block definitions.  What they would apply to Block references [whether all or a selection of them] would not  be "this," but would be particular transparency and material values.


If you redefine the Block Definitions, inserting a redefined block into the drawing still sets the reference blocks transparency and material properties to "ByLayer", at least on my system. Hence my question to the OP.

I am not one of the robots you're looking for

0 Likes
Message 17 of 17

Kent1Cooper
Consultant
Consultant

@dlanorh wrote:

.... If you redefine the Block Definitions, inserting a redefined block into the drawing still sets the reference blocks transparency and material properties to "ByLayer"....


 

That's true only when "ByLayer" is the current setting  of the CETRANSPARENCY and/or CMATERIAL System Variables.  Those are no different from other entity properties, e.g. by initial default everything you draw will have a Color property of "ByLayer" as long as that's the setting of the CECOLOR System Variable, but you can change that, and you can similarly change the Transparency and/or Material that newly-drawn objects will get.

Kent Cooper, AIA
0 Likes