乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 168|回复: 13

Rename Block on Insert?????

[复制链接]

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2005-3-14 17:56:50 | 显示全部楼层 |阅读模式
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
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2005-3-14 18:13:27 | 显示全部楼层
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.
回复

使用道具 举报

14

主题

194

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
250
发表于 2005-3-14 18:38:30 | 显示全部楼层
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.
回复

使用道具 举报

14

主题

194

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
250
发表于 2005-3-14 18:50:49 | 显示全部楼层
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
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2005-3-14 20:31:14 | 显示全部楼层

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:
  1. 'NOTE that this is just sample coding that lacks any style, formatting, error checking or correctness.
  2. 'It is merely for the ideas...
  3. bname = utility.getstring(vbcr & "Block to insert: ")
  4. bscale = utility.getreal(vbcr & "Value to scale the block: ")
  5. 'Now check whether the block has already been placed:
  6. dim oBlock as AcadBlock
  7. On error reume next
  8. Set oBlock = thisdrawing.blocks.item(bname & "-" & bscale)
  9. If Err then
  10.   set oBlock = ThisDrawing.Blocks.Add(bname & "-" & bscale)
  11.   err.clear
  12.   Set oLayer = ThisDrawing.Layers.Add(the desired new layer....)
  13. '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)
  14. End If
  15. 'Now insert the new block as desired on the layer desired.

Is THAT somewhat close to what you are thinking of?
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2005-3-15 09:09:18 | 显示全部楼层
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
  1. Sub LegendLayers()
  2. Dim BlkRef As AcadBlockReference
  3. Dim layer As AcadLayer
  4. Dim layers As AcadLayers
  5. Set layers = ThisDrawing.Layers
  6. On Error Resume Next
  7. For Each BlkRef In ThisDrawing.ModelSpace
  8. 'Use the scale factor of the inserted block to suffix the existing layer names
  9. 'Legend Blocks Layers
  10. For Each layer In layers
  11.    Select Case layer.Name
  12.      Case Is = ("BA-SYMB")
  13.        layer.Name = ("BA-SYMB") & "-" & BlkRef.XScaleFactor
  14.      Case Is = ("CA-SYMB")
  15.        layer.Name = ("ADT-CA-SYMB") & "-" & BlkRef.XScaleFactor
  16.      Case Is = ("D-SYMB")
  17.        layer.Name = ("D-SYMB") & "-" & BlkRef.XScaleFactor
  18.      Case Is = ("FA-SYMB")
  19.        layer.Name = ("FA-SYMB") & "-" & BlkRef.XScaleFactor
  20.      Case Is = ("I-SYMB")
  21.        layer.Name = ("I-SYMB") & "-" & BlkRef.XScaleFactor
  22.      Case Is = ("TV-SYMB")
  23.        layer.Name = ("TV-SYMB") & "-" & BlkRef.XScaleFactor
  24. 'Text Layers
  25.      Case Is = ("BA-SYMB-TEXT")
  26.        layer.Name = ("BA-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
  27.      Case Is = ("CA-SYMB-TEXT")
  28.        layer.Name = ("CA-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
  29.      Case Is = ("D-SYMB-TEXT")
  30.        layer.Name = ("D-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
  31.      Case Is = ("FA-SYMB-TEXT")
  32.        layer.Name = ("FA-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
  33.      Case Is = ("I-SYMB-TEXT")
  34.        layer.Name = ("I-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
  35.      Case Is = ("TV-SYMB-TEXT")
  36.       layer.Name = ("TV-SYMB-TEXT") & "-" & BlkRef.XScaleFactor
  37.    End Select
  38.   Next
  39. Next
  40. End Sub
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2005-3-15 10:03:59 | 显示全部楼层
You want to rename your layers, insert your blocks as xrefs, change the name and insert it again. Each layer will have a different name.
回复

使用道具 举报

14

主题

194

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
250
发表于 2005-3-15 10:11:23 | 显示全部楼层
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
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2005-3-15 10:13:05 | 显示全部楼层
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
回复

使用道具 举报

14

主题

194

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
250
发表于 2005-3-15 10:57:34 | 显示全部楼层
(command "rename" oldname newname)
sendcommand rename etc.
Then insert the block again and rename again.
would either of those work?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-16 22:11 , Processed in 0.973482 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表