Bend tags need to be Alphabetical instead of Numerical.

Bend tags need to be Alphabetical instead of Numerical.

dzajacobs
Explorer Explorer
344 Views
1 Reply
Message 1 of 2

Bend tags need to be Alphabetical instead of Numerical.

dzajacobs
Explorer
Explorer

Hi all, 

 

Was hoping someone could help, I'm trying to create a programme to auto create a table for the flat pattern of a specific IDW view. I have gotten as far as the table being created but I'm really struggling with the last bit. I need help to get the Bend ID to have Alphabetical letters instead of Numerical ones. Here is the current code: 

Public Sub Main CreateBendTable()
    ' Reference to the active drawing document
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument
    
    ' Reference to the active sheet
    Dim oActiveSheet As Sheet
    oActiveSheet = oDrawDoc.ActiveSheet
    
    ' Get path sheetpart
    Dim oPartDoc As PartDocument
    oPartDoc = oDrawDoc.ReferencedDocuments.Item(1)
    
    ' Create the placement point for the table
    Dim oPoint As Point2d
    oPoint = ThisApplication.TransientGeometry.CreatePoint2d(21.5, 19)
    
    ' Specify the columns - this can be specified in any combination/order
    Dim strColumns(0 To 2) As String
    strColumns(0) = "BEND ID"
    strColumns(1) = "BEND ANGLE"
    strColumns(2) = "BEND DIRECTION"
    
    ' Create the bend table by specifying the source sheet metal file
    Dim oBendTable As CustomTable
    oBendTable = oActiveSheet.CustomTables.AddBendTable(oPartDoc.FullDocumentName, oPoint, "Bend Table", strColumns)
	 
    ' Select the bend table and execute the "Select Bends to Display" command
    oDrawDoc.SelectSet.Select(oBendTable)
    ThisApplication.CommandManager.ControlDefinitions("DrawingTableSelectBendViewCtxCmd").Execute2(False)
    
    ' Select the fifth drawing view
    ThisApplication.CommandManager.DoSelect(oActiveSheet.DrawingViews(5))
End Sub
0 Likes
345 Views
1 Reply
Reply (1)
Message 2 of 2

gerrardhickson
Collaborator
Collaborator

I've had to interprete your code to VBA, and I'm not very familiar with CommandManager, but it seems like your code needs to complete the pick view operation.

 

In any case. Once that's done, all you need to do is define the list of characters you want your list to be, split that list in to an array (not essential, but convenient. I've used a helper function for this), then iterate through your table rows, replacing the table value with the next letter.

 

Public Sub CreateBendTable()
    ' Reference to the active drawing document
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    
    ' Reference to the active sheet
    Dim oActiveSheet As Sheet
    Set oActiveSheet = oDrawDoc.ActiveSheet
    
    ' Get path sheetpart
    Dim oPartDoc As PartDocument
    Set oPartDoc = oDrawDoc.ReferencedDocuments.Item(1)
    
    ' Create the placement point for the table
    Dim oPoint As Point2d
    Set oPoint = ThisApplication.TransientGeometry.CreatePoint2d(21.5, 19)
    
    ' Specify the columns - this can be specified in any combination/order
    Dim strColumns(0 To 2) As String
    strColumns(0) = "BEND ID"
    strColumns(1) = "BEND ANGLE"
    strColumns(2) = "BEND DIRECTION"
    
    ' Create the bend table by specifying the source sheet metal file
    Dim oBendTable As CustomTable
    Set oBendTable = oActiveSheet.CustomTables.AddBendTable(oPartDoc.FullDocumentName, oPoint, "Bend Table", strColumns)
     
    ' Select the bend table and execute the "Select Bends to Display" command - **ASSUME THIS IS THE "ADD TAGS TO VIEW" COMMAND?
    oDrawDoc.SelectSet.Select oBendTable
    ThisApplication.CommandManager.ControlDefinitions("DrawingTableSelectBendViewCtxCmd").Execute
'    Dim oView As DrawingView
'    Set oView = oDrawDoc.ActiveSheet.DrawingViews(1).
    'obendtable.
    
    ' Select the fifth drawing view
    ThisApplication.CommandManager.DoSelect oActiveSheet.DrawingViews(1)
    '***NEED TO FINISH THE COMMAND. NOT SURE HOW TO DO THIS WITH VBA.
    
    'SPEFIFY THE LIST OF LETTERS YOU WANT INCLUDED - YOU MIGHT LIKE TO OMIT 'I' OR OTHERS.
    Dim Alpha() As String
    Alpha = SplitString("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    
    'Once the command has completed, we need to iterate through the rows
    'replacing the first column value with a letter.
    Dim oBTR As row
    Dim X1 As Integer
    For X1 = 1 To oBendTable.Rows.Count
        Set oBTR = oBendTable.Rows(X1)
        oBTR(1).Value = Alpha(X1 - 1)
    Next X1
    
End Sub

Function SplitString(my_string As String) As Variant
Dim buff() As String
Dim i As Integer
    ReDim buff(Len(my_string) - 1)
    For i = 1 To Len(my_string)
        buff(i - 1) = Mid$(my_string, i, 1)
    Next
    SplitString = buff
End Function

 

You'll need to adapt this back to .Net, but it should work well enough.

 

Hope that helps.

0 Likes