乐筑天下

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

[编程交流] AutoCAD vba“找不到键”er

[复制链接]

170

主题

347

帖子

174

银币

中流砥柱

Rank: 25

铜币
870
发表于 2022-7-6 14:42:49 | 显示全部楼层 |阅读模式
在AutoCAD 2009 VBA中,“未找到键”是什么意思。我看起来怎么样
对于此错误。
非常感谢。
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 15:05:15 | 显示全部楼层
这通常在例程尝试引用不在相关集合中的命名对象时显示。例如,将对象设置为不存在的图层,或尝试插入名称不属于块表记录的块参照。
回复

使用道具 举报

170

主题

347

帖子

174

银币

中流砥柱

Rank: 25

铜币
870
发表于 2022-7-6 15:24:28 | 显示全部楼层
这是我的密码“
如果你看到问题,请帮助。
 
 
公共子BlkDefAttLayerChg()
Dim objAttribs作为集合
Dim objAttrib作为AcadAttribute
将objBlock设置为AcadBlock
作为字符串的Dim strAttribs
“”获取块
对于此图形中的每个对象块。阻碍
'strBlockList=strBlockList&vbCr&objBlock。名称
'下一个
 
设置objBlock=ThisDrawing。阻碍。项目(objBlock.Name)
“”获取属性
设置objAttribs=GetAttributes(objBlock)
“”显示有关每个
对于objAttribs中的每个objAttrib
'strAttribs=objAttrib。标记字符串和vbCrLf
'strAttribs=strAttribs&“标记:”&objAttrib。标记字符串和vbCrLf&_
'提示:“&objAttrib。PromptString&vbCrLf&“值:”&_
“objAttrib。TextString&vbCrLf&“模式:”&_
“objAttrib。模式
'私有m_AttLayerNameOld As String
'Private m_AttLayerNameNew As String
 
 
“如果是objAttrib。图层m\u AttLayerNameNew Then
objAttrib。Layer=m_AttLayerNameNew'指定新层名称
'其他
“转到NextItem
'如果结束
strattribsl=objAttrib。层
'MsgBox strAttribs
'MsgBox strattribsl
'NextItem:
下一个
下一个
末端接头
函数GetAttributes(objBlock作为AcadBlock)作为集合
出错时继续下一步
Dim objEnt1作为身份
Dim objAttribute为AcadAttribute
Dim coll作为新系列
“”迭代块
对于objBlock中的每个objEnt1
“”如果是属性
如果objEnt1。ObjectName=“AcDbAttributeDefinition”然后
“”强制转换为属性
设置objAttribute=objEnt1
“”将属性添加到集合
科尔。添加objAttribute,objAttribute。标记字符串“***这会导致错误
'coll。添加对象属性
如果结束
下一个
'返回集合
设置GetAttributes=coll
结束函数
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 16:01:50 | 显示全部楼层
我做了一些改变,看看这是否有帮助。
 
有几件事表明,发布的代码依赖于未发布的代码。例如,从未设置用m_AttLayerNameNew引用的层名称。在我发布的代码中,我将其设置为一个测试层,我确保该层在图形中可用。
 
我做的另一个更改是防止例程使用标准AutoCAD blocks Modes\u Space和Paper\u Space运行GetAttributes()函数。
 
  1. Public Sub BlkDefAttLayerChg()
  2. Dim objAttribs As Collection
  3. Dim objAttrib As AcadAttribute
  4. Dim objBlock As AcadBlock
  5. Dim strAttribs As String
  6. Dim m_AttLayerNameNew As String
  7. Dim strattribsl As String
  8. '' get the block
  9.   For Each objBlock In ThisDrawing.Blocks
  10.      
  11.      
  12.      'Set objBlock = ThisDrawing.Blocks.Item(objBlock.Name) ''''not needed
  13.      If InStr(objBlock.Name, "_Space") = 0 Then 'Don't process Model and Paper space blocks
  14.         Set objAttribs = GetAttributes(objBlock)
  15.         '' show some information about each
  16.         For Each objAttrib In objAttribs
  17.         
  18.            'm_AttLayerNameNew = "TestLayer" ''''used for testing.  Layer must be present
  19.      
  20.            objAttrib.Layer = m_AttLayerNameNew ' Assign new layer name
  21.            strattribsl = objAttrib.Layer 'is this needed if it's already set in m_AttLayerNameNew
  22.         Next
  23.      End If
  24.   Next
  25. End Sub
  26. Function GetAttributes(objBlock As AcadBlock) As Collection
  27. On Error Resume Next
  28. Dim objEnt1 As AcadEntity
  29. Dim objAttribute As AcadAttribute
  30. Dim coll As New Collection
  31. '' iterate the block
  32. For Each objEnt1 In objBlock
  33. '' if it's an attribute
  34. If objEnt1.ObjectName = "AcDbAttributeDefinition" Then
  35. '' cast to an attribute
  36. Set objAttribute = objEnt1
  37. '' add attribute to the collection
  38. coll.Add objAttribute, objAttribute.TagString '***This causes the error
  39. End If
  40. Next
  41. 'return collection
  42. Set GetAttributes = coll
  43. End Function
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-5 00:24 , Processed in 0.625141 second(s), 60 queries .

© 2020-2025 乐筑天下

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