Author Topic: reset each block definition objects' color from ByLayer To ByBlock  (Read 3506 times)

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
as the title says, I just want to reset block definitions where the objects are set to ByLayer to be ByBlock. I was going to put this in my startup, but I wanted to see if anyone saw an issue with the code...

Code: [Select]
  (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
    (if (not (or (wcmatch (vla-get-name block) "`**")
                 (eq (vla-get-isxref block) :vlax-true)
             )
        )
      (vlax-for x block
        (if (eq (vla-get-color x) 256)
          (vla-put-color x 0)
        )
      )
    )
  )
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #1 on: April 16, 2014, 09:51:07 AM »
I assume you're trying to omit the unnamed blocks of model/paper space / dimensions / mtext / etc. with that "`**" wildcard. Note though it's also going to miss out any annotative- and dynamic blocks. But I think you should be all-right ... AFAICR the vla-put-color "should" update all the variants of DB's (and probably anno blocks too).

One thing I might be a bit concerned about: blocks inside xrefs. Does the isxref return true for these definition also?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #2 on: April 16, 2014, 10:07:42 AM »
I assume you're trying to omit the unnamed blocks of model/paper space / dimensions / mtext / etc. with that "`**" wildcard. Note though it's also going to miss out any annotative- and dynamic blocks. But I think you should be all-right ... AFAICR the vla-put-color "should" update all the variants of DB's (and probably anno blocks too).
I was thinking about Dimensions, Model/paperspace, and anonymous blocks (not real important), but I didn't think about Dynamic blocks, but I was thinking the actual definition of the block would include all objects (all visibility states, etc.).
As far as annotative blocks go, I didn't realize they had "`**" matching definition. I would still think they'd operate under the same principal as my thoughts on dynamic blocks.

One thing I might be a bit concerned about: blocks inside xrefs. Does the isxref return true for these definition also?
This I do not know.

I'll have to research this.
Thank you, irneb.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #3 on: April 16, 2014, 10:24:30 AM »
I would still think they'd operate under the same principal as my thoughts on dynamic blocks.
Yep, that's my understanding also. I'm not entirely sure if they only make anonymous blocks if the fidelity thing is turned on. But from past experience they do this too. And I've also found some strange things happening if you directly modify them. But as stated, I've found that using ActiveX on the original definition tends to work reasonably. Though in one case I have found that adjusting some DB's needed a BEdit + BSave + BClose to make them update properly.

This I do not know.

I'll have to research this.
Thank you, irneb.
I think it might error, but that's circumventable also  :wink:

Anyhow, you're welcome. Hope it helps a bit.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Jeff H

  • Needs a day job
  • Posts: 6144
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #4 on: April 16, 2014, 10:58:34 AM »
Annotative blocks do not create anonymous blocks.

Wait do you mean saving drawing with annotative blocks to 2007 or earlier?

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #5 on: April 16, 2014, 11:04:02 AM »

This I do not know.

I'll have to research this.
Thank you, irneb.
I think it might error, but that's circumventable also  :wink:
I ran it on a drawing with xrefs and it never errored or did anything strange to the drawing. I'd still like to do a data dump to make sure. TBH, I was under the impression that an xref wouldn't bring in all it's block definitions.

I'll play with the dynamic blocks (we use very few). This was more about fixing a bunch of storm/sewer structure blocks.

It's a huge help. As always, I appreciate your council and time.

Annotative blocks do not create anonymous blocks.

Wait do you mean saving drawing with annotative blocks to 2007 or earlier?
I didn't think so. Thank you. And no, I'm not saving anything down. Hell, with my new machine, I only have access to c3d 2013.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Jeff H

  • Needs a day job
  • Posts: 6144
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #6 on: April 16, 2014, 11:15:53 AM »
I have something similar but opposite where changes to bylayer, and works fine for dynamic blocks because the dynamic block definition keeps a collection of the anonymous blocks created from it, and when modified will use new definition to recreate anonymous blocks.


I also changed entities to layer 0 and had to add option to skip frozen and nonplot layers but you would not have that problem.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #7 on: April 16, 2014, 11:47:12 AM »
Maybe add a check for attributes too  :)
Code: [Select]
(vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
  (if (not (or (wcmatch (vla-get-name block) "`**") (eq (vla-get-isxref block) :vlax-true)))
    (vlax-for x block
      (if (eq (vla-get-color x) 256)
(vla-put-color x 0)
      )
      (if
(and (= (vla-get-objectname x) "AcDbBlockReference") (minusp (vlax-get x 'hasattributes)))
(foreach att (vlax-invoke x 'getattributes)
   (if (eq (vla-get-color att) 256)
     (vla-put-color att 0)
   )
)
      )
    )
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #8 on: April 16, 2014, 12:18:43 PM »
Ohhh, good catch, Ron.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7526
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #9 on: April 16, 2014, 02:33:00 PM »
 :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #10 on: April 16, 2014, 02:37:35 PM »
What about the "SEQEND" entity?

When an attributed block is inserted in BricsCAD the AcDbSequenceEnd object will have the same layer as the AcDbBlockReference it belongs to. But if you then change the layer of the AcDbBlockReference the layer of the AcDbSequenceEnd does not change. This can be confusing if you are trying to purge a layer. But this may be a BricsCAD bug.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #11 on: April 16, 2014, 02:43:48 PM »
... The same problem applies to the color property but is then not a big issue I guess. :-D

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #12 on: April 16, 2014, 04:23:04 PM »
Annotative blocks do not create anonymous blocks.

Wait do you mean saving drawing with annotative blocks to 2007 or earlier?
Must've been an older ACad when I saw this. Come to think of it ... was in 2008, so I guess it was due to saving back to 2007 format as there was no 2008 format.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: reset each block definition objects' color from ByLayer To ByBlock
« Reply #13 on: April 16, 2014, 05:17:02 PM »
Annotative blocks do not create anonymous blocks.

Wait do you mean saving drawing with annotative blocks to 2007 or earlier?
Must've been an older ACad when I saw this. Come to think of it ... was in 2008, so I guess it was due to saving back to 2007 format as there was no 2008 format.
That must have been confusing, given that you would have a 2007 format drawing, and 2008 would allow you to create annotative objects.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox