09-19-2024
07:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-19-2024
07:38 AM
Hi @DeepshipEngineering. Here is an updated version of the code you posted above (in Message 6) that may offer more feedback, clarity, and error prevention. It may seem (or actually be) like overkill, but once you figure out and fix the issues you are having, using the informational feedback from this, you can simplify it back down again however you want.
'make sure the iLogic Log window (or at least its tab) is visible
ThisApplication.UserInterfaceManager.DockableWindows.Item("ilogic.logwindow").Visible = True
'get a reference to the drawing document, if one is available
Dim oDDoc As Inventor.DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
'if the document object obtained could not be 'Cast' (converted) to DrawingDocument then exit rule
If oDDoc Is Nothing Then
Logger.Debug("Rule named '" & iLogicVb.RuleName & "' did not obtain a DrawingDocument!")
Return 'or Exit Sub
End If
'make sure specific internal iLogic Form exists
Dim sFormName As String = "Create Drawing"
If Not iLogicForm.FormNames.Contains(sFormName) Then
Logger.Debug("Could not find internal iLogic Form named '" & sFormName & "'!")
Return 'or Exit Sub
End If
'show that specific internal iLogic Form, and capture how it gets closed
' call up list of sheets from parameter "Sheet_Format"
Dim oFRV As FormReturnValue = iLogicForm.Show(sFormName, FormMode.Modal)
'if it was canceled by Cancel button, 'X' button, or similar, then exit this rule also
If oFRV.Result = FormResult.Cancel OrElse
oFRV.Result = FormResult.None OrElse
oFRV.Result = FormResult.Close Then
Return 'or Exit Sub
End If
'make sure internal iLogic rule exists in this document, then try to run it
Dim sRuleName As String = "Sheet Formats"
If iLogicVb.Automation.GetRule(oDDoc, sRuleName) IsNot Nothing Then
Try
Dim i As Integer = iLogicVb.Automation.RunRule(oDDoc, sRuleName)
If i <> 0 Then 'will be -1 if it threw error, and zero if there was no error
Logger.Debug("Internal rule named '" & sRuleName & "' encountered an error when ran!")
'could exit this rule, since that rule encountered an error
'Return 'or Exit Sub
End If
Catch
Logger.Error("Internal rule named '" & sRuleName & "' could not be found in specified document!")
'exit this rule, since that rule did not run
Return 'or Exit Sub
End Try
End If
Dim oSheets As Inventor.Sheets = oDDoc.Sheets
Dim oSheet As Inventor.Sheet
If MyBooleanParam = True Then
If oSheets.Count > 1 Then
oSheet = oSheets.Item(2)
Try
oSheet.Delete
Logger.Info("Second Sheet Deleted")
Catch
Logger.Debug("Failed to delete second Sheet!")
End Try
End If
Else 'MyBooleanParam = False
Try
oSheet = oSheets.Item(1)
oSheet.Delete
Logger.Info("First Sheet Deleted")
Catch
Logger.Debug("Failed to delete first Sheet!")
MessageBox.Show("2nd sheet not found?", "iLogic")
Return
End Try
End If
Wesley Crihfield
(Not an Autodesk Employee)