wharris1996 发表于 2022-7-6 21:47:41

移动命令错误

您好,我正在尝试做一个脚本,将为我移动项目。我正在导入2到9个图形作为外部参照,然后运行此VBA脚本,根据图纸编号将它们移动到预定义的位置,以进行布局设置。脚本可以很好地读取名称并说明问题,但它在move命令上返回运行时错误5,我不知道为什么。任何帮助都将不胜感激。
 
谢谢
 

wharris1996 发表于 2022-7-6 23:34:25

抱歉,没有看到代码格式准则:
 

Sub DWG_Combine()
'On Error Resume Next
'Reads number of objects, moves them based on name, then creates layouts. Finally, explodes all for editing
Dim i, NumObj, ObjID As Integer
Dim SS1 As AcadSelectionSet
Dim MspaceObj As AcadObject
Dim p1(0 To 2), p2(0 To 2) As Double

'set p1 as origin
p1(0) = 0: p1(1) = 0: p1(2) = 0

'selection set?
If Err.Number <> 0 Then
   Set SS1 = ThisDrawing.SelectionSets.Add("SS1")
End If

'Counts number of objects
NumObj = ThisDrawing.ModelSpace.Count
'MsgBox NumObj


i = 0

'Cycles through each item in the modelspace, reads the ID number, and moves a multiple of the ID Number
For Each Item In ThisDrawing.ModelSpace
   Set MspaceObj = ThisDrawing.ModelSpace.Item(i)
   'MsgBox MspaceObj.EffectiveName
   ObjID = Left(Right(MspaceObj.EffectiveName, 2), 1)
   'MsgBox objID
   p2(0) = (ObjID - 1) * 45: p2(1) = 0: p2(2) = 0
   MspaceObj.Move p1, p2
   i = i + 1
Next

End Sub
页: [1]
查看完整版本: 移动命令错误