乐筑天下

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

2007 和插入块

[复制链接]

18

主题

222

帖子

51

银币

后起之秀

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

铜币
260
发表于 2006-8-7 12:23:00 | 显示全部楼层 |阅读模式
有没有人弄清楚插入块功能在07中是如何变化的? 我一直得到一个文件管理器错误使用此代码
  1. ThisDrawing.PaperSpace.InsertBlock inst, "u:\titleblocks\PP-VTITLINFO.DWG", 1, 1, 1, 0

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-8-7 14:00:39 | 显示全部楼层
据我所知,块插入在2007年没有改变。
文件管理器错误通常指向文件问题,而不是vba问题
我假设您已经检查了路径和块名称
我们在Acad 2000到'2007中运行了一些代码~相同的代码,没有问题
回复

使用道具 举报

18

主题

222

帖子

51

银币

后起之秀

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

铜币
260
发表于 2006-8-7 14:03:10 | 显示全部楼层
它在第一个dwg上工作,然后在之后的每个dwg上崩溃。我尝试过路径、无路径、w/the. dwg和w/o它。它总是在第一个dwg上工作,然后崩溃。
回复

使用道具 举报

18

主题

222

帖子

51

银币

后起之秀

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

铜币
260
发表于 2006-8-7 23:00:18 | 显示全部楼层
不久前,我编写了一些代码来处理块,但后来不需要它并将其删除。我在动态创建块并插入它。我建议您在尝试插入块之前先查看它的实例是否存在
  1. Public Function BlockExists(BlockName As String) As Boolean
  2. Dim oBlock As AcadBlock
  3. Dim thisdrawing As AcadDocument
  4. 'iterate through the Block collection object
  5. Set entity = thisdrawing.Application.ActiveDocument
  6. For Each oBlock In thisdrawing.Blocks
  7. If oBlock.Name Like BlockName & "*" Then
  8. 'found a match, so it exist
  9. BlockExists = True
  10. 'so, exit the function with True
  11. Exit Function
  12. End If
  13. Next oBlock
  14. 'lblock does not exist
  15. BlockExists = False
  16. End Function

小心这行:
如果对象锁定。名称类似于BlockName&“*”,然后<br>要获得精确匹配,请将其修改为:<br>If oBlock。像BlockName这样的名称,然后是“&”*”
上面的代码最初是由Bell,R.Robert在Autodesk论坛上发布的,用于查看是否存在层。我现在为集合集提供了多种风格的代码
一个重要的注意事项是,如果多次使用add方法,如果该方法存在,它将返回当前值,因此您根本不需要检查。我在那里也读到了,但直到我写了一些代码才明白,这样做并没有因为添加了这样存在的层而崩溃
以下是我使用的一些其他方法:
  1. Public Function TextStyleExists(TextStyle As String) As Boolean
  2. Dim oStyle As ACADTextStyle
  3. Dim entity As AcadDocument
  4. 'iterate through the Layers collection object
  5. Set entity = thisdrawing.Application.ActiveDocument
  6. For Each oStyle In entity.TextStyles
  7. If LCase(oStyle.Name) Like LCase(TextStyle) Then '& "*" Then
  8. 'found a match, so it exist
  9. TextStyleExists = True
  10. 'so, exit the function with True
  11. Exit Function
  12. End If
  13. Next oStyle
  14. 'layer does not exist
  15. TextStyleExists = False
  16. End Function
  17. Public Function DimStyleExists(DimStyle As String) As Boolean
  18. Dim oStyle As ACADDimStyle
  19. Dim entity As AcadDocument
  20. 'iterate through the Layers collection object
  21. Set entity = thisdrawing.Application.ActiveDocument
  22. For Each oStyle In entity.DimStyles
  23. If LCase(oStyle.Name) Like LCase(DimStyle) Then '& "*" Then
  24. 'found a match, so it exist
  25. DimStyleExists = True
  26. 'so, exit the function with True
  27. Exit Function
  28. End If
  29. Next oStyle
  30. 'layer does not exist
  31. DimStyleExists = False
  32. End Function
  33. Public Function GroupExists(grpName As String) As Boolean
  34. Dim oGroup As AcadGroup
  35. Dim thisdrawing As AcadDocument
  36. 'Dim entity As AcadDocument
  37. 'iterate through the Layers collection object
  38. Set thisdrawing = AutoCAD_Application.ActiveDocument
  39. For Each oGroup In thisdrawing.Groups
  40. If oGroup.Name Like grpName & "*" Then
  41. 'found a match, so it exist
  42. GroupExists = True
  43. 'so, exit the function with True
  44. Exit Function
  45. End If
  46. Next oGroup
  47. 'layer does not exist
  48. GroupExists = False
  49. End Function
  50. Public Function LayerExists(LayerName As String) As Boolean
  51. Dim oLayer As AcadLayer
  52. Dim entity As AcadDocument
  53. 'iterate through the Layers collection object
  54. Set entity = thisdrawing.Application.ActiveDocument
  55. For Each oLayer In entity.Layers
  56. If oLayer.Name Like LayerName & "*" Then
  57. 'found a match, so it exist
  58. LayerExists = True
  59. 'so, exit the function with True
  60. Exit Function
  61. End If
  62. Next oLayer
  63. 'layer does not exist
  64. LayerExists = False
  65. End Function
  66. Public Function LayerExists2(LayerName As String) As Boolean
  67. Dim oLayer As AcadLayer
  68. Dim entity As AcadDocument
  69. 'iterate through the Layers collection object
  70. Set entity = thisdrawing.Application.ActiveDocument
  71. For Each oLayer In entity.Layers
  72. If oLayer.Name Like LayerName Then '& "*" Then
  73. 'found a match, so it exist
  74. LayerExists2 = True
  75. 'so, exit the function with True
  76. Exit Function
  77. End If
  78. Next oLayer
  79. 'layer does not exist
  80. LayerExists2 = False
  81. End Function

回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-8-8 03:43:30 | 显示全部楼层

您确定是这一行导致了崩溃吗?代码的其余部分是什么?错误是什么?
我们的代码毫无问题地运行了40或50个块插入,本质上与您的代码没有什么不同
(好吧,反正就是那一行)
回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-8-8 09:56:38 | 显示全部楼层
这是模块代码3]
和您一样,我在插入积木时从未遇到过任何问题。当我使用F8单步执行代码时,或者当我让它因出错而中断时,它总是突出显示那一行。它也只有在打开超过1个dwg时才会崩溃。
我将此问题告诉了autodesk,如果他们打开了不止一个dwg,就可以重复出现此问题。他们把它放在发展中,看看发生了什么。
回复

使用道具 举报

12

主题

150

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
198
发表于 2006-9-29 14:30:50 | 显示全部楼层
我仍然没有听到Autodesk的解决方案(大惊喜),但我确实找到了一个持续有效的解决方案。
通过创建变量,它可以一致地工作
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-6 13:04 , Processed in 1.217537 second(s), 66 queries .

© 2020-2025 乐筑天下

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