- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to create a work around for retaining legacy revision rows before populating with Vault Data. (populating old legacy revision tables with Vault Data deletes legacy revision rows)
I have iLogic Code to: export revision tables out, and even Import them back in as a Custom Table, but I was wondering if there was Code that would instead just put the Revision table contents into a Custom Table without exporting?
I guess the first question should be, is this doable?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a code started for you, but it still has a bug (or few), so it still needs a little more work. But, I'm headed home for the weekend, so I'm just going to post what I have so far. I hope this helps. Have a great weekend. ![]()
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oRevTbl As RevisionTable = oSheet.RevisionTables.Item(1)
Dim oTitle As String = oRevTbl.Title
Dim oPos As Point2d = oRevTbl.Position
Dim oRowCount As Integer = oRevTbl.RevisionTableRows.Count
Dim oColCount As Integer = oRevTbl.RevisionTableColumns.Count
Dim oCellCount As Integer = oRowCount * oColCount
Dim oColTitles(oColCount - 1) As String
Dim oColWidths(oColCount - 1) As Double
Dim oRowHeights(oRowCount-1) As Double
Dim oCellContents(oCellCount) As String
Dim oRow, oCol, oCell As Integer
oCell = 0
For oRow = 1 To oRowCount
For oCol = 1 To oColCount
For oCell = 1 To oCellCount - 1
oCellContents(oCell) = oRevTbl.RevisionTableRows.Item(oRow).Item(oCol).FormattedText
If oCell < (oCellCount - 1) Then oCell = oCell + 1
Next
oColTitles(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Title
oColWidths(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Width
If oCol < oColCount Then oCol = oCol + 1
Next
oRowHeights(oRow-1) = oRevTbl.RevisionTableRows.Item(oRow).Height
If oRow < oRowCount Then oRow = oRow + 1
Next
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oCTable As CustomTable = oSheet.CustomTables.Add(oTitle, oPos, oColCount, oRowCount, oColTitles, oCellContents, oColWidths, oRowHeights)
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS
or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hope you enjoy your weekend as well. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
The loop "For oCell = 1 To oCellCount - 1" is not necessary. I've modified your code a little bit and it seems to work now.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oRevTbl As RevisionTable = oSheet.RevisionTables.Item(1)
Dim oTitle As String = oRevTbl.Title
Dim oPos As Point2d = oRevTbl.Position
Dim oRowCount As Integer = oRevTbl.RevisionTableRows.Count
Dim oColCount As Integer = oRevTbl.RevisionTableColumns.Count
Dim oCellCount As Integer = oRowCount * oColCount
Dim oColTitles(oColCount - 1) As String
Dim oColWidths(oColCount - 1) As Double
Dim oRowHeights(oRowCount - 1) As Double
Dim oCellContents(oCellCount-1) As String
Dim oRow, oCol, oCell As Integer
For oRow = 1 To oRowCount
For oCol = 1 To oColCount
oCellContents(oCell) = oRevTbl.RevisionTableRows.Item(oRow).Item(oCol).FormattedText
oCell = oCell+1
oColTitles(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Title
oColWidths(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Width
Next
oRowHeights(oRow - 1) = oRevTbl.RevisionTableRows.Item(oRow).Height
Next
Dim oCTable As CustomTable = oSheet.CustomTables.Add(oTitle, oPos, oColCount, oRowCount, oColTitles, oCellContents, oColWidths, oRowHeights)
R. Krieg
RKW Solutions
www.rkw-solutions.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was thinking about making this run automatically after open. For that I'd want to identify if my Custom Table already exists so I don't keep pasting over the top of it.
I'm extremely new to ilogic so I may not even be on the right track here, but this is what I came up with.
It'll recognize a named custom table if it has one, but if it doesn't have one, it'll error out. If I run just the portion after the the if statement separately, it works. I'm guessing it has to do with the declarations, but I'm stumped if this can be fixed? (I made a few other changes to specify the sheet but that I don't think is the issue). If I'm way off track, no worries, but I thought I would ask.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub End If Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument Dim oSheet As Sheet oSheet = oDDoc.Sheets(2) Dim oRevTable As CustomTable oRevTable = oSheet.CustomTables.Item(1) If oRevTable.Title = ("REVISION HISTORY - LEGACY") Then Exit Sub End If Dim oRevTbl As RevisionTable = oSheet.RevisionTables.Item(1) Dim oTitle As String = "REVISION HISTORY - LEGACY" Dim oPos As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(27.0815,27.145) Dim oRowCount As Integer = oRevTbl.RevisionTableRows.Count Dim oColCount As Integer = oRevTbl.RevisionTableColumns.Count Dim oCellCount As Integer = oRowCount * oColCount Dim oColTitles(oColCount - 1) As String Dim oColWidths(oColCount - 1) As Double Dim oRowHeights(oRowCount - 1) As Double Dim oCellContents(oCellCount-1) As String Dim oRow, oCol, oCell As Integer For oRow = 1 To oRowCount For oCol = 1 To oColCount oCellContents(oCell) = oRevTbl.RevisionTableRows.Item(oRow).Item(oCol).FormattedText oCell = oCell+1 oColTitles(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Title oColWidths(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Width Next oRowHeights(oRow - 1) = oRevTbl.RevisionTableRows.Item(oRow).Height Next Dim oCTable As CustomTable oCTable = oSheet.CustomTables.Add(oTitle, oPos, oColCount, oRowCount, oColTitles, oCellContents, oColWidths, oRowHeights)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
You can insert this block of code in there right after defining the oSheet variable, to check for a pre-existing custom table. If it finds it, it will let you know, and ask you if you want to replace the existing one. If you say 'Yes', it will delete the existing one, then continue with the rest of the code to create a new one. If you say 'No', it will exit the code.
Dim oExists As Boolean 'false by default
If oSheet.CustomTables.Count > 0 Then
For Each oCTbl As CustomTable In oSheet.CustomTables
If oCTbl.Title = "REVISION HISTORY - LEGACY" Then
oExists = True
oAns = MsgBox("That Custom Table already exists." & vbCrLf & _
"Do you want to replace it?", vbYesNo + vbQuestion, "Custom Table Exists")
If oAns = vbYes Then
oCTbl.Delete
ElseIf oAns = vbNo Then
Exit Sub
End If
End If
Next
End If
Also, to make this work, change the following line lower in the main code:
Dim oTitle As String = oRevTbl.Title
To:
Dim oTitle As String = "REVISION HISTORY - LEGACY"(which you already did)
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS)
.
If you want and have time, I would appreciate your Vote(s) for My IDEAS
or you can Explore My CONTRIBUTIONS
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It looks like if I specify another sheet other than the active sheet, I need to activate that sheet at least once before the code works. Out of curiosity, would you know why that is? I can write in the sheet activation in at the beginning and that fixes it, but I found this an odd behavior.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
If you want, we could change the code so that it loops through each sheet in the drawing, checking if each sheet has a revision table in it, and if it does, create a duplicate of that revision table as a custom table, that way it wouldn't matter what sheet you specify in the code. I believe that which ever sheet the code is going to be placing a new custom table on needs to be 'active' or 'activated', because we're physically placing that new custom table on it at a specific 2d location. That simple 2d location doesn't know/care which sheet is active, so we have to set that part up as needed before that point in the code. The Sheet object has a method called 'Activate', that we can use for that purpose as we loop through the sheets.
We could also put the bulk of the code that gathers data from the existing revision table and creates the new custom table into a separate, lower sub routine, then call that sub routine within the loop of the sheets, when it finds an existing revision block.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is my fix. We have what we call a "revision history sheet" on all our drawings and it's always the last sheet, so this is how I handled it:
Dim oDDoc As DrawingDocument = ThisDrawing.Document Dim oSheet As Inventor.Sheet 'Activate All Sheets in Document For Each oSheet In oDDoc.Sheets oSheet.Activate Next 'set oSheet as the last sheet in a document oSheet = oDDoc.Sheets(oDDoc.Sheets.Count)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ive modified this code. Perhaps its useful to someone else?
It will update all rev tables across all sheets.
It will update the rev table style to match the styles library
It will quit if it detects the script has already been run.
Sub Main()
'Check if drawing
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.", vbOKOnly + vbCritical, "Don't worry, Rodney. This time next year, we'll be millionaires!")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oTitle As String = "LEGACY REVISION HISTORY"
Dim oTable As CustomTable
'Stops the iLogic running if Legacy revision history exists.
Dim oExists As Boolean 'false by default
If oSheet.CustomTables.Count > 0 Then
For Each oCTbl As CustomTable In oSheet.CustomTables
If oCTbl.Title = oTitle Then
End If
Next
Exit Sub
End If
Dim oRevTbl As RevisionTable = oSheet.RevisionTables.Item(1)
Dim oPos As Point2d = oRevTbl.Position
'Alternative insertion position off page.
'Dim oPos As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0,0)
Dim oRowCount As Integer = oRevTbl.RevisionTableRows.Count
Dim oColCount As Integer = oRevTbl.RevisionTableColumns.Count
Dim oCellCount As Integer = oRowCount * oColCount
Dim oColTitles(oColCount - 1) As String
Dim oColWidths(oColCount - 1) As Double
Dim oRowHeights(oRowCount - 1) As Double
Dim oCellContents(oCellCount - 1) As String
Dim oRow, oCol, oCell As Integer
'Get Rvision table information
For oRow = 1 To oRowCount
For oCol = 1 To oColCount
oCellContents(oCell) = oRevTbl.RevisionTableRows.Item(oRow).Item(oCol).FormattedText
oCell = oCell + 1
oColTitles(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Title
oColWidths(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Width
Next
oRowHeights(oRow - 1) = oRevTbl.RevisionTableRows.Item(oRow).Height
Next
'Apply to each sheet
For Each oSheet In oDDoc.Sheets
'Remove old revision tables
If oSheet.RevisionTables.Count > 0 Then
For Each oRevTable In oSheet.RevisionTables
oRevTable.Delete
Next
End If
'Insert new legacy revision table
Dim oCTable As CustomTable = oSheet.CustomTables.Add(oTitle, oPos, oColCount, oRowCount, oColTitles, oCellContents, oColWidths, oRowHeights)
'set the table style to match Legacy Revision Table. You need to create a table style in the styles editor, this can be a global style.
Dim oActiveTableStyle As TableStyle
Dim oTableTitle As String
oActiveTableStyle = oDDoc.StylesManager.TableStyles("Legacy Revision Table")
oTableTitle = oActiveTableStyle.Title
oCTable.Style = oActiveTableStyle
Next
End Sub