iLogic Setting LOD Causing Error When Opening BOM

iLogic Setting LOD Causing Error When Opening BOM

kwalker1
Enthusiast Enthusiast
558 Views
1 Reply
Message 1 of 2

iLogic Setting LOD Causing Error When Opening BOM

kwalker1
Enthusiast
Enthusiast

Hi All,

 

I have some assemblies that contain the following iLogic code to set a custom Level Of Detail called "Automated Model".

I need this to run straight after opening the document so this iLogic code is set to trigger after open document.

 

'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)

 

The code works fine but when I open the Bill Of Materials dialogue box, I encounter the following unspecified error:

Error in rule: Setting Level Of Detail, in document: COLUMN 1.iam

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

I believe when opening the BOM dialogue box, Inventor interprets this as opening of the document and the BOM loads in the 'Master' LOD.

The iLogic code only needs to run once straight after opening the document and not when opening the BOM.

Therefore I have tried to modify the above iLogic code with a Try / Catch statement but it seems to have no effect.

 

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

 

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.

 

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

 

I have attached a small example model. (Note that the code I have tried writing is contained within the COLUMN 1.iam file).

 

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.

 

Regards,

Kurt.

0 Likes
Accepted solutions (1)
559 Views
1 Reply
Reply (1)
Message 2 of 2

kwalker1
Enthusiast
Enthusiast
Accepted solution

Never mind about the above question.

I just realised my error with the try / catch statement.

 

I just needed to delete the "ex As System.ArgumentException" after the Catch.

All works well now.

0 Likes