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

iLogic Error Help!!

Hi Guys,

 

I am receiving an error after the "cancel" button event on an input box.

The rule runs fine when entering a value into the inputbox.

 

But, after the inputbox is cancelled, the next time it is run, it gives the following error. I have pasted the code below.

Please any help, I have searched for help on vb and ilogic and I can't find anything!

 

 

 

Error in rule: ISSUE REVISION, in document: ILOGIC.ipt

Object reference not set to an instance of an object.

 

(More Info)

 

System.NullReferenceException: Object reference not set to an instance of an object.

at iLogic.GoExcel.SetCurrentSheet(String fileName, String sheetName)

at iLogic.GoExcel.GetCell(String cellAddress)

at iLogic.GoExcel.get_CurrentCellValue(String cellAddress)

at LmiRuleScript.Main()

at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

 

 

 

 

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 49705 StartFragment: 314 EndFragment: 49673 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

'Setup .ipt parameters
Section = Left(Parameter("SECTION"),1) 'Type (mechanical, Fluid)
Struct = Left(Parameter("STRUCTURE"),1) 'Assembly or Component

'define the file to create/open
Worksheet = "Z:\CAD\DESIGN ENVIRONMENT\iLogic\PN.xlsx"
Sheetno = ("Sheet1")

'check for existing file 
If Dir(Worksheet) <> "" Then
'workbook exists, open it
GoExcel.Open(Worksheet, Sheetno)

'save current iproperty value
OldRevisionNumber = iProperties.Value("Project", "Revision Number")
'set new revision number to input box value
NewRevisionNumber = InputBox("Enter the new Revision Number e.g. B", "iLogic", NewRevisionNumber)


If NewRevisionNumber = "" Then
'catch an empty input or user pressing cancel button
MessageBox.Show("Please Enter a Valid Revision Number", "Error Handler ")
Return
Else
End If


'store revision number in iproperties
iProperties.Value("Project", "Revision Number") = NewRevisionNumber
' Open excel 
GoExcel.Open(Worksheet, Sheetno)
' Define Range
RowStart = 2
RowEnd = 10000

'Find the first empty cell
For count = RowStart To RowEnd
    ' If it's blank count it
    If String.IsNullOrEmpty(GoExcel.CellValue("C" & count)) Then 
    ' Row Number is equal to the current row
        rowN = count
        'Exit For loop
        Exit For
    End If
Next

MessageBox.Show("Inserting Data on Row " & rowN, "Updating Database...")
' Enter & Read values back from Excel Spreadsheet
Filename = iProperties.Value("Project", "Part Number") & iProperties.Value("Project", "Revision Number")& "_" & iProperties.Value("Project", "Description")
GoExcel.CellValue("C" & RowN) = iProperties.Value("Project", "Part Number")
GoExcel.CellValue("D" & RowN) = iProperties.Value("Project", "Revision Number")
GoExcel.CellValue("E" & RowN) = iProperties.Value("Project", "Description")
GoExcel.CellValue("F" & RowN) = Filename
iProperties.Value("Project", "Designer") = iProperties.Value("Summary", "Author")
Filename = GoExcel.CellValue("F" & rowN)
'save excel
GoExcel.Save
MessageBox.Show("Your Unique Part Number is " & Filename, "Updating Database...")
'
'
'define the active document
oDoc = ThisDoc.Document
'create a file dialog box
Dim oFileDlg2 As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg2)

'check file type and set dialog filter
If oDoc.DocumentType = kPartDocumentObject Then
oFileDlg2.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
oFileDlg2.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
oFileDlg2.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"
End If


'set the directory to open the dialog at
oFileDlg2.InitialDirectory = ThisDoc.WorkspacePath()
'set the file name string to use in the input box
oFileDlg2.FileName = Filename

'work with an error created by the user backing out of the save 
oFileDlg2.CancelError = True
On Error Resume Next
'specify the file dialog as a save dialog (rather than a open dialog)
oFileDlg2.ShowSave()

'catch an empty string in the imput
If Err.Number <> 0 Then
'MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")

'Enter Code which removes last entry from Spreadsheet if cancelled
GoExcel.Open(Worksheet, Sheetno)
For count = RowStart To RowEnd
    ' If it's blank count it
    If String.IsNullOrEmpty(GoExcel.CellValue("C" & count)) Then 
    ' Last entry was on bottom row minus 1
        rowN = count -1
        
        'Exit For loop
        Exit For
    End If
Next
'if cancelled, 
iProperties.Value("Project", "Revision Number") = OldRevisionNumber
'Clear entries in these rows for unsaved part
GoExcel.CellValue("A" & rowN) = ""
GoExcel.CellValue("B" & rowN) = ""
GoExcel.CellValue("C" & rowN) = ""
GoExcel.CellValue("D" & rowN) = ""
GoExcel.CellValue("E" & rowN) = ""
GoExcel.CellValue("F" & rowN) = ""

GoExcel.Save

MessageBox.Show("No File Saved." &vbLf & "Removing Last Entry From Database...")

ElseIf oFileDlg2.FileName <> "" Then
MyFile = oFileDlg2.FileName
'save the file 
oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As

End If

iLogicVb.UpdateWhenDone = True
Else
MessageBox.Show("Excel Failed to Open." &vbLf & "Ensure Engineering Root is mapped to Z:/", "Error Handler")

End If