<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic iLogic Setting LOD Causing Error When Opening BOM in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-setting-lod-causing-error-when-opening-bom/m-p/5575705#M55153</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some assemblies that contain the following iLogic code to set a custom Level Of Detail called "Automated Model".&lt;/P&gt;&lt;P&gt;I need this to run straight after opening the document so this iLogic code is set to trigger after open document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'SETTING LEVEL OF DETAIL
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oLOD As LevelOfDetailRepresentation
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Automated Model")
oLOD.Activate(True)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code works fine but when I open the Bill Of Materials dialogue box, I encounter the following unspecified error:&lt;/P&gt;&lt;P&gt;Error in rule: Setting Level Of Detail, in document: COLUMN 1.iam&lt;/P&gt;&lt;P&gt;Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe when opening the BOM dialogue box, Inventor interprets this as opening of the document and the BOM loads in the 'Master' LOD.&lt;/P&gt;&lt;P&gt;The iLogic code only needs to run once straight after opening the document and not when opening the BOM.&lt;/P&gt;&lt;P&gt;Therefore I have tried to modify the above iLogic code with a Try / Catch statement but it seems to have no effect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Try
'SETTING LEVEL OF DETAIL
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oLOD As LevelOfDetailRepresentation
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Automated Model")
oLOD.Activate(True)
Catch ex As System.ArgumentException
'END CODE TO PREVENT AN UNSPECIFIED ERROR DIALOGUE BOX APPEARING WHEN OPENING BILL OF MATERIALS
End Try&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an alternative, I have tried to write some code to only trigger the rule when there is no BOM dialogue box is open but I am unsure how to write this code. The closest I come to writing it is as follows but this does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;If
Dim oCtrlDef As ControlDefinition
oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyBillOfMaterialsCmd")
oCtrlDef.Execute Then
iLogicVb.RunRule("Setting Level Of Detail") = False
Else
iLogicVb.RunRule("Setting Level Of Detail") = True
End If&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached a small example model. (Note that the code I have tried writing is contained within the COLUMN 1.iam file).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone has any idea how to correct the unspecified error or how to my correct my work-around codes then it would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kurt.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2015 13:46:21 GMT</pubDate>
    <dc:creator>kwalker1</dc:creator>
    <dc:date>2015-04-08T13:46:21Z</dc:date>
    <item>
      <title>iLogic Setting LOD Causing Error When Opening BOM</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-setting-lod-causing-error-when-opening-bom/m-p/5575705#M55153</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some assemblies that contain the following iLogic code to set a custom Level Of Detail called "Automated Model".&lt;/P&gt;&lt;P&gt;I need this to run straight after opening the document so this iLogic code is set to trigger after open document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'SETTING LEVEL OF DETAIL
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oLOD As LevelOfDetailRepresentation
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Automated Model")
oLOD.Activate(True)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code works fine but when I open the Bill Of Materials dialogue box, I encounter the following unspecified error:&lt;/P&gt;&lt;P&gt;Error in rule: Setting Level Of Detail, in document: COLUMN 1.iam&lt;/P&gt;&lt;P&gt;Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe when opening the BOM dialogue box, Inventor interprets this as opening of the document and the BOM loads in the 'Master' LOD.&lt;/P&gt;&lt;P&gt;The iLogic code only needs to run once straight after opening the document and not when opening the BOM.&lt;/P&gt;&lt;P&gt;Therefore I have tried to modify the above iLogic code with a Try / Catch statement but it seems to have no effect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Try
'SETTING LEVEL OF DETAIL
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oLOD As LevelOfDetailRepresentation
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Automated Model")
oLOD.Activate(True)
Catch ex As System.ArgumentException
'END CODE TO PREVENT AN UNSPECIFIED ERROR DIALOGUE BOX APPEARING WHEN OPENING BILL OF MATERIALS
End Try&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an alternative, I have tried to write some code to only trigger the rule when there is no BOM dialogue box is open but I am unsure how to write this code. The closest I come to writing it is as follows but this does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;If
Dim oCtrlDef As ControlDefinition
oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AssemblyBillOfMaterialsCmd")
oCtrlDef.Execute Then
iLogicVb.RunRule("Setting Level Of Detail") = False
Else
iLogicVb.RunRule("Setting Level Of Detail") = True
End If&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached a small example model. (Note that the code I have tried writing is contained within the COLUMN 1.iam file).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone has any idea how to correct the unspecified error or how to my correct my work-around codes then it would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kurt.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2015 13:46:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-setting-lod-causing-error-when-opening-bom/m-p/5575705#M55153</guid>
      <dc:creator>kwalker1</dc:creator>
      <dc:date>2015-04-08T13:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: iLogic Setting LOD Causing Error When Opening BOM</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-setting-lod-causing-error-when-opening-bom/m-p/5575744#M55154</link>
      <description>&lt;P&gt;Never mind about the above question.&lt;/P&gt;&lt;P&gt;I just realised my error with the try / catch statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just needed to delete the "ex As System.ArgumentException" after the Catch.&lt;/P&gt;&lt;P&gt;All works well now.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2015 14:01:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/ilogic-setting-lod-causing-error-when-opening-bom/m-p/5575744#M55154</guid>
      <dc:creator>kwalker1</dc:creator>
      <dc:date>2015-04-08T14:01:53Z</dc:date>
    </item>
  </channel>
</rss>

