Message 1 of 6
Adding revision rows
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am struggling with a problem to automate revision rows.
i have made a code so that when the revision is 0 or 1 the code adds a revision table and then for every new revision added to the part the revision number on the drawing is also counted up and a new revision row is added.
but if I accidentally delete the revision table and then run the code again the code does not add new rows but instead it just change revision number on the first row in the table to active revision number.
How do I code it so that even if I by accident delete the table the code will still add new rows up to the active revision number?
Here is the code:
Sub main()
InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True
Dim updateCmd As ControlDefinition
updateCmd = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd")
updateCmd.Execute2(True)
Dim Odoc As Document = ThisDoc.Document
Dim DrawDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet
For Each oSheet In DrawDoc.Sheets
If oSheet.RevisionTables.Count = 0 Then
oSheet.Activate
Call AddRevTable(DrawDoc, oSheet)
Call Stylesedit(Odoc)
Else
Call Stylesedit(Odoc)
Call AddRevRow(DrawDoc)
End If
Next
InventorVb.DocumentUpdate()
End Sub
Sub AddRevTable(DrawDoc As DrawingDocument, oSheet As Sheet)
Dim oRTBs As RevisionTables
Dim oLocation As Point2d
Dim oRTB As RevisionTable
oRTBs = oSheet.RevisionTables
If ActiveSheet.Border="A4 Stående" Then
oLocation = ThisApplication.TransientGeometry.CreatePoint2d(2, 28.55)
Else
oLocation = ThisApplication.TransientGeometry.CreatePoint2d(2, 1.9596)
End If
oRTB = oRTBs.Add2(oLocation, False, True, True, "1")
oRTB.UpdatePropertyToRevisionNumber = False
End Sub
Sub Stylesedit (Odoc As Document)
Dim oDocStyles As Inventor.DrawingStylesManager
Dim oRevStyle As RevisionTableStyle
Dim oRevisionTable As RevisionTable
Dim oLocation As Point2d
'Checks which border is active and change revisionstyle and position accordingly
If ActiveSheet.Border = "A4 Stående" Then
oDocStyles = Odoc.StylesManager
oRevStyle = oDocStyles.RevisionTableStyles.Item("Revision A4 Stående")
oRevisionTable = Odoc.Sheets(1).RevisionTables(1)
oLocation = ThisApplication.TransientGeometry.CreatePoint2d(2, 28.55)
ActiveSheet.Sheet.RevisionTables.Item(1).Position=oLocation
oRevisionTable.Style = oRevStyle
Else
oDocStyles = Odoc.StylesManager
oRevStyle = oDocStyles.RevisionTableStyles.Item("Revision")
oRevisionTable = Odoc.Sheets(1).RevisionTables(1)
oLocation = ThisApplication.TransientGeometry.CreatePoint2d(2, 1.9596)
ActiveSheet.Sheet.RevisionTables.Item(1).Position=oLocation
oRevisionTable.Style = oRevStyle
End If
End Sub
Sub AddRevRow(DrawDoc As DrawingDocument)
' Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
' Get the revision table
Dim oRevTable As RevisionTable = DrawDoc.ActiveSheet.RevisionTables.Item(1)
' Get last row
Dim oRow As RevisionTableRow
oRow = oRevTable.RevisionTableRows.Item(oRevTable.RevisionTableRows.Count)
' Make sure we have the active row
If oRow.IsActiveRow Then
' Go through all columns in that row
For i = 1 To oRevTable.RevisionTableColumns.Count
Dim oCell As RevisionTableCell = oRow.Item(i)
' Set all cells to static
oCell.Text = oCell.Text
Next
End If
' Add another row at the end
Dim r As Inventor.RevisionTableRow
Dim oRev As RevisionTableCell = oRow.Item(1)
If oRev.Text = iProperties.Value("Project", "Revision Number") Then
Exit Sub
Else If oRev.Text < iProperties.Value("Project", "Revision Number") Then
Dim oRows As RevisionTableRows = oRevTable.RevisionTableRows
r = oRows.Add()
Dim rnmbr As Integer = Asc(r.Item(1).Text) - 63
r.Item(1).Text = rnmbr
Else If oRev.Text > iProperties.Value("Project", "Revision Number") Then
MessageBox.Show("Obs! Antal revisioner stämmer inte med modellens revision. Kontrollera så att revisionerna stämmer överens", "Revision stämmer inte överens", OK)
Exit Sub
End If
End Sub
Thanks in advance!

