Revision Table iProperties

Revision Table iProperties

GSK2019
Enthusiast Enthusiast
696 Views
6 Replies
Message 1 of 7

Revision Table iProperties

GSK2019
Enthusiast
Enthusiast

Hi,

 

I am currently trying to make an automatic revision table, when you use the rule, it will update the letter in the revision block as well as on the sheet. But So far i am running against some problems with the revision table:

- And it is not updating the iProperty's Revision Number

Sub Main()
	Dim Odoc As Document = ThisDoc.Document
	Dim DrawDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet
	Dim visibleRowsWanted As Integer = 3
	For Each oSheet In DrawDoc.Sheets
		If oSheet.RevisionTables.Count = 0 Then
			Call AddRevTable(DrawDoc)
			Else
				Call AddRevRow(DrawDoc)
				Call PurgeRev(DrawDoc, visibleRowsWanted)
		End If
	Next
InventorVb.DocumentUpdate()

End Sub

Sub AddRevTable(DrawDoc As DrawingDocument)
'    Dim oDrawDoc As DrawingDocument
'    oDrawDoc = ThisApplication.ActiveDocument
	
    Dim oRTBs As RevisionTables
    oRTBs = DrawDoc.ActiveSheet.RevisionTables
 
    Dim oLocation As Point2d
    oLocation = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
 
    'add a new table
    Dim oRTB As RevisionTable
    oRTB = oRTBs.Add2(oLocation, True, True, True, "A")
	iProperties.Value("Project", "Revision Number") = "A"
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
' or static and blank'oCell.Text = ""
Next
End If
' Add another row at the end
Dim oRows As RevisionTableRows = oRevTable.RevisionTableRows
oRows.Add()
End Sub

Sub PurgeRev(DrawDoc As DrawingDocument, visibleRowsWanted As Integer)
	For Each sheet As Sheet In ThisDrawing.Document.Sheets
  		For Each revTable As RevisionTable In Sheet.RevisionTables
    		Trace.WriteLine(" --- " & revTable.Title)
			Dim rows As RevisionTableRows = revTable.RevisionTableRows 
			Dim numberToHide As Integer = rows.Count - visibleRowsWanted
	If (numberToHide <= 0) Then Continue For
	For i = 1 To numberToHide
	  rows(i).Visible = False
	Next
  Next
Next
 End Sub

 

So far I have this, how can i make sure it also updates the iProperties?

0 Likes
Accepted solutions (1)
697 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Here is the snippet you need from the API help

Syntax

RevisionTable.UpdatePropertyToRevisionNumber() As Boolean

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 7

GSK2019
Enthusiast
Enthusiast

How would you incorporate this in the code?

Because when I try it in my code I get the following Error:

GSK2019_0-1660052725125.png

Sub Main()
	Dim Odoc As Document = ThisDoc.Document
	Dim DrawDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet
	Dim visibleRowsWanted As Integer = 3
	For Each oSheet In DrawDoc.Sheets
		If oSheet.RevisionTables.Count = 0 Then
			Call AddRevTable(DrawDoc)
			Else
				Call AddRevRow(DrawDoc)
				Call PurgeRev(DrawDoc, visibleRowsWanted)
		End If
	Next
InventorVb.DocumentUpdate()

End Sub

Sub AddRevTable(DrawDoc As DrawingDocument)
'    Dim oDrawDoc As DrawingDocument
'    oDrawDoc = ThisApplication.ActiveDocument
	
    Dim oRTBs As RevisionTables
    oRTBs = DrawDoc.ActiveSheet.RevisionTables
 
    Dim oLocation As Point2d
    oLocation = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
 
    'add a new table
    Dim oRTB As RevisionTable
    oRTB = oRTBs.Add2(oLocation, True, True, True, "A")
'	iProperties.Value("Project", "Revision Number") = "A"
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
' or static and blank'oCell.Text = ""
Next
End If
' Add another row at the end
Dim oRows As RevisionTableRows = oRevTable.RevisionTableRows
oRows.Add()
oRevTable.UpdatePropertyToRevisionNumber(True)
End Sub

Sub PurgeRev(DrawDoc As DrawingDocument, visibleRowsWanted As Integer)
	For Each sheet As Sheet In ThisDrawing.Document.Sheets
  		For Each revTable As RevisionTable In Sheet.RevisionTables
    		Trace.WriteLine(" --- " & revTable.Title)
			Dim rows As RevisionTableRows = revTable.RevisionTableRows 
			Dim numberToHide As Integer = rows.Count - visibleRowsWanted
	If (numberToHide <= 0) Then Continue For
	For i = 1 To numberToHide
	  rows(i).Visible = False
	Next
  Next
Next
 End Sub
0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

Maybe try 

oRevTable.UpdatePropertyToRevisionNumber = True

In the error message it looks like it isn't reading the boolean assignment as you have written it. 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 7

GSK2019
Enthusiast
Enthusiast

It didn't work. It only reads True or False. I now have a MsgBox before it, and when i have

oRevTable.UpdatePropertyToRevisionNumber = True

It reads False and vise versa.

Nothing else happens 

0 Likes
Message 6 of 7

A.Acheson
Mentor
Mentor
Accepted solution

The reason your not seeing an update to the drawing revision is because the table is set up for sheet scope and not drawing scope.. The below adds a table with drawing scope meaning every revision table will update with the same revision.

   oRTB = oRTBs.Add2(oLocation, False, True, True, "A")
	oRTB.UpdatePropertyToRevisionNumber = True

 

AAcheson_0-1660064876737.png

I see there is more than one table is added so the detection of a table is likely not working correctly. 

AAcheson_1-1660065027735.png

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 7

GSK2019
Enthusiast
Enthusiast

Awesome! This works thank you so much!

0 Likes