乐筑天下

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

[编程交流] 移动命令错误

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 21:47:41 | 显示全部楼层 |阅读模式
您好,我正在尝试做一个脚本,将为我移动项目。我正在导入2到9个图形作为外部参照,然后运行此VBA脚本,根据图纸编号将它们移动到预定义的位置,以进行布局设置。脚本可以很好地读取名称并说明问题,但它在move命令上返回运行时错误5,我不知道为什么。任何帮助都将不胜感激。
 
谢谢
 
224745egnd7xxqd22xymz4.jpg
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 23:34:25 | 显示全部楼层
抱歉,没有看到代码格式准则:
 
  1. Sub DWG_Combine()
  2. 'On Error Resume Next
  3. 'Reads number of objects, moves them based on name, then creates layouts. Finally, explodes all for editing
  4. Dim i, NumObj, ObjID As Integer
  5. Dim SS1 As AcadSelectionSet
  6. Dim MspaceObj As AcadObject
  7. Dim p1(0 To 2), p2(0 To 2) As Double
  8. 'set p1 as origin
  9. p1(0) = 0: p1(1) = 0: p1(2) = 0
  10. 'selection set?
  11. If Err.Number <> 0 Then
  12.    Set SS1 = ThisDrawing.SelectionSets.Add("SS1")
  13. End If
  14. 'Counts number of objects
  15. NumObj = ThisDrawing.ModelSpace.Count
  16. 'MsgBox NumObj
  17. i = 0
  18. 'Cycles through each item in the modelspace, reads the ID number, and moves a multiple of the ID Number
  19. For Each Item In ThisDrawing.ModelSpace
  20.    Set MspaceObj = ThisDrawing.ModelSpace.Item(i)
  21.    'MsgBox MspaceObj.EffectiveName
  22.    ObjID = Left(Right(MspaceObj.EffectiveName, 2), 1)
  23.    'MsgBox objID
  24.    p2(0) = (ObjID - 1) * 45: p2(1) = 0: p2(2) = 0
  25.    MspaceObj.Move p1, p2
  26.    i = i + 1
  27. Next
  28. End Sub
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 14:54 , Processed in 0.366761 second(s), 59 queries .

© 2020-2025 乐筑天下

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