Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Error in code while running Event Triggers

b.slootenMHLJY
Observer

Error in code while running Event Triggers

b.slootenMHLJY
Observer
Observer

Good day,

 

Since we migrated from Inventor 2018 to Inventor 2023 I get a strange error.

The bit of code shown a bit more down runs with the iLogic Event Trigger when the drawing is opened.

In 2018 all was fine but now I get the following error:

Error.jpg

 

The strange thing is is that the code runs perfectly fine when I run it manually....

 

Here is the code I'm running:

It looks up some values in the revision table and then puts it in some custom iProperties.

 

'xxx
'xxx
'xxx


	' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
    oDrawDoc = ThisApplication.ActiveDocument

    ' Set a reference to the first revision table on the active sheet.
    ' This assumes that a revision table is on the active sheet.
    Dim oRevTable As RevisionTable
    oRevTable = oDrawDoc.ActiveSheet.RevisionTables.Item(1)

	    ' Iterate through the contents of the revision table.
	    Dim Rij As Long
	    For Rij = 1 To oRevTable.RevisionTableRows.Count
	        ' Get the current row.
	        Dim oRow As RevisionTableRow
	        oRow = oRevTable.RevisionTableRows.Item(Rij)

	    ' Iterate through column 2 in the row.
	    Dim Kolom As Long
	    For Kolom = 2 To 2'oRevTable.RevisionTableColumns.Count
			
	        ' Get the current cell.
	        Dim oCell As RevisionTableCell
	        oCell = oRow.Item(Kolom)
			
		
            ' Display the value of the current cell
			' MsgBox("Row: " & Rij & ", Column: " & oRevTable.RevisionTableColumns.Item(Kolom).Title & " = " & oCell.Text)
			
		' Write value of current cell to the following iProperties
		iProperties.Value("Custom", "NL_META_UITGAVE") = oCell.Text
		iProperties.Value("Custom", "NL_META_CONTROL_DATUM") = oCell.Text
        
		Next
		
    Next

 

I hope some of you can enlighten me where this goes wrong.

0 Likes
Reply
163 Views
2 Replies
Replies (2)

WCrihfield
Mentor
Mentor

Hi @b.slootenMHLJY.  You may need to change from using ThisApplication.ActiveDocument to using ThisDoc.Document to set the value of your initial oDrawDoc variable, because it is possible, in some situations for it to be pointing to the wrong document (one you are not expecting).  It will not be a problem when you have that drawing visibly open, and the 'active' document when you manually run the rule, but it can be a problem if triggered to run in other ways, or while other documents are open, where that drawing may not actually be the 'active' document.  It may also help avoid potential errors by integrating a DocumentType check in those first few lines, to make sure you are working with a DrawingDocument, instead of just assuming it will be one.  If it is not a DrawingDocument, then trying to access the ActiveSheet will fail.

 

Here is an example bit of code you could use instead:

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oDrawDoc As DrawingDocument = ThisDoc.Document

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

WCrihfield
Mentor
Mentor

Another thing that could be happening, since the error mentioned line 14, and an object reference not being set to an instance of an object, is that your not finding that first RevisionTable object on the active sheet.  There may simply not be a RevisionTable object on the 'active' sheet of that drawing.  You could avoid this error by checking If RevisionTables.Count = 0.  If that check is true, you may just want to exit the rule at that point, or move on to some other process.  Or you could try looping through all sheets and checking their RevisionTables.Count, to find a sheet with one on it, then when you find a sheet with more than zero, proceed to get the first one, then exit the loop.  And if no RevisionTable was gotten within that loop, exit the rule, or that part of the overall code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes