Thank you forum guys for the help!
I have two issues I don't know how to solve in this function.
First, I am not getting a string returned from the table I inserted. (Suggestions appreciated) This is the Example I was trying to use to learn how to get my values from the table. 2019 SOLIDWORKS API Help - Insert BOM Table and Extract Data Example (VB.NET)
The second is a symptom of first, but I don't why it is telling me test is a boolean? I am getting an error and the catch ex message tells me that "Fastener" is not of the boolean type. This happens while checking if the Test variable in the code below has a specific string. Problem is, the Test variable is not a boolean type so why is it trying to check if it is? Line 64 below
Here is my code:
Private Function InsertBOMtable(swmodel As ModelDoc2, swassy As AssemblyDoc) As Data.DataTable
Dim swModelDocExt As ModelDocExtension
Dim swBOMAnnotation As BomTableAnnotation
Dim swBOMFeature As BomFeature
Dim swtable As TableAnnotation
Dim BomType As Long
Dim numtype As Long
Dim Configuration As String
Dim TemplateName As String
Dim conf As Configuration = swmodel.GetActiveConfiguration
#Region "Insert BOM"
Try
swModelDocExt = swmodel.Extension
TemplateName = "c:\users\jhixon\desktop\csvbom.sldbomtbt"
BomType = swBomType_e.swBomType_PartsOnly
numtype = swNumberingType_e.swNumberingType_Detailed
Configuration = conf.Name
swBOMAnnotation = swModelDocExt.InsertBomTable3(TemplateName, 0, 1, BomType,
Configuration, False, numtype, True)
swBOMFeature = swBOMAnnotation.BomFeature
swtable = swBOMAnnotation
swmodel.ViewZoomtofit2()
Catch ex As Exception
MsgBox(ex.Message.ToString)
Return Nothing
End Try
#End Region
#Region "Create Datatable For csv"
Dim Bomdata As New Data.DataTable("BOM")
Dim Bomcol As DataColumn = Bomdata.Columns.Add("Part_Num", Type.GetType("System.String"))
Bomcol.AllowDBNull = False
Bomcol.Unique = True
Bomdata.Columns.Add("QTY", Type.GetType("System.Double"))
Bomdata.Columns.Add("Vendor", Type.GetType("System.String"))
Bomdata.Columns.Add("Cost", Type.GetType("System.String"))
#End Region
#Region "Fill Datatable with BOM in assembly"
'Fills Datatable with Bom and gets array of weldment bodies
Dim r As Int16 = 0
Dim numrow As Int16 = swtable.RowCount
Dim Part As String
Dim vend As String = ""
Dim cost As String = ""
Dim model As ModelDoc2
Dim qty As Int16
Dim test As String = ""
Try
For r = 0 To numrow - 1
test = swtable.Text2(r, 3, True)
If test = "Fastner" Or "Fastener" Or "Inventory" Or "DRMATL" Then
Part = swtable.Text(r, 1)
qty = swtable.Text(r, 2)
'Add vendor info only to drmatl
If test = "DRMATL" Then
vend = swtable.Text(r, 4)
cost = swtable.Text(r, 5)
End If
Bomdata.Rows.Add(New Object() {Part, qty, vend, cost})
Else
Part = swtable.Text(r, 1)
qty = swtable.Text(r, 2)
model = swBOMAnnotation.GetComponents(r)
Bomdata = RawQTY(model, qty, Bomdata)
End If
'clear vendor and cost for next row
vend = ""
cost = ""
Next r
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
Return Bomdata
#End Region
End Function