Jump to content

Recommended Posts

Posted

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.

 

Thanks.

 

Sample Code.jpg

Posted

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
Next

End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...