smma
Mechanical
- Jun 4, 2007
- 24
I am attempting to insert a Bill of Materials using a specific table template into a Solidworks drawing via API. My macro so far is thus:
Sub Macro2()
Dim BomTable As Object
Dim BomFeat As Object
Dim Names As Variant
Dim Visible As Variant
Set swApp = CreateObject("SldWorks.Application")
Set Drawing = swApp.ActiveDoc
Set View = Drawing.GetFirstView 'This is the sheet
Set View = View.GetNextView 'This is the first actual view
Filepath = "W:\BLOCKS\Solidworks Templates\Other\HTC BOM.sldbomtbt"
Set BomTable = View.InsertBomTable2(True, 0, 0, swBOMConfigurationAnchor_TopRight, _
swBomType_TopLevelOnly, "", Filepath)
Set BomFeat = BomTable.BomFeature
Names = BomFeat.GetConfigurations(False, Visible)
Visible(0) = True
boolstatus = BomFeat.SetConfigurations(True, Visible, Names)
Drawing.FeatureManager.UpdateFeatureTree
End Sub
The other thing about this macro is that it is embedded in a button in an Excel sheet, if that is a factor. When I try to run this macro, it hangs up at the line "Set BomFeat..." with an error stating that the object variable is not set. What am I missing here? I have used the examples given in the Solidworks API help to make this macro, and it doesn't seem to follow through. Any suggestions?
Sub Macro2()
Dim BomTable As Object
Dim BomFeat As Object
Dim Names As Variant
Dim Visible As Variant
Set swApp = CreateObject("SldWorks.Application")
Set Drawing = swApp.ActiveDoc
Set View = Drawing.GetFirstView 'This is the sheet
Set View = View.GetNextView 'This is the first actual view
Filepath = "W:\BLOCKS\Solidworks Templates\Other\HTC BOM.sldbomtbt"
Set BomTable = View.InsertBomTable2(True, 0, 0, swBOMConfigurationAnchor_TopRight, _
swBomType_TopLevelOnly, "", Filepath)
Set BomFeat = BomTable.BomFeature
Names = BomFeat.GetConfigurations(False, Visible)
Visible(0) = True
boolstatus = BomFeat.SetConfigurations(True, Visible, Names)
Drawing.FeatureManager.UpdateFeatureTree
End Sub
The other thing about this macro is that it is embedded in a button in an Excel sheet, if that is a factor. When I try to run this macro, it hangs up at the line "Set BomFeat..." with an error stating that the object variable is not set. What am I missing here? I have used the examples given in the Solidworks API help to make this macro, and it doesn't seem to follow through. Any suggestions?