Hi All,
I have a function that creates a custom form in a drawing which is working almost as I need. I pass the function a part number and it populates the columns based on that. This works fine (code included below), however what I want to be able to do is pass X amount of part numbers to the function, then a new row created for each part number.
How would I go about doing this?
Thanks in advance.
Function funcCustomTable(strPartNo As String)
Logger.Debug("funcCustomTable run with strPartNo: " + strPartNo)
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oCols As Integer = 4
Dim oRows As Integer = 1
Select Case strPartNo
Case "1234567"
strDesc = "description of part"
End Select
' Set the column titles
Dim oTitles(3) As String
oTitles(0) = "ITEM"
oTitles(1) = "PART NO"
oTitles(2) = "QTY"
oTitles(3) = "DESCRIPTION"
Logger.Debug("Titles Created")
' Set the contents of the custom table (contents are set row-wise)
Dim oContents(3) As String
oContents(0) = "1"
oContents(1) = strPartNo
oContents(2) = 1
oContents(3) = strDesc
Logger.Debug("Contents Created")
' Set the column widths (defaults to the column title width if not specified)
Dim oColumnWidths(3) As Double
oColumnWidths(0) = 1
oColumnWidths(1) = 2.9
oColumnWidths(2) = 1
oColumnWidths(3) = 9.7
Logger.Debug("Widths Adjusted")
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)
Logger.Debug("Placement Point Added")
' Create the custom table
Dim oCustomTable As CustomTable
Try
oCustomTable = oSheet.CustomTables.Add("SUBSTITUTE MATERIAL", oPlacementPoint, oCols, oRows, oTitles, oContents, oColumnWidths)
Catch ex As Exception
Logger.Debug(ex.ToString)
End Try
Solved! Go to Solution.
Hi All,
I have a function that creates a custom form in a drawing which is working almost as I need. I pass the function a part number and it populates the columns based on that. This works fine (code included below), however what I want to be able to do is pass X amount of part numbers to the function, then a new row created for each part number.
How would I go about doing this?
Thanks in advance.
Function funcCustomTable(strPartNo As String)
Logger.Debug("funcCustomTable run with strPartNo: " + strPartNo)
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oCols As Integer = 4
Dim oRows As Integer = 1
Select Case strPartNo
Case "1234567"
strDesc = "description of part"
End Select
' Set the column titles
Dim oTitles(3) As String
oTitles(0) = "ITEM"
oTitles(1) = "PART NO"
oTitles(2) = "QTY"
oTitles(3) = "DESCRIPTION"
Logger.Debug("Titles Created")
' Set the contents of the custom table (contents are set row-wise)
Dim oContents(3) As String
oContents(0) = "1"
oContents(1) = strPartNo
oContents(2) = 1
oContents(3) = strDesc
Logger.Debug("Contents Created")
' Set the column widths (defaults to the column title width if not specified)
Dim oColumnWidths(3) As Double
oColumnWidths(0) = 1
oColumnWidths(1) = 2.9
oColumnWidths(2) = 1
oColumnWidths(3) = 9.7
Logger.Debug("Widths Adjusted")
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)
Logger.Debug("Placement Point Added")
' Create the custom table
Dim oCustomTable As CustomTable
Try
oCustomTable = oSheet.CustomTables.Add("SUBSTITUTE MATERIAL", oPlacementPoint, oCols, oRows, oTitles, oContents, oColumnWidths)
Catch ex As Exception
Logger.Debug(ex.ToString)
End Try
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
try something like this:
Sub Main()
Dim partNumbers As New List(Of String)
partNumbers.Add("1234567")
partNumbers.Add("8901234")
partNumbers.Add("1234567")
funcCustomTable(partNumbers)
End Sub
Public Function funcCustomTable(partNumbers As List(Of String))
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oCols As Integer = 4
Dim oRows As Integer = 1
Dim strDesc = String.Empty
logger.Debug("Contents Created")
' Set the column titles
Dim oTitles(3) As String
oTitles(0) = "ITEM"
oTitles(1) = "PART NO"
oTitles(2) = "QTY"
oTitles(3) = "DESCRIPTION"
logger.Debug("Titles Created")
' Set the column widths (defaults to the column title width if not specified)
Dim oColumnWidths(3) As Double
oColumnWidths(0) = 1
oColumnWidths(1) = 2.9
oColumnWidths(2) = 1
oColumnWidths(3) = 9.7
logger.Debug("Widths Adjusted")
Dim oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)
logger.Debug("Placement Point Added")
' Create the custom table
Dim oCustomTable As CustomTable
Try
Dim firstPartNumber = partNumbers.First()
partNumbers.Remove(firstPartNumber)
Dim content = createRowContent(firstPartNumber)
oCustomTable = oSheet.CustomTables.Add("SUBSTITUTE MATERIAL", oPlacementPoint, oCols, oRows, oTitles, content, oColumnWidths)
For Each partNumber As String In partNumbers
content = createRowContent(partNumber)
oCustomTable.Rows.Add(,, content)
Next
Catch ex As Exception
logger.Debug(ex.ToString)
End Try
End Function
Public Function createRowContent(partNumber)
Dim description = "Unknown"
Select Case partNumber
Case "1234567"
description = "description of part"
Case "8901234"
description = "description of part 2"
End Select
Dim content(3) As String
content(0) = "1"
content(1) = partNumber
content(2) = 1
content(3) = description
Return content
End Function
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
try something like this:
Sub Main()
Dim partNumbers As New List(Of String)
partNumbers.Add("1234567")
partNumbers.Add("8901234")
partNumbers.Add("1234567")
funcCustomTable(partNumbers)
End Sub
Public Function funcCustomTable(partNumbers As List(Of String))
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oCols As Integer = 4
Dim oRows As Integer = 1
Dim strDesc = String.Empty
logger.Debug("Contents Created")
' Set the column titles
Dim oTitles(3) As String
oTitles(0) = "ITEM"
oTitles(1) = "PART NO"
oTitles(2) = "QTY"
oTitles(3) = "DESCRIPTION"
logger.Debug("Titles Created")
' Set the column widths (defaults to the column title width if not specified)
Dim oColumnWidths(3) As Double
oColumnWidths(0) = 1
oColumnWidths(1) = 2.9
oColumnWidths(2) = 1
oColumnWidths(3) = 9.7
logger.Debug("Widths Adjusted")
Dim oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)
logger.Debug("Placement Point Added")
' Create the custom table
Dim oCustomTable As CustomTable
Try
Dim firstPartNumber = partNumbers.First()
partNumbers.Remove(firstPartNumber)
Dim content = createRowContent(firstPartNumber)
oCustomTable = oSheet.CustomTables.Add("SUBSTITUTE MATERIAL", oPlacementPoint, oCols, oRows, oTitles, content, oColumnWidths)
For Each partNumber As String In partNumbers
content = createRowContent(partNumber)
oCustomTable.Rows.Add(,, content)
Next
Catch ex As Exception
logger.Debug(ex.ToString)
End Try
End Function
Public Function createRowContent(partNumber)
Dim description = "Unknown"
Select Case partNumber
Case "1234567"
description = "description of part"
Case "8901234"
description = "description of part 2"
End Select
Dim content(3) As String
content(0) = "1"
content(1) = partNumber
content(2) = 1
content(3) = description
Return content
End Function
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Here is one approach. Create an empty table then add a row and populate then move to the next.
Sub Main
Dim strPartNoList As New List(Of String)
strPartNoList.Add("1234567")
strPartNoList.Add("123")
strPartNoList.Add("12345")
For Each strPartNo In strPartNoList
funcCustomTable(strPartNo)
Next
End Sub
Function funcCustomTable(strPartNo As String)
Logger.Debug("funcCustomTable run with strPartNo: " + strPartNo)
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oCustomTable As CustomTable
If oSheet.CustomTables.Count = 0 Then
Dim oCols As Integer = 4
Dim oRows As Integer = 1
'Set the column titles.
Dim oTitles(3) As String
oTitles(0) = "ITEM"
oTitles(1) = "PART NO"
oTitles(2) = "QTY"
oTitles(3) = "DESCRIPTION"
Logger.Debug("Titles Created")
'Set the column widths (defaults to the column title width if not specified).
Dim oColumnWidths(3) As Double
oColumnWidths(0) = 1
oColumnWidths(1) = 2.9
oColumnWidths(2) = 1
oColumnWidths(3) = 9.7
Logger.Debug("Widths Adjusted")
Dim oPlacementPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)
Logger.Debug("Placement Point Added")
Try
oCustomTable = oSheet.CustomTables.Add("SUBSTITUTE MATERIAL", oPlacementPoint, oCols, oRows, oTitles, , oColumnWidths)
Catch ex As Exception
Logger.Debug(ex.ToString)
End Try
Else
'Get the custom table object.
oCustomTable = oSheet.CustomTables(1)
oCustomTable.Rows.Add()
End If
Dim strDesc As String
Select Case strPartNo
Case "1234567"
strDesc = "description of part"
Case Else
strDesc = "N/A"
End Select
'Get last row number.
Dim TableRowNo As Integer = oCustomTable.Rows.Count
'Get row object.
Dim TableRow As Row = oCustomTable.Rows(TableRowNo)
'Get each cell object.
Dim ItemCell As Cell = TableRow.Item(1)
Dim PartCell As Cell = TableRow.Item(2)
Dim QtyCell As Cell = TableRow.Item(3)
Dim DescCell As Cell = TableRow.Item(4)
'Populate the table.
ItemCell.Value = (TableRowNo+1)-1 '-1 to Skip Header Row
PartCell.Value = strPartNo
QtyCell.Value = "1"
DescCell.Value = strDesc
End Function
Here is one approach. Create an empty table then add a row and populate then move to the next.
Sub Main
Dim strPartNoList As New List(Of String)
strPartNoList.Add("1234567")
strPartNoList.Add("123")
strPartNoList.Add("12345")
For Each strPartNo In strPartNoList
funcCustomTable(strPartNo)
Next
End Sub
Function funcCustomTable(strPartNo As String)
Logger.Debug("funcCustomTable run with strPartNo: " + strPartNo)
Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDrawDoc.ActiveSheet
Dim oCustomTable As CustomTable
If oSheet.CustomTables.Count = 0 Then
Dim oCols As Integer = 4
Dim oRows As Integer = 1
'Set the column titles.
Dim oTitles(3) As String
oTitles(0) = "ITEM"
oTitles(1) = "PART NO"
oTitles(2) = "QTY"
oTitles(3) = "DESCRIPTION"
Logger.Debug("Titles Created")
'Set the column widths (defaults to the column title width if not specified).
Dim oColumnWidths(3) As Double
oColumnWidths(0) = 1
oColumnWidths(1) = 2.9
oColumnWidths(2) = 1
oColumnWidths(3) = 9.7
Logger.Debug("Widths Adjusted")
Dim oPlacementPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)
Logger.Debug("Placement Point Added")
Try
oCustomTable = oSheet.CustomTables.Add("SUBSTITUTE MATERIAL", oPlacementPoint, oCols, oRows, oTitles, , oColumnWidths)
Catch ex As Exception
Logger.Debug(ex.ToString)
End Try
Else
'Get the custom table object.
oCustomTable = oSheet.CustomTables(1)
oCustomTable.Rows.Add()
End If
Dim strDesc As String
Select Case strPartNo
Case "1234567"
strDesc = "description of part"
Case Else
strDesc = "N/A"
End Select
'Get last row number.
Dim TableRowNo As Integer = oCustomTable.Rows.Count
'Get row object.
Dim TableRow As Row = oCustomTable.Rows(TableRowNo)
'Get each cell object.
Dim ItemCell As Cell = TableRow.Item(1)
Dim PartCell As Cell = TableRow.Item(2)
Dim QtyCell As Cell = TableRow.Item(3)
Dim DescCell As Cell = TableRow.Item(4)
'Populate the table.
ItemCell.Value = (TableRowNo+1)-1 '-1 to Skip Header Row
PartCell.Value = strPartNo
QtyCell.Value = "1"
DescCell.Value = strDesc
End Function
Thanks so much, worked as expected. Really handy to know how to pick out each cell object too.
Thanks so much, worked as expected. Really handy to know how to pick out each cell object too.
Yes this works well for quering the table after its populated. And the same approach can be used for revision table and partslist. The API help has samples for the partslist in VBA launguage.
Yes this works well for quering the table after its populated. And the same approach can be used for revision table and partslist. The API help has samples for the partslist in VBA launguage.
Can't find what you're looking for? Ask the community or share your knowledge.