I was wondering if anyone had an example (assuming it is possible) that could rename a block on insert if it sees that the name already exists?
So, the drawing has a block called block1, the user inserts block1 again, the codes sees that block1 already exists and renames the one being inserted to -2 and so on.
Is this possible and does anyone have any examples that I can draw from?
Thank you
Mark
Why in the world would you want to do that? Use invisible attributes in the block if you're using it for some sort of counting function. It would make everyones life easier.
Mark, I've got to agree with Tim.
The whole purpose of having a block is so it can be inserted many times but only take up the space to define it once. By 'renaming' each insert, you would need to copy the block in the block table as the new named block and insert that......do that 50 times and you've got the exact same block defined 50 times in the block table...the only difference being in the names.
Now what if one thing needs to change in the master block? Yep, you gotta go change each one of those blocks with a different name, too.
Hey guys
I can see why that would seem silly at first.
Jeff, you will recall because you helped me work through the code in the previous attempts:
I am inserting a block (at a speciific scale), I want to rename its layers for very specific reason but not necessarily explode it.
I then may want to use the same block again but at a different scale and then rename its layers as well, please don't ask why
As it stands, after I insert the second block, I am asked to redefine the block, after I redefine the block, there becomes a sharing problem with the layers, then layer control becomes impossible.
I inserted the block earlier at 48, ran my macro, it renamed the layers accordingly, I then copied the block, inserted it in, ran my macro and it worked perfectly.
So, without a longer explanation, I will ask again, can this be done?
Thanks again
Mark
Mark, even though I helped in your previous attempts I never was clear on exactly what you were trying to do. I think I may now have a clue
You have BlockA whose entities were created on a specific layer "Layer1".
You now want to have sepearte block definitions based on the block's scale factor with the block's entites to be on the matching layer name, such as BlockA-48 & "Layer1-48".
When you insert this block at 48 scale you first need to see if it exists, if not you need to create the new block by copying the data from the main block, BlockA, while also creating the associated layer(s).
You DON'T want to actually rename the block everytime it's inserted....we already covered that this is not possible.(Not yet anyway, have a look at the specs for R2006......it looks like dynamic blocks may be what you are looking for).
So, to start coding we need to get from the user, or calling function or whereever, the block name to insert and the scale:
'NOTE that this is just sample coding that lacks any style, formatting, error checking or correctness.
'It is merely for the ideas...
bname = utility.getstring(vbcr & "Block to insert: ")
bscale = utility.getreal(vbcr & "Value to scale the block: ")
'Now check whether the block has already been placed:
dim oBlock as AcadBlock
On error reume next
Set oBlock = thisdrawing.blocks.item(bname & "-" & bscale)
If Err then
set oBlock = ThisDrawing.Blocks.Add(bname & "-" & bscale)
err.clear
Set oLayer = ThisDrawing.Layers.Add(the desired new layer....)
'Use the copyobjects method to copy all of the entities from the main block to the new one and change all the entities' layers in the new block to match the new layer(s)
End If
'Now insert the new block as desired on the layer desired.
Is THAT somewhat close to what you are thinking of?
Hey Jeff
I thought that I had e-mailed you my code with an explanation via PM?
I'm sorry I never explained but you are very close.
OK,
THe Block is actually 4 Legends. On each legend are multiple symbols which are also blocks.
Each Block with all of its symbols are on one layer.
Lets say BA-SYMB.
So, I insert the block at 48, I want BA-SYMB to become BA-SYMB-48. It is very simple.
Suppose I insert another one at 96, I then want those layers to be suffixed BA-SYMB-96.
I have the code working real well after the first one is inserted, the problem is after the second one is inserted, all layers are renamed accordingly but because the block has been redefined, all blocks will be controlled by The BA-SYMB-96 layer because that was the last inserted.
I need to be able to freeze blocks on BA-SYMB-48 and on BA-SYMB-96 individually.
The only solutions that come to mind are to either explode on insert or rename the second block which was the reason for this post.
Does this make sense?
Check out the below code
Thanks
Mark
No, that won't work Daron.
The symbols in the legend will be attributed at a later time so I will need to keep them as blocks.
The above code I put together works real well, I just have the feeling i will need to insert as exploded blocks
Thanks
Mark
Actually, that will not work either.
If it is exploded, then the code will fail as it is looking for a blockreference.
This takes me back to the very first question
How can I rename a block upon insertion?
Thank you
Mark