TheSwamp

Code Red => VB(A) => Topic started by: ELOQUINTET on August 11, 2008, 01:24:03 PM

Title: Block definiton already exists
Post by: ELOQUINTET on August 11, 2008, 01:24:03 PM
Hey guys,

I create and manage my company's block library and have discovered a need for a routine that I can embed in my drawing that would alert me if a block is introduced that has the same name as one that exists in the drawing. I have a routine that works but it does not work on nested blocks so that is what I need to add to it. Can someone help me add this?
Title: Re: Block definiton already exists
Post by: Keith™ on August 11, 2008, 01:43:44 PM
do you want to find nested blocks in the inserted object or nested blocks existing in the drawing?
Title: Re: Block definiton already exists
Post by: ELOQUINTET on August 11, 2008, 02:21:40 PM
Basically I want to prevent blocks that I bring into a drawing by any means (pasting, inserting, etc.) from being redefined so I think I would need to look at both. I will eventually insert all blocks existing in the drawing. I need to look through the entire block library and it would tell me that the definiton already exists. Thanks
Title: Re: Block definiton already exists
Post by: Bob Wahr on August 14, 2008, 05:35:31 PM
Just so you know, this isn't being ignored.  I'm pretty busy but am thinking on it.

You could use the object modified event and redefine it back but then when you redefine it modifies it again.  In semi-pseudo code form

public moddedyet as boolean

if moddedyet = false then
  if typeof objectmodified is iacadblockreference then (i think iacadblockreference is right)
    if objectmodified.name = "whatever" then
      redefine the block
      moddedyet = true
    end if
  end if
else
  moddedyet = false
end if

the problem is that I think it will run once for each instance of the block

I need to figure out a clean way to do this without going into an endless loop.  maybe do a public integer countdown.  It would be ugly as hell but might work for you. sorta

public moddedyet as boolean
public moddedback as boolean
public bunchesofem as integer

if moddedback = true then
  if bunchesofem = 0 then
    moddedback=false
  else
    bunchesofem = bunchesofem - 1
  end if

  if moddedyet = false then
    if typeof objectmodified is iacadblockreference then (i think iacadblockreference is right)
      if objectmodified.name = "whatever" then
        selection set of that block reference
        bunchesofem = selectionset.count
        moddedyet = true
      end if
    end if
  else
    if bunchesofem = 0 then
      redefine block
      moddedyet = false
      moddedback = true
      selection set of block references again
      bunchesofem = selectionset.count
    else
      bunchesofem = bunchesofem - 1
    end if
  end if
end if
Title: Re: Block definiton already exists
Post by: ELOQUINTET on August 18, 2008, 01:04:26 PM
Thanks Bob. This is not a pressing need but is something that would be very useful for me (and others I think). I'm glad it hasn't slipped through the cracks.
Title: Re: Block definiton already exists
Post by: Bob Wahr on August 18, 2008, 04:24:55 PM
I've been ridiculously, crazy busy the last few days.  I had a thought sometime either Friday or this weekend on a way to simplify it although it is gone from my head right now.  Hopefully it will come back to me when I've got a few minutes to devote to it.
Title: Re: Block definiton already exists
Post by: ELOQUINTET on August 22, 2008, 04:16:08 PM
I know the feeling. I think this sort of thing would be useful to many so I'm kind of surprised that someone has not developed something similar already. Anyway thanks for the thought.
Title: Re: Block definiton already exists
Post by: Bob Wahr on August 22, 2008, 04:23:49 PM
To me it's an abomination of a sort that should never exist.  I hate the very concept of programs that block me from doing what I need to do.  I think it is far better to have a properly trained and competent staff that won't incorrectly redefine blocks, or whatever else.  That won't stop me from helping, just had to soapbox it a little.
Title: Re: Block definiton already exists
Post by: rogue on August 25, 2008, 06:07:36 AM
From experience, Ive learned not to try and idiot-proof code. They come out with new versions of idiots faster than you can come out with new versions of code. If it was even possible to try and stop every possible way to do things wrong, your code would end up so large, and so slow, that, come the day when a bug finally slips thru, you will be the fall guy for 'allowing' them to ride without training wheels.
Title: Re: Block definiton already exists
Post by: ELOQUINTET on September 03, 2008, 04:42:51 PM
Bob I am mainly using this to protect myself from creating blocks in an external file and bringing them into my block library which may already have a block by that name and having them redefined without notifying me. I am producing massive block libraries and some of the graphics and block names are so similar that it is very easy for me to duplicate names if i'm not careful and hard for me to tell that my new block has been redefined. I am also dealing with legacy blocks that were not created by me and all of these blocks do not adhere to current naming conventions so it can be very tricky when the two mingle in a drawing. The block name is key because it ties into a database and is extracted for creating cost reports and other stuff. Does that explain it better?
Title: Re: Block definiton already exists
Post by: Bob Wahr on September 03, 2008, 05:38:24 PM
yeah, it does.  Things have slowed down a bit.  Let me think on it some.  I have a tendency to let the whatifs get out of control and the logic gets spotty.