Jump to content

Recommended Posts

Posted

Hi, I'm writing in this section of the forum because I assume there is no solution with the normal use of the program.

I'm struggling with a building export from Revit, the generated file is a block that contains many nested blocks, even if I change the colors of the layers (I want to make them all the same color), until I go inside each single block and change the color from there I don't get the desired effect.

I would like to create a layer with a certain color and associate the color fromLayer (DaLayer) to the block and all its nested subblocks in a single operation.
Is it possible?
Thanks in advance

Posted

I am thinking you might use this from Lee Mac to get a list of nested blocks and work from there:

https://lee-mac.com/extractnestedblock.html

 

I think this is the related part of the code

 

;;https://lee-mac.com/extractnestedblock.html

;;USe this line to select a block
(enb:getreferences (cdr (assoc 2 (entget (car(entsel))))))


; Use this to loop through the blocks, in this case it is making a list, in your case (ssget "_X") and modify assoc codes to by block / layer colouras and layer codes.
(defun enb:getreferences ( blk / ent enx lst )
    (if (setq ent (tblobjname "block" blk))
        (foreach dxf (entget (cdr (assoc 330 (entget ent))))
            (if
                (and
                    (= 331 (car dxf))
                    (setq ent (cdr dxf))
                    (setq enx (entget ent))
                    (setq enx (entget (cdr (assoc 330 (reverse enx)))))
                )
                (if (wcmatch (strcase (setq blk (cdr (assoc 2 enx)))) "`**_SPACE")
                    (setq lst (cons (list ent) lst))
                    (setq lst (append (mapcar '(lambda ( l ) (cons ent l)) (enb:getreferences blk)) lst)) ;; Change this line to set colours / layers
                )
            )
        )
    )
    lst
)

 

 

 

That might give you a start if you want to do some thinking

 

  • Like 1
Posted (edited)

You could try this too: 

(defun c:foo (/ a d)
  (vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object))))
    (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a))))
  )
  (vlax-for b (vla-get-blocks d)
    (if	(= 0 (vlax-get b 'isxref) (vlax-get b 'islayout))
      (vlax-for	o b
	(vl-catch-all-apply 'vla-put-layer (list o "0"))
	(vl-catch-all-apply 'vla-put-color (list o 256))
      )
    )
  )
  (foreach l a (vlax-put l 'lock -1))
  (vla-purgeall d)
  (vla-regen d acactiveviewport)
  (princ)
)

 

Edited by ronjonp
  • Like 2
Posted

Wow! This is just what I needed, thanks!

I tried it and at first glance it works perfectly! do you want to give a name to your lisp? I'm archiving it as "acnb" but I will use your name if any

Now that I've used it, it's fine for me, but if I wanted to improve it, I think it could be useful to ask for the block to be modified because in this version the lisp works on all the nested blocks of the drawing... I repeat that it's fine for me too and so I thank you again!
Greetings

Posted
  On 3/19/2025 at 1:58 PM, itacad said:

Wow! This is just what I needed, thanks!

I tried it and at first glance it works perfectly! do you want to give a name to your lisp? I'm archiving it as "acnb" but I will use your name if any

Now that I've used it, it's fine for me, but if I wanted to improve it, I think it could be useful to ask for the block to be modified because in this version the lisp works on all the nested blocks of the drawing... I repeat that it's fine for me too and so I thank you again!
Greetings

Expand  

Glad to help 🍻

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