Problem with numbering of revision rows and other issues - Ilogic

Problem with numbering of revision rows and other issues - Ilogic

christian_a6KG7M
Participant Participant
480 Views
6 Replies
Message 1 of 7

Problem with numbering of revision rows and other issues - Ilogic

christian_a6KG7M
Participant
Participant

Hi,

 

I am looking to make make a event trigger that will add a revision table then the iproperty revision number are 1 and then every time the revision number are changed it should add a new row. here i have a few bumps in the road. 

  • first of all i want the trigger to only add a new row when the iproperty revision number changes. as it is today, the trigger ads a new row every time the trigger is run even if the value is not changed.

 

  • Also, the value of the iproperty revision number should not be affected by adding a new row because this value is set in the part instead. Today this is being changed along with adding a new revision row.

 

  • Next problem is the numbering of the revisions. when there is added more than 2 rows the number of previously revisions are changed to 1 and it is only the last row that has the correct revision number. how do i make it not changing the revision numbers before the last one?

christian_a6KG7M_0-1708689202746.png

here is my code:

 

Sub main()
Dim Odoc As Document = ThisDoc.Document
	Dim DrawDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet
	Dim RevTableCount As Integer = 0
	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
    oLocation = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
	
   		oRTB = oRTBs.Add2(oLocation, False, True, True, "1")
		oRTB.UpdatePropertyToRevisionNumber = True
End Sub

Sub Stylesedit (Odoc As Document)
	Dim oDocStyles As Inventor.DrawingStylesManager
	Dim oRevStyle As RevisionTableStyle
	Dim oRevisionTable As RevisionTable
	Dim oLocation As Point2d 
	
	'Kontrollerar vilken Border ritningen har och lägger in rätt sorts revisionstabell
	If ActiveSheet.Border = "A4 Stående" Then
    oDocStyles = Odoc.StylesManager
    oRevStyle = oDocStyles.RevisionTableStyles.Item("Revision A4 Stående")
    oRevisionTable = Odoc.Sheets(1).RevisionTables(1)
	
	oRevisionTable.Style = oRevStyle
	Else

    oDocStyles = Odoc.StylesManager
    oRevStyle = oDocStyles.RevisionTableStyles.Item("Revision")
    oRevisionTable = Odoc.Sheets(1).RevisionTables(1)
	
	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 oRows As RevisionTableRows = oRevTable.RevisionTableRows
	Dim r As Inventor.RevisionTableRow = oRows.Add()
	Dim rnmbr As Integer = Asc(r.Item(1).Text) - 63
	r.Item(1).Text = rnmbr

End Sub







Thanks in advance!

Regards,

Christian

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

A.Acheson
Mentor
Mentor

Hi @christian_a6KG7M 

For items 1 and 2 in the drawing these things are linked by the below line. You add a revision row and the value in the revision row is updated to the titleblock revision. 

 

If you need to change the revision or any part of the revision row without adding a new row you need to target each table cell. 

 

oRTB.UpdatePropertyToRevisionNumber = True

 

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

christian_a6KG7M
Participant
Participant

@A.Acheson thanks! 

Now the problem with the numbering is solved.

But I want also that the code to compare the last revision number in the table with the iproperty value. if these two are not the same. then the code should add an new revision row with the new revision number that is in iproperty.

Is this possible?

i have tried a bit but with no success.

0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

Is the iproperty coming from the drawing revision number or the model revision number? Can you post your attempt to see where it is going wrong for you?

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

christian_a6KG7M
Participant
Participant

The property is coming from the model. I have selected by inventors settings that the revision number should be copied from the model to the drawing.

 

From row 72 in the code. I have tried to compare the revision number value  from the revision table with the value in iproperty. if they are equal then the code shall skip adding a row else continue adding row.

 

Sub main()
Dim Odoc As Document = ThisDoc.Document
	Dim DrawDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet
	Dim RevTableCount As Integer = 0
	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
    oLocation = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
	
   		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 
	
	'Kontrollerar vilken Border ritningen har och lägger in rätt sorts revisionstabell
	If ActiveSheet.Border = "A4 Stående" Then
    oDocStyles = Odoc.StylesManager
    oRevStyle = oDocStyles.RevisionTableStyles.Item("Revision A4 Stående")
    oRevisionTable = Odoc.Sheets(1).RevisionTables(1)
	
	oRevisionTable.Style = oRevStyle
	Else

    oDocStyles = Odoc.StylesManager
    oRevStyle = oDocStyles.RevisionTableStyles.Item("Revision")
    oRevisionTable = Odoc.Sheets(1).RevisionTables(1)
	
	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 = iProperties.Value("Project", "Revision Number") Then
	
	Else
	Dim oRows As RevisionTableRows = oRevTable.RevisionTableRows
	r = oRows.Add()
	Dim rnmbr As Integer = Asc(r.Item(1).Text) - 63
	r.Item(1).Text = rnmbr
	End If
End Sub

 

This is the error message I get when I run the code.

 

Error on line 75 in rule: Rule2, in document: Test.dwg

A matching overlay cannot be found because no public = can be called with these arguments:
'Public Shared Operator =(a As String, b As String) As Boolean':
The argument match parameter a cannot convert from __ComObject to String.

 

 

0 Likes
Message 6 of 7

A.Acheson
Mentor
Mentor
Accepted solution

Line 75  is checking cell object = to string object. You need to check a string object against a string object. See API help here

 

So the error message is correct in saying you can't convert a com object to string. 

 

 

 

If oRev.Text = iProperties.Value("Project", "Revision Number") Then

 

 

 

 

I haven't checked the rest of the code but that is your immediate issue.

 

Another potential issue I see is the iproperty being set in the titleblock before the revision block. In normal operation the revision row is updated first and the update line mentioned earlier  will sync the titleblock to the  revision row. 

 

If you want to read the part revision number seperate to it being pulled to the drawing these are the lines to do it. It looks at the first view model document. It is just another method if you need it.  

Dim drawDoc As DrawingDocument = ThisApplication.ActiveDocument 
Dim modelDoc As Document = drawingDoc.ReferencedDocuments.Item(1)
Dim revNo as String = modelDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value

 

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

christian_a6KG7M
Participant
Participant
Thanks, that will do it!