I think i have a strange one here, I'm bringing a BOM into an assy drawing using the TopLevelOnly setting. My "new" BOM works in the drawing perfecly. In my code I bring in the same BOM template and it does not always work. In the code I know the config name and have verified that the macro has the correct config. But on some top level drawings it is not populating the BOM, I get just the headers.
' This section adds the BOM to the Drawing
'
Dim longstatus As Long, longwarnings As Long
Set swApp = Application.SldWorks
Dim swSelMgr As SldWorks.SelectionMgr
Dim swBomTable As SldWorks.BomTableAnnotation
Dim swView As SldWorks.View
Dim vPickPt As Variant
Dim strConfigName As String
Set swSelMgr = swModel.SelectionManager
Set swView = swSelMgr.GetSelectedObject5(1)
Debug.Print swView.ReferencedConfiguration
strConfigName = swView.ReferencedConfiguration
' Debug.Print strConfigName
MsgBox strConfigName
vPickPt = swSelMgr.GetSelectionPoint(1)
If Matl = "304SS" Then
Set swBomTable = swView.InsertBomTable2( _
False, _
vPickPt(0), vPickPt(1), _
swBOMConfigurationAnchorType_e.swBOMConfigurationAnchor_TopLeft, _
swBomType_e.swBomType_TopLevelOnly, _
strConfigName, "C:\\SolidWorks Data\\Fontaine\\Macro\\Outils\\Tools\\VM-XML-BOM-304.sldbomtbt"): Debug.Assert Not swBomTable Is Nothing
End If
SolidworksApi macros
Can you delete the BOM with the header only added by the macro and manually add the BOM?
On the BOM that just have the header, can you manually go into the properties of it to get it to appear properly?
In the two screen shots attached earlier the tree is a little different at the Configurations section. In the files that do not work correctly the configuration is uncheck and on the ones that work the box is a drop down and the BOM is linked to the config correctly. I even created a new drawing from one of these non-woring assembly models and it does the same thing.
Thanks for any help you can provide
Tom
From the API help file under remarks
If BomType is swBomType_TopLevelOnly, then do not specify Configuration. Instead, use IBomFeature::GetConfigurations or IBomFeature::IGetConfigurations and IBomFeature::SetConfigurations or IBomFeature::ISetConfigurations to work with configurations in BOM tables.
I am not sure exactly what they are saying, but will look into it when I have time.
Does the one on the right have multiple configurations? Do all the ones that fail only have one configuration?
Hi Wayne,
Thanks for your help, it is very much appreciated.
The two different screen shots are from two different assembly models. They both have sub-assemblies below them and they both only have one configuration name (& it's not default).
I'm trying to follow the information that you gave me but SW documentation is very vague and is not always very helpful for the beginner programmer. It's still not clear to me how to get the config which I already know the name to be the used in the BOM.
By the writing in the help I would expect that all BOM's would fail since I use TopLevel for all.
Thanks again,
Tom
Wayne,
You pointed me in the right direction once again. I was able to get this piece of the code working. This was the biggest and most difficult program I've done to date. Hopefully they start getting a little easier.
Thanks again,
Tom
Glad I could help.
What did you do to get it working?
Wayne,
Sorry I did not back to you sooner been out of work to have a minor procedure taken care of. I'm back now though.
I had a few "little" things to address on this program/problem.
1. the two different screen shots where I was questioning why I had a dropdown in one and a checkbox in another was a setting change in the options. That was a big part of the problems.
2. I needed to figure out how to pass the config name into the settings. When using TopLevel seeting you cannot pass the name into the insert command you have to change it later.
Now it's on to sorting the BOM by Item number rather than insert in Assembly order.
Thanks again for your help.
Tom,
Thanks for the update.
If you are using SolidWorks 2012 you can use this sample from the API help file. Previous versions of SolidWorks you will have to use a brute force method and do all the work yourself.
http://help.solidworks.com/2012/English/api/sldworksapi/Sort_Table_Example_VB.htm