Loop Through all sheets, delete revision rows, delete revision block. problem

pschell
Contributor
Contributor

Loop Through all sheets, delete revision rows, delete revision block. problem

pschell
Contributor
Contributor

Hello all,

 

I have a bit of code that i created with Inventor 2016. We recently updated to Inventor 2018 and now my code is not working properly. I have tried figuring out how to fix the problem and I'm stumped. 

Sub Main RemoveAllTags()
	Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
	Dim i As Integer = 1
	Dim oRTB As RevisionTable = oDrawDoc.ActiveSheet.RevisionTables.Item(i)
	Dim oRow As RevisionTableRow
	Dim oSheet As Sheet

	For Each oSheet In oDrawDoc.Sheets
		oSheet.Activate
		oSheet.Update

		Try	'try to get the first rev table on the active sheet
			oRTB = oDrawDoc.ActiveSheet.RevisionTables.Item(i)
		Catch 'catch error when no rev table is found
			MessageBox.Show("Error: No Revision Table was found", "iLogic")
		End Try

		Dim oRows As RevisionTableRows

		oRows.Add()

		For Each oRow In oRows
			If oRow.IsActiveRow Then

			Else
				oRow.Delete
			End If
		Next

		oRTB.Delete

	Next

End Sub

 This is my original code snippet that has ceased to work. I have done some troubleshooting on it and have found that it breaks on "oRows.add()". If anyone can help me on this I would greatly appreciate it. Attached is the Error in Rule that pops up when i run the code.

 

thanks

0 Likes
Reply
Accepted solutions (1)
1,256 Views
4 Replies
Replies (4)

pschell
Contributor
Contributor

Nevermind. I fixed it. :

Sub Main RemoveAllTags()
	Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
	Dim i As Integer = 1
	Dim oRTB As RevisionTable = oDrawDoc.ActiveSheet.RevisionTables.Item(i)
	Dim oRow As RevisionTableRow
	Dim oSheet As Sheet

	For Each oSheet In oDrawDoc.Sheets
		oSheet.Activate
		oSheet.Update

		Try	'try to get the first rev table on the active sheet
			oRTB = oDrawDoc.ActiveSheet.RevisionTables.Item(i)
		Catch 'catch error when no rev table is found
			MessageBox.Show("Error: No Revision Table was found", "iLogic")
		End Try

		Dim oRows As RevisionTableRows = oRTB.RevisionTableRows
		oRows.Add()

		For Each oRow In oRows
			If oRow.IsActiveRow Then

			Else
				oRow.Delete
			End If
		Next

		oRTB.Delete

	Next

End Sub

If anyone is looking for ilogic code to iterate through all sheets, to delete revision tags and revision blocks ... then this works. thanks 

pschell
Contributor
Contributor
Accepted solution

On further testing of my code, every time I had a sheet with no revision table I would get an error.

I have modified my previous code extensively to produce this:

 
Sub Main RemoveAllTags()
	Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument

	For Each oSheet In oDrawDoc.Sheets
		oSheet.activate
		ProcessSheet(oSheet)
	Next
	oDrawDoc.Update
End Sub


Sub ProcessSheet(oSheet As Sheet)

	If oSheet.RevisionTables.Count = 0 Then
		On Error Resume Next
	End If
	
	Dim oRTB As RevisionTable = oSheet.RevisionTables.Item(1)

	Dim oRows As RevisionTableRows = oRTB.RevisionTableRows
	oRows.Add()

	Dim oRow As RevisionTableRow = oRTB.RevisionTableRows.Item(oRTB.RevisionTableRows.Count)
	For Each oRow In oRows
		If oRow.IsActiveRow Then

		Else
			oRow.Delete
		End If
	Next

	oRTB.Delete

End Sub
 

Now there are no errors and this works every time. 

Hope this helps someone else out there.

 

 

0 Likes

G.Binl
Advocate
Advocate

Thanks for the Code it worked great,

I add some code to it hop you or someone else can use it. 

it just places the Table where you wanted. 

 

Next
oRTB.Delete
oDrawDoc = ThisApplication.ActiveDocument
Dim oRTBs As RevisionTables
oRTBs = oDrawDoc.ActiveSheet.RevisionTables

Dim oLocation As Point2d
oLocation = ThisApplication.TransientGeometry.CreatePoint2d(68.08999997, 9.780835)

oRTB = oRTBs.Add(oLocation)

End Sub

0 Likes

Jusdoo
Contributor
Contributor

I have developed an app to operate revision tables. For trial version, it just limits the time and number of sheets to use. hope it will help.

 

https://apps.autodesk.com/INVNTOR/en/Detail/Index?id=7788639131627009214&appLang=en&os=Win64