My goal is to take a part and save many slices of it as images to use in a 3D visualization program. The way I do that now is to use 2 Section Views to show a very thin slice, then I save that slice as a .jpg file with a number as a name (000 up to however many slices there are). I have to do this manually for each slice (usually 200+) and I'd like to use a macro. I'm not even sure if it is possible to create a macro that changes the section view, because the one I recorded just ignores all the section view commands. I have no problem with saving the .jpgs under the correct filenames, nor is there a problem with determining the dimensions of the slice to be used. The only problem is getting the macro to actually change the section view before saving the .jpg. Can anyone lend any insight? I'm using SW 2011 on a Mac that is running a PC Parallel Desktop version of Windows 7 (It was the only machine available that had Solidworks). And if there is any relevant info that I left out, please let me know. Thanks!
Here's my code:
Sub main()
Set swApp = _ Application.SldWorks
Set Part = swApp.ActiveDoc
Dim length As Double
Dim index As Integer
index = 0
'create slices from 47.6 mm down to 0
For length = 47.6 To 0 Step -0.1
'add the correct number of zeroes to the beginning of the .jpg name
If index < 10 Then
longstatus = Part.SaveAs3("\\psf\Home\Desktop\Kevin\block_auto\00" + CStr(index) + ".JPG", 0, 0)
ElseIf index < 100 Then
longstatus = Part.SaveAs3("\\psf\Home\Desktop\Kevin\block_auto\0" + CStr(index) + ".JPG", 0, 0)
Else
longstatus = Part.SaveAs3("\\psf\Home\Desktop\Kevin\block_auto\" + CStr(index) + ".JPG", 0, 0)
End If
'create the section views
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, True, 2, Nothing, 0)
Dim sViewData As Object
Set sViewData = Part.ModelViewManager.CreateSectionViewData()
Set sViewData.FirstPlane = Nothing
sViewData.FirstReverseDirection = False
sViewData.FirstOffset = length
sViewData.FirstRotationX = 0
sViewData.FirstRotationY = 0
sViewData.FirstColor = 16711680
Set sViewData.SecondPlane = Nothing
sViewData.SecondReverseDirection = True
'Make the slices 0.1 mm thick
sViewData.SecondOffset = length - 0.1
sViewData.SecondRotationX = 0
sViewData.SecondRotationY = 0
sViewData.SecondColor = 65280
sViewData.ShowSectionCap = True
boolstatus = Part.ModelViewManager.CreateSectionView(sViewData)
Part.ClearSelection2 True
'advance the name of the .jpg file
index = index + 1
Next
End Sub