Message 1 of 14
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm getting this error when running my code as an event trigger:
My code has nothing to do with Cables and Harnesses. The event trigger is creating a new document. It happens whether I put it in the "Drawings" or "This Document" tab. The code runs without the error when it's not an event trigger. Other codes ran with the same trigger in the same location do not produce the error. It doesn't matter what document I'm trying to draw, I've tried it on assemblies, weldments, and parts. It still allows the whole code to run fine. I'm running Inventor 2022.
Here is the code:
'Drawing Setup will take the form options and create the desired drawing template
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
iLogicForm.Show("Drawing Setup")
'Set the drawing size
Dim FormatName As String
FormatName = "COMPANY " + Parameter("DrawingSize")
Dim oFormat As SheetFormat
Try
oFormat = oDoc.SheetFormats.Item(FormatName)
Catch
MessageBox.Show("Sheet format does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
'Get default sheet
Dim dSheet As Sheet
dSheet = oDoc.ActiveSheet
'Select all views
Dim oSelect As SelectSet
oSelect = oDoc.SelectSet
oSelect.Clear
Dim oView As DrawingView
For Each oView In dSheet.DrawingViews
oSelect.Select(oView)
Next
Dim oSelectBool As Boolean
oSelectBool = oSelect.Count > 0
'Copy all views
Dim oCopy As ControlDefinition
If oSelectBool
oCopy = ThisApplication.CommandManager.ControlDefinitions.Item("AppCopyCmd")
oCopy.Execute
End If
'Add new sheet with chosen format
Dim oSheet As Sheet
oSheet = oDoc.Sheets.AddUsingSheetFormat(oFormat)
If oSelectBool
'Activate new sheet and select
oSheet.Activate
oDoc.SelectSet.Select(oSheet)
'Paste views
Dim oPaste As ControlDefinition
oPaste = ThisApplication.CommandManager.ControlDefinitions.Item("AppPasteCmd")
oPaste.Execute
End If
'Delete the default sheet
dSheet.Delete
'Construct the Title Block Name and Standard Style Name from the radio button options
Dim TitleBlockName As String = "COMPANY"
Dim styleChoice As String = "Company"
If Parameter("DrawingUnits") = "Metric"
TitleBlockName = TitleBlockName + " " + Parameter("DrawingUnits")
styleChoice = styleChoice + " " + Parameter("DrawingUnits")
End If
If Not Parameter("DrawingType") = "Part"
TitleBlockName = TitleBlockName + " " + Parameter("DrawingType")
End If
If Parameter("DualUnits")
styleChoice = styleChoice + " Assembly"
Else If Not Parameter("DrawingType") = "Part"
styleChoice = styleChoice + " " + Parameter("DrawingType")
End If
TitleBlockName = UCase(TitleBlockName + " " + Parameter("DrawingSize"))
'Check if title block name exists
Dim oTitleBlock As TitleBlockDefinition
Try
oTitleBlock = oDoc.TitleBlockDefinitions.Item(TitleBlockName)
Catch
MessageBox.Show("Title block name does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
'Delete out the title block and add the chosen one in
oSheet.TitleBlock.Delete
oSheet.AddTitleBlock(oTitleBlock)
'Get styles library
Dim oStylesLib As DrawingStandardStylesEnumerator = oDoc.StylesManager.StandardStyles
'Change drawing style
Dim oStyle As DrawingStandardStyle
Try
For Each oStyle In oStylesLib
If oStyle.Name = styleChoice Then
oDoc.StylesManager.ActiveStandardStyle = oStyle
Exit Try
End If
Next
Logger.Debug("Style " + styleChoice + " not found.")
Catch
MessageBox.Show("Style " + styleChoice + " not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Solved! Go to Solution.