Thanks Tobin. That got me heading in the right direction. The first draft is working now. Needs tidying up and finessing.
' ******************************************************************************
' C:\DOCUME~1\NICKBA~1\LOCALS~1\Temp\swx240\Macro1.swb - macro recorded on 08/06/08 by Nick Banks
' ******************************************************************************
Dim swApp As Object
Dim Part As Object
Dim SelMgr As Object
Dim swView As String
Dim swType As String
Dim swFileName As String
Dim swFilePath As String
Dim swParts(0 To 100) As String
Dim boolstatus As Boolean
Dim Feature As Object
Dim Child As Object
Dim ModDoc As Object
Dim i As Integer
Dim j As Integer
Dim Children As Variant
Dim InfoText As String
Dim swModel As Object
Dim TopAssy As String
Dim longstatus As Long, longwarnings As Long
Dim PosX As Double, PosY As Double
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
TopAssy = swModel.GetPathName
swType = swModel.GetType
If swType = swDocASSEMBLY Then
Set ModelDoc2 = swApp.ActiveDoc
Set Configuration = ModelDoc2.GetActiveConfiguration
Set Component2 = Configuration.GetRootComponent
Set ModDoc = Component2.GetModelDoc
InfoText = ""
Children = Component2.GetChildren()
ChildCount = UBound(Children) + 1
i = 0
Do While i <> ChildCount
Set Component2 = Children(i)
Set ModDoc = Component2.GetModelDoc
swFileName = Component2.Name2
swFilePath = Component2.GetPathName
InfoText = InfoText & "Item " & i & swFilePath & " <" & vbNewLine
swParts(i) = swFilePath
i = i + 1
Loop
MsgBox InfoText, vbOKOnly
i = 0
Do While i <> ChildCount
swFilePath = swParts(i)
' MsgBox ("opening: " & swFilePath)
Set Part = swApp.OpenDoc6(swFilePath, 1, 0, "", longstatus, longwarnings)
swApp.ActiveDoc.ActiveView.FrameLeft = 0
swApp.ActiveDoc.ActiveView.FrameTop = 0
swApp.ActiveDoc.ActiveView.FrameState = 1
swApp.ActiveDoc.ActiveView.FrameState = 1
Set Part = swApp.ActivateDoc2(swFilePath, False, longstatus)
If Part Is Nothing Then
Call MsgBox("Unable to open document!", vbExclamation, "Line3") ' Display error message
End If
i = i + 1
Loop
Set Part = swApp.ActivateDoc2(TopAssy, False, longstatus)
sTemplateName = "\\srv-Lancelot\aardvark\CAD\Templates\Pacer CNC.slddrt"
Set swDrawing = swApp.NewDocument(sTemplateName, swDwgPaperAsize, 0#, 0#)
' display sheet format
Set swNewSheet = swDrawing.GetCurrentSheet
swNewSheet.SheetFormatVisible = True
swDrawing.EditSheet
i = 0
Do While i <> ChildCount
swView = swParts(i)
'MsgBox ("creating view: " & swView)
PosX = 0.3 + (0.2 * i)
PosY = 0.3 + (0.02 * i)
'Create view
DrawView = swDrawing.CreateDrawViewFromModelView(swView, "*Top", PosX, PosY, 0)
'set scale
boolstatus = swNewSheet.SetScale(1, 1, True, True)
i = i + 1
Loop
End If
If swType = swDocPART Then
MsgBox ("Its a part")
End If
End Sub