Entity color change in anonymous blocks

Discussion in 'AutoCAD' started by rolandganter, Feb 10, 2004.

  1. rolandganter

    rolandganter Guest

    I'm sure this has been asked before, but I can't find the exact solution: I have drawings with thousands of anonymous blocks, whose sub-entities have hard-coded color. Does anybody know of a routine to change the nested block entities to bylayer in one step? (globally or by selection). Thanks, Roland
     
    rolandganter, Feb 10, 2004
    #1
  2. rolandganter

    BillZ Guest

    Here's a routine that you could modify to change colors of returned list of ents.

    ;;;5/14/03 Luis Esquivel
    ;;;to find list of nested blocks and ents inside block.


    (defun rcmd-dxf (g e)
    (cond
    ((= (type e) 'ename) (cdr (assoc g (entget e))))
    ((= (type e) 'list) (cdr (assoc g e)))))


    ;; (setq lst (rcmd-scanBlock-lst ent))
    ;; (("INSERT" )
    ;; ("INSERT" )
    ;; ("INSERT" ))
    (defun rcmd-scanBlock-lst (blk / enext entNames)
    (setq enext
    (cdr
    (assoc
    -2
    (tblSearch
    "block"
    (rcmd-dxf 2 (entget blk))))))
    (while enext
    (setq entNames
    (cons (list (rcmd-dxf 0 (entget enext)) enext)
    entNames))
    (setq enext (entnext enext)))
    (reverse entNames))

    Bill
     
    BillZ, Feb 10, 2004
    #2
  3. rolandganter

    Jeff Mishler Guest

    Here's a little lisp that will set ALL entites in ALL blocks (except the
    Model & Paperspace blocks) to bylayer. Can be modified to include all
    objects or to only include anonymous blocks.

    Jeff

    (defun block_color_fix (/ blks doc blk ent)
    (setq blks (vla-get-blocks
    (setq doc (vla-get-activedocument
    (vlax-get-acad-object)))))
    (vla-startundomark doc)
    (vlax-for blk blks
    (if (not (wcmatch (vla-get-name blk) "*Model*,*Paper*"))
    (progn
    (vlax-for ent blk
    (vla-put-color ent 256)
    )
    )
    )
    )
    (vla-regen doc acActiveViewport)
    (vla-endundomark doc)
    )
    (defun c:BFX () (block_color_fix)(princ))


    solution: I have drawings with thousands of anonymous blocks, whose
    sub-entities have hard-coded color. Does anybody know of a routine to
    change the nested block entities to bylayer in one step? (globally or by
    selection). Thanks, Roland
     
    Jeff Mishler, Feb 10, 2004
    #3
  4. rolandganter

    Joe Burke Guest

    Hi Jeff,

    I believe the block names *MODEL_SPACE and *PAPER_SPACE are always upper case. So
    wcmatch fails and those two blocks are modified.

    Maybe also filter out xref blocks?

    Joe Burke
     
    Joe Burke, Feb 11, 2004
    #4
  5. rolandganter

    Jeff Mishler Guest

    Hi Joe,
    Thanks for the heads-up on the names,. However, checking the names in
    2002 I get:
    _$
    _1_$ (vla-get-name blk)
    "*Model_Space"
    _1_$ (vla-get-name blk)
    "*Paper_Space"
    _1_$

    Now it very well could be different in other releases so I will adjust
    the code to allow for that. As for the xref's, you are absolutely
    correct! I didn't even think of them........

    Revised code follows,
    Jeff

    (defun block_color_fix (/ blks doc blk ent)
    (setq blks (vla-get-blocks
    (setq doc (vla-get-activedocument
    (vlax-get-acad-object)))))
    (vla-startundomark doc)
    (vlax-for blk blks
    (if (and (not (wcmatch (strcase (vla-get-name blk))
    "*MODEL*,*PAPER*,*|*"))
    (= (vla-get-isxref blk) :vlax-false)
    )
    (progn
    (vlax-for ent blk
    (vla-put-color ent 256)
    )
    )
    )
    )
    (vla-regen doc acActiveViewport)
    (vla-endundomark doc)
    )
    (defun c:BFX () (block_color_fix)(princ))
     
    Jeff Mishler, Feb 11, 2004
    #5
  6. rolandganter

    Joe Burke Guest

    Hi Jeff,

    I'm using A2k2 as well.

    Apparently those names are either title case or upper case. In the files I'm working
    on now it's upper case. Looked at a few others and it's title case.

    Good fix... something I'll keep in mind in the future.

    Joe Burke
     
    Joe Burke, Feb 12, 2004
    #6
  7. rolandganter

    Joe Burke Guest

    Hi Jeff,

    A little more info on the model and paper space block names. Take a look at developer
    docs under ActiveX and VBA Reference > Objects > Block Object. Seems to indicate the
    names are intended to be upper case. So maybe the title case condition is from some
    version prior to A2k2?

    Question on another topic, which your code demonstrates at the nested vlax-for
    function. My understanding of vlax-for is it operates on a collection. I think I
    understand what I'll call the "primary" collections fairly well, blocks, layers,
    textstyles, etc. But as I read/understand your code, you are using vlax-for on a
    block definition within the blocks collection.

    If I'm right about that, then a block definition within the blocks collection is also
    considered a collection. And if that's true, are there other types of objects
    contained within collections which might be thought of as a "sub-collection" within a
    "primary" collection? For instance, a group object within the groups collection.

    Or maybe I'm really dumb and I don't understand collections at all. Or maybe I don't
    understand vlax-for. Whatever, there's clearly a hole in my head which needs to be
    plugged. :)

    Please anyone, feel free to educated me. I've perused the docs. I must be missing
    something important.

    Thanks
    Joe Burke
     
    Joe Burke, Feb 12, 2004
    #7
  8. #1 It is best to assume nothing when doing a string comparison.

    #2 There *are* collections within collections. Look at the Object Model map
    in the ActiveX Reference. Note the _shapes_ of the labels on the map. A
    rectangle indicates a collection, and note that a Block object is indeed a
    collection.

    --
    R. Robert Bell, MCSE
    www.AcadX.com


    Hi Jeff,

    A little more info on the model and paper space block names. Take a look at
    developer
    docs under ActiveX and VBA Reference > Objects > Block Object. Seems to
    indicate the
    names are intended to be upper case. So maybe the title case condition is
    from some
    version prior to A2k2?

    Question on another topic, which your code demonstrates at the nested
    vlax-for
    function. My understanding of vlax-for is it operates on a collection. I
    think I
    understand what I'll call the "primary" collections fairly well, blocks,
    layers,
    textstyles, etc. But as I read/understand your code, you are using vlax-for
    on a
    block definition within the blocks collection.

    If I'm right about that, then a block definition within the blocks
    collection is also
    considered a collection. And if that's true, are there other types of
    objects
    contained within collections which might be thought of as a "sub-collection"
    within a
    "primary" collection? For instance, a group object within the groups
    collection.

    Or maybe I'm really dumb and I don't understand collections at all. Or maybe
    I don't
    understand vlax-for. Whatever, there's clearly a hole in my head which needs
    to be
    plugged. :)

    Please anyone, feel free to educated me. I've perused the docs. I must be
    missing
    something important.
     
    R. Robert Bell, Feb 12, 2004
    #8
  9. rolandganter

    Joe Burke Guest

    Robert,

    Maybe I'm getting it now, though I'm not entirely sure. Seems I need to pay more
    attention to the legend at the bottom of the Object Model diagram, as you said.

    Still on the up side of the leaning curve. Though hopefully quick to take a hint.

    Thanks
    Joe Burke
     
    Joe Burke, Feb 12, 2004
    #9
  10. rolandganter

    rolandganter Guest

    I just wanted to thank everybody for their help. Jeff, your routine solved my problem nicely. By the way, in one or two of the drawings I got this error message: "Initializing...lisp value has no coercion to VARIANT with this type: 256". I'm not sure why this happens.
    Thanks again.
    Roland
     
    rolandganter, Feb 16, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.