ElevatorJoe
Mechanical
- Apr 24, 2008
- 15
Hi,
I found this example macro in the API help and it does pretty much what I need it to do with the exception of importing the flat pattern view. When I try and type the name of the view in it doesn't work. Any ideas? Here is the code that I have now.
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swFeature As SldWorks.Feature
Dim swSubFeature As SldWorks.Feature
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim bFound As Boolean
Dim vViewNames As Variant
Dim vViewName As Variant
Dim strViewName As String
Dim lNumViews As Long
Dim dSheetScale As Double
Dim vSheetProperties As Variant
Dim nPaperSize As swDwgPaperSizes_e
Dim dWidth As Double
Dim dHeight As Double
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDrawing = swModel
' Get current sheet.
Set swSheet = swDrawing.GetCurrentSheet
vSheetProperties = swSheet.GetProperties
dSheetScale = vSheetProperties(2) / vSheetProperties(3)
nPaperSize = swSheet.GetSize(dWidth, dHeight)
Debug.Print "Sheet scale = " & dSheetScale
Debug.Print "Sheet width = " & dWidth
Debug.Print "Sheet height = " & dHeight
lNumViews = 0
vViewNames = swDrawing.GetDrawingPaletteViewNames
If (Not (IsEmpty(vViewNames))) Then
lNumViews = (UBound(vViewNames) - LBound(vViewNames) + 1)
Debug.Print "Number of views on palette = " & lNumViews
For Each vViewName In vViewNames
strViewName = vViewName
Debug.Print strViewName
If (strViewName = "*Top") Then
Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, 0.175, 0.235, 0#)
Debug.Print " Dropped => " & swView.Name
End If
If (strViewName = "*Isometric") Then
Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, 0.16, 0.11, 0#)
Debug.Print " Dropped => " & swView.Name
End If
If (strViewName = "*Right") Then
Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, 0.125, 0.235, 0#)
Debug.Print " Dropped => " & swView.Name
End If
Next vViewName
End If
End Sub
I found this example macro in the API help and it does pretty much what I need it to do with the exception of importing the flat pattern view. When I try and type the name of the view in it doesn't work. Any ideas? Here is the code that I have now.
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim swFeature As SldWorks.Feature
Dim swSubFeature As SldWorks.Feature
Dim swSheet As SldWorks.Sheet
Dim swView As SldWorks.View
Dim bFound As Boolean
Dim vViewNames As Variant
Dim vViewName As Variant
Dim strViewName As String
Dim lNumViews As Long
Dim dSheetScale As Double
Dim vSheetProperties As Variant
Dim nPaperSize As swDwgPaperSizes_e
Dim dWidth As Double
Dim dHeight As Double
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDrawing = swModel
' Get current sheet.
Set swSheet = swDrawing.GetCurrentSheet
vSheetProperties = swSheet.GetProperties
dSheetScale = vSheetProperties(2) / vSheetProperties(3)
nPaperSize = swSheet.GetSize(dWidth, dHeight)
Debug.Print "Sheet scale = " & dSheetScale
Debug.Print "Sheet width = " & dWidth
Debug.Print "Sheet height = " & dHeight
lNumViews = 0
vViewNames = swDrawing.GetDrawingPaletteViewNames
If (Not (IsEmpty(vViewNames))) Then
lNumViews = (UBound(vViewNames) - LBound(vViewNames) + 1)
Debug.Print "Number of views on palette = " & lNumViews
For Each vViewName In vViewNames
strViewName = vViewName
Debug.Print strViewName
If (strViewName = "*Top") Then
Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, 0.175, 0.235, 0#)
Debug.Print " Dropped => " & swView.Name
End If
If (strViewName = "*Isometric") Then
Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, 0.16, 0.11, 0#)
Debug.Print " Dropped => " & swView.Name
End If
If (strViewName = "*Right") Then
Set swView = swDrawing.DropDrawingViewFromPalette2(strViewName, 0.125, 0.235, 0#)
Debug.Print " Dropped => " & swView.Name
End If
Next vViewName
End If
End Sub