Hello to all.
I have a big problem using an iLogis Rule inside an IDW file.
I want to open an excell file and use the sheet values to replace .ipt files.
Now the rule works right without problems.
This is the code:
' Open the Excel ref file
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Excel Files (*.xls;*.xlsx)|*.xls;*.xlsx"
'oFileDlg.InitialDirectory = ThisDoc.Path
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
MessageBox.Show("File not chosen.", "Dialog Cancellation")
Exit Sub
ElseIf oFileDlg.FileName <> "" Then
selectedfile = oFileDlg.FileName
End If
On Error Goto 0
Dim DrawDoc as DrawingDocument
Dim RulesOnEventsStore As Boolean
RulesOnEventsStore = iLogicVb.Automation.RulesOnEventsEnabled
iLogicVb.Automation.RulesOnEventsEnabled = False
GoExcel.Open(selectedfile, "Sheet1")
' The two While cycles below are used to assign the values of the parameters
Dim aRow = 2
While GoExcel.CellValue("A" & aRow) <> ""
Dim aCol = 65
While GoExcel.CellValue(chr(aCol) & 1) <> ""
On Error Resume Next
Parameter(GoExcel.CellValue(chr(aCol) & 1)) = GoExcel.CellValue(chr(aCol) & aRow)
If Err.Number <> 0 Then
MessageBox.Show("The spreadsheet column title '" & GoExcel.CellValue(chr(aCol) & 1) & "' doesn't match any parameter name in the Inventor part. Please go back to the spreadsheet, change this title, save the file and launch the iLogic rule again.", "Warning: the iLogic rule will be stopped now!")
Exit Sub
Else
aCol = aCol + 1
End If
On Error Goto 0
End While
'replace
doc = ThisDoc.Document
Dim oFD As FileDescriptor
oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(ThisDoc.Path & "\" & Parameter("MaterialCode") & ".ipt")
doc.Update()
'save as
ThisDoc.Document.SaveAs(ThisDoc.Path & "\IDW\" & Parameter("MaterialCode") & ".idw", True)
aRow = aRow + 1
End While
'message
MessageBox.Show("Process Complete", "Message")
The main problem is about this row:
GoExcel.Open(selectedfile, "Sheet1")
Now it works because the sheet name is "Sheet1".
But some people use the Italian or German excell version or other langages.
I want that the rule opens always the first sheet in excell, regardless of the name of the sheet.
How can I do it?
Please help me.