TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: alanjt on April 16, 2014, 09:42:29 AM

Title: reset each block definition objects' color from ByLayer To ByBlock
Post by: alanjt on April 16, 2014, 09:42:29 AM
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)
        )
      )
    )
  )
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: irneb 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?
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: alanjt 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.
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: irneb 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.
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: Jeff H 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?
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: alanjt 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.
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: Jeff H 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.
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: ronjonp 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)
   )
)
      )
    )
  )
)
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: alanjt on April 16, 2014, 12:18:43 PM
Ohhh, good catch, Ron.
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: ronjonp on April 16, 2014, 02:33:00 PM
 :)
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: roy_043 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.
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: roy_043 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
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: irneb 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.
Title: Re: reset each block definition objects' color from ByLayer To ByBlock
Post by: alanjt 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.