Inventor 2019 Crashing on iLogic Title Block Replacement

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all you wonderful people.
Firstly I'd like to say how grateful I am to you all. You have made my journey though automation of laborious tasks a joy.
However for the first time I have come across an issue I just can't seam to find on this great site.
I have an external iLogic rule that strips out borders and title blocks in drawings, loads all the drawing resources from the template file (title blocks, border and sketch symbols) and then proceeds to update all global styles, set the Style Standard.
The last command in the rule is to iterate through the sheets of the drawing and insert the latest and greatest title block and border. And here is where my issue lies...
For the longest time the rule worked perfectly, then I started to get errors occasionally and now the rule is alternating between working, throwing the error and crashing Inventor?! After a bit of debugging (putting in message boxes after each section of code) I found that the ActiveSheet.Titleblock command was what was causing the issue.
The error that is thrown is here:
Error Message:
Error in rule: DrawingResourceUpdate, in document: P2017-130-1902A-Upper Chute Welded Assembly.idw
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
More info:
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.Sheet.AddBorder(Object BorderDefinition, Object PromptStrings)
at Autodesk.iLogic.Runtime.TitleBlockAndBorder.SetBorder(String name, String[] promptedEntries)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
The code I wrote (with more than a little help from this site) is as follows but please bare in mind that I am no coder and I apologise for how shoddy this is!
Sub Main() If ThisApplication.ActiveDocument Is Nothing Or ThisApplication.ActiveDocumentType <> kDrawingDocumentObject Then MsgBox ("Please open a Drawing to work on.") Exit Sub End If Dim oTemplate As DrawingDocument Dim odrawdoc As DrawingDocument
Dim oSheet As Sheet Dim oSourceTitleBlockDef As TitleBlockDefinition Dim oSourceBorderDef As BorderDefinition odrawdoc = ThisApplication.ActiveDocument oSheet = odrawdoc.ActiveSheet 'Clear out the old Titleblocks & Border For Each oSheet In odrawdoc.Sheets oSheet.Activate If Not odrawdoc.ActiveSheet.TitleBlock Is Nothing Then odrawdoc.ActiveSheet.TitleBlock.Delete End If If Not odrawdoc.ActiveSheet.Border Is Nothing Then odrawdoc.ActiveSheet.Border.Delete End If Next oSheet 'MessageBox.Show("DELETE ACTIVE BLOCKS & BORDERS COMPLETE", "Title") updateStyles (odrawdoc) 'MessageBox.Show("GLOBAL STYLES UPDATED", "Title") DeleteBorders (odrawdoc) 'MessageBox.Show("BORDERS UPDATED", "Title") DeleteTitleBlocks (odrawdoc) 'MessageBox.Show("TITLE BLOCKS UPDATED", "Title") 'the styles collection Dim oStandardDesignStyles As DrawingStandardStylesEnumerator = odrawdoc.StylesManager.StandardStyles 'the current active style Dim oActiveStandardStyle As DrawingStandardStyle = odrawdoc.StylesManager.ActiveStandardStyle 'MsgBox(oActiveStandardStyle.Name) 'find the right style and set it then exit Dim oStandardStyle As DrawingStandardStyle For Each oStandardStyle In oStandardDesignStyles If oStandardStyle.Name = "CoC Default Standard (ANSI)" Then odrawdoc.StylesManager.ActiveStandardStyle = oStandardStyle End If Next 'MessageBox.Show("DRAWING STANDARD SET", "Title") oTemplate = ThisApplication.Documents.Open(ThisApplication.FileOptions.TemplatesPath & "Standard(2018).idw",False) 'MessageBox.Show("TEMPLATE FILE SET", "Title") For Each oSourceTitleBlockDef in oTemplate.TitleBlockDefinitions If oSourceTitleBlockDef.Name <> "ANSI - Large" Then oSourceTitleBlockDef.CopyTo(odrawdoc, True) End If Next oSourceTitleBlockDef 'MessageBox.Show("TITLE BLOCKS COPIED", "Title") For Each oSourceBorderDef in oTemplate.BorderDefinitions If oSourceBorderDef.Name <> "Default Border" Then oSourceBorderDef.CopyTo(odrawdoc, True) End If Next oSourceBorderDef 'MessageBox.Show("BORDERS COPIED", "Title") oTemplate.Close 'MessageBox.Show("TEMPLATE CLOSED", "Title") Dim oSketchSymLib As SketchedSymbolDefinitionLibrary oSketchSymLib = odrawdoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries.Item("CoC Symbols") For Each oSketchSym in oSketchSymLib.SketchedSymbolDefinitions Dim oSSDEf As SketchedSymbolDefinition oSSDef = odrawdoc.SketchedSymbolDefinitions.AddFromLibrary(oSketchSymLib, oSketchSym.Name, True) Next 'MessageBox.Show("SKETCH SYMBOLS UPDATED", "Title") For Each oSheet In odrawdoc.Sheets oSheet.Activate ActiveSheet.Border = "CoC Default" ActiveSheet.TitleBlock = "CoC Imperial" Next oSheet 'MessageBox.Show("TITLE BLOCK AND BORDER INSERTED", "Title") oSheet.Activate End Sub Sub DeleteTitleBlocks(oActiveDoc As Inventor.DrawingDocument) 'Iterate through the collection deleting any titleblocks that are not referenced by the drawing object Dim oTitle As TitleBlockDefinition For Each oTitle In oActiveDoc.TitleBlockDefinitions If oTitle.IsReferenced = False Then oTitle.Delete End If Next End Sub Sub DeleteBorders(oActiveDoc As Inventor.DrawingDocument) 'Iterate through the collection deleting any titleblocks that are not referenced by the drawing object Dim oBorder As BorderDefinition For Each oBorder In oActiveDoc.BorderDefinitions If oBorder.IsReferenced = False Then oBorder.Delete End If Next End Sub Sub updateStyles(oActiveDoc As Inventor.DrawingDocument) Dim oStyle As Style For Each oStyle In oActiveDoc.StylesManager.Styles If oStyle.UpToDate = False Then oStyle.UpdateFromGlobal() End If Next End Sub
I hope I have covered all the required information.
I'd love to know what I'm doing wrong and how to fix it.
Thanks,
Chris