Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
Hi everybody,
I would like to get the bill of material by API. I have already worked through vbug.pdf, but I couldn´t find a clue in this direction.
You can get the first level dependencies by IpfcModel.ListDependencies() (doing this recursively will get all dependecies for complex assemblies) but I couldn´t get the number for a part/assembly in this level?! I have played some time with IpfcComponentPath, but I think this is the wrong direction.
Here a simple example:
root.asm
- 1 x part1.prt
- 5 x part2.prt
- 2 x other.asm
- 3 x partA.prt
- 1 x partB.prt
- 8 x GenericPart.prt
So ListDependencies() for root.asm would return
- part1.prt
- part2.prt
- other.asm
- GenericPart.prt
But how to get the numbers? In fact to get the commercial counts for purchase I need to pass the number of other.asm (2x) down to multiply.
Hope this shows what I mean 😃
Thanks in advanced for your help.
Best regards,
Benjamin
Solved! Go to Solution.
Hi Benjamin,
Try the below code
Dim AConnection As IpfcAsyncConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, Nothing)
Dim BSession As IpfcBaseSession = AConnection.Session
Dim Model As IpfcModel = BSession.CurrentModel
Dim Drawing As IpfcDrawing = CType(Model, IpfcDrawing)
Dim DTables As IpfcTables = Drawing.ListTables()
Dim DTable As IpfcTable = DTables(Table)
Dim RowCount As Integer = DTable.GetRowCount
Dim ColumnCount As Integer = DTable.GetColumnCount
' GETTING COLUMN
Dim Description, Idtnr, PartNo, Qty, Sym As IpfcTableCell
For j As Integer = 2 To RowCount
For k As Integer = 1 To ColumnCount
MyCell As IpfcTableCell = New (CCpfcTableCell).Create(j, k)
Dim ItemValue = DTable.GetText(MyCell, 0)
RowItems.Add(ItemValue(0).ToString)
Next
' GETTING CELL VALUES IN STRING FORMAT
Dim SymV, QtyV, PartNoV, DescriptionV AsString
SymV = RowItems(0).ToString
PartNoV = RowItems(1).ToString
DescriptionV = RowItems(2).ToString
QtyV = RowItems(3).ToString
' ADD VALUES TO YOUE DATAGRID HERE
Next
Hi Benjamin,
My suggestion is instead of trying in model you go to drawing & export the BOM table,
In VB API You can easily load the BOM table to your application datagridview...
Hi Parthiban,
I don´t know, perhaps it´s because of the oncoming weekend, but I don´t get it 😃
With following Code I can create a BOM export as txt-file.
// create export instructions
CCpfcBOMExportInstructions bomExportCreate = new CCpfcBOMExportInstructions();
IpfcBOMExportInstructions exportInstr = bomExportCreate.Create();
IpfcExportInstructions temp = (IpfcExportInstructions)exportInstr;
// export to file
this.model.Export(fileName, temp);
But how to load the BOM table? I couldn´t find a hint in the vbug.pdf.
Best reagrds,
Benjamin
Hi Benjamin,
Try the below code
Dim AConnection As IpfcAsyncConnection = (New CCpfcAsyncConnection).Connect(Nothing, Nothing, Nothing, Nothing)
Dim BSession As IpfcBaseSession = AConnection.Session
Dim Model As IpfcModel = BSession.CurrentModel
Dim Drawing As IpfcDrawing = CType(Model, IpfcDrawing)
Dim DTables As IpfcTables = Drawing.ListTables()
Dim DTable As IpfcTable = DTables(Table)
Dim RowCount As Integer = DTable.GetRowCount
Dim ColumnCount As Integer = DTable.GetColumnCount
' GETTING COLUMN
Dim Description, Idtnr, PartNo, Qty, Sym As IpfcTableCell
For j As Integer = 2 To RowCount
For k As Integer = 1 To ColumnCount
MyCell As IpfcTableCell = New (CCpfcTableCell).Create(j, k)
Dim ItemValue = DTable.GetText(MyCell, 0)
RowItems.Add(ItemValue(0).ToString)
Next
' GETTING CELL VALUES IN STRING FORMAT
Dim SymV, QtyV, PartNoV, DescriptionV AsString
SymV = RowItems(0).ToString
PartNoV = RowItems(1).ToString
DescriptionV = RowItems(2).ToString
QtyV = RowItems(3).ToString
' ADD VALUES TO YOUE DATAGRID HERE
Next
Hi Parthiban,
thank you for the great code. You gave me the hint I needed.
Unfortunately I´m using C# and the interface is not exactly the same as in VB.
E.g. if I make a IpfcDrawing out of the model, there is no ListTables-Operation. So there are a lot of obstacles to overcome 😃
FYI: I needed to use IpfcTableOwner to catch the tables. See below (C#) code for getting the cell-informations of the tables.
IpfcTableOwner owner = (IpfcTableOwner)this.model;
foreach (IpfcTable table in owner.ListTables())
{
for (int r = 0; r <= table.GetRowCount(); r++) // Rows
{
string columnContent = "";
for (int c = 0; c <= table.GetColumnCount(); c++) // Cols
{
IpfcTableCell tempCell = new CCpfcTableCell().Create(r, c);
try
{
// Extract cell information
Cstringseq seq = table.GetText(tempCell, (int)EpfcParamMode.EpfcDWGTABLE_NORMAL);
string tempstr;
seq.GetValues(0, seq.Count, out tempstr);
columnContent += tempstr;
}
catch (Exception ex)
{
// ...
}
}
Console.WriteLine("(" + r + "): " + columnContent);
}
Best Regards,
Benjamin
Hi,
old thread revival ...
trying to do the same thing but using VB API.
I get into a problem I cannot figure out, using this code:
Private Function GetCellText(TheTable As IpfcTable, rIdx As Integer, cIdx As Integer) As String
Try
Debug.Print("Number of lines in table: " & TheTable.GetRowCount)
Debug.Print("Number of columns in table: " & TheTable.GetColumnCount)
Dim MyCell As IpfcTableCell = (New CCpfcTableCell).Create(rIdx, cIdx)
Dim MyText As Cstringseq = TheTable.GetText(MyCell, 0)
Return MyText(0).ToString
Catch ex As Exception
MsgBox(ex.Message & vbNewLine & vbNewLine & ex.StackTrace,, GetCurrentMethod().Name)
Return Nothing
End Try
End Function
I get an exception from xToolkit at the line "Dim MyText As Cstringseq = TheTable.GetText(MyCell, 0)" but I can't find what I am doing wrong.
Any idea?