creating relative view on separate sheets of each body of multibody part

Hi,

I am trying to automatically create drawing document with number of sheets that match number of bodies in multibody part that is active and opened prior to running the macro. Each sheet would contain relative view of one body. What does happen when running macro as shown below, I do get number of sheets but without any models in it (empty template drawing). My guess is that I am missing the command that drops view onto the sheet, therefore please if anyone can take a look and let me know what I am missing here.

Thanks.

' Only precondition for macro is to have multibody part open

Dim swModel as ModelDoc2

Dim pathName As String = ""

Dim swPart as PartDoc = Nothing

Dim swFeature as Feature = Nothing

Dim swBodyFolder as BodyFolder = Nothing

Dim numberOfBodies As Integer = 0

Dim allBodies As Object ' array

Dim swBody As Body2 = Nothing

Dim swDoc As ModelDoc2 = Nothing

Dim bodyName As String = ""

Dim swDrawing As DrawingDoc = Nothing

Dim firstView As View = Nothing

Dim bolBody As Boolean = False

swModel = swApp.ActiveDoc

pathName = swModel.GetPathName ' path name is string value

swPart = swApp.ActiveDoc

If swPart Is Nothing Then

Exit Sub

End If

swModel = swApp.NewDocument("D:\Macros\Macro_A.drwdot", 0, 0.2159, 0.2794) ' opening new drawing document

swFeature = swPart.FirstFeature

Do While Not swFeature.GetTypeName2 = "SolidBodyFolder"

swFeature = swFeature.GetNextFeature

Loop

If swFeature.GetTypeName2 = "SolidBodyFolder" Then

swBodyFolder = swFeature.GetSpecificFeature2

numberOfBodies = swBodyFolder.GetBodyCount

allBodies = swBodyFolder.GetBodies()

For i = 0 To (numberOfBodies - 1)

swBody = allBodies(i) ' swBody is Body2 and allBodies is array of bodies (object)

bodyName = swBody.Name

swDoc = CType(swApp.ActiveDoc, ModelDoc2)

bolBody = swDoc.Extension.SelectByID2(bodyName, "SOLIDBODY", 0.0254, 0.038, 0.1135, True, 0, Nothing, 0)

bolBody = swDoc.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

bolBody = swDoc.Extension.SelectByID2("Right Plane", "PLANE", 0, 0, 0, True, 0, Nothing, 0)

swDrawing = CType(swDoc, DrawingDoc)

firstView = swDrawing.CreateRelativeView(pathName, 0.0972, 0.133, 0, 1)

If i < (numberOfBodies - 1) Then

swDrawing.NewSheet("Sheet" & (i + 2), 0, 0, 0, 0)

End If

Next

End If

SolidworksApi macros