AnsweredAssumed Answered

First Macro - Insert BOM API

Question asked by David Dickens on Jul 28, 2017
Latest reply on Aug 3, 2017 by Deepak Gupta

Hi Everyone!!!!

I thank you all in advance for all your comments and help.

I started here where I was inquiring in another's thread about adding blank rows to a BOM (to be filled in with shop supply items later.  Long and short of this is that we heavily use the routing tool here at work in which we use the "identify spools" feature that consumes the model and would have required me to insert quite a few of the virtual dummy parts etc etc etc.  I just didn't find a feasible way to make actual modeling work without more work than it should be which brought me back to the BOM and just wanting to add these two rows of parts that go into everything we do.  Mr Deepak Gupta offered up some suggestions, one of which was a macro for parts but since I had determined the modeling route would have taken more steps than necessary I decided to explore using a macro to just insert and manipulate the BOM to add my two rows Mr. Gupta also said should work for me. And here I am.  I read up some on macros and saw some others trying to do similar things and also saw some of the trouble they were having so I am going to start small and cross the first bridge of just being able to get the macro to insert my BOM.  I found another thread that someone had some code inserting a BOM that worked so I copied it since I could not get my recorded macro to work.  My recorded macro did not have a quarter of the lines this other one did.  So I copied it, tweaked it a little and it inserts a BOM.  Hurray!!!   But......... it doesn't insert my BOM template and not at the anchor point.  It appears to insert a generic three column template.  Not sure if the line pointing to the server location for the template isn't enough and its defaulting or what.  So that is my first hurdle.  To get it to insert my BOM, at the anchor point.  Any help you all can offer as to what I need to fix in order to get my template to insert will be greatly appreciated!!!            CODE BELOW FOR SCREWTENIZING



Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeatMgr As SldWorks.FeatureManager
Dim swView As SldWorks.View
Dim swBomAnn As BomTableAnnotation
Dim swBomFeat As SldWorks.BomFeature
Dim anchorType As Long
Dim bomType As Long
Dim configuration As String
Dim tableTemplate As String
Dim Names As Variant
Dim visible As Variant
Dim boolStatus As Boolean
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As SldWorks.Sheet

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeatMgr = swModel.FeatureManager
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet

'Select View
swModel.ClearSelection2 True
Set swView = swDraw.GetCurrentSheet.GetViews()(0)



'Insert BOM Table
tableTemplate = "" ' "\P:\Engineering\Templates\CryoWorks_ASM_BOM REV C.sldbomtbt"
anchorType = SwConst.swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopRight
bomType = SwConst.swBomType_e.swBomType_Indented

swModel.ClearSelection2 True

configuration = "" '"Default"


Set swBomAnn = swView.InsertBomTable2(False, 0, 0, anchorType, bomType, configuration, tableTemplate)
Set swBomFeat = swBomAnn.BomFeature
Names = swBomFeat.GetConfigurations(False, visible)
visible(0) = True
boolStatus = swBomFeat.SetConfigurations(True, visible, Names)





End Sub