Jump to content

Move Command Error

Recommended Posts


Hello, I am trying to make a script that will move items for me. I am importing anywhere from 2 to 9 drawings as Xrefs, then running this VBA script to move them based on the sheet number to a predefined spot for layout setups. The script is reading the names fine and making the point, but it is returning Runtime Error 5 on the move command, and I am not sure why. Any help would be appreciated.




Sample Code.jpg

Share this post

Link to post
Share on other sites

Sorry didn't see CODE formatting guidelines:


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

End Sub

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now