- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Event Trigger Error
I have a rule in a iAssembly to set the LOD to "iLogic" when the file is opened. When I set the Event Triggers to run that rule when the file is opened I get the following error.
The Rule is below. If someone could figure out what the issue is I would greatly appreciate it.
defaultLoD = "Main LoD"
customLoDExsits = False
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oLOD As LevelOfDetailRepresentation
Dim cLOD As LevelOfDetailEnum = kCustomLevelOfDetail
Dim oAsmCompDef As ComponentDefinition = doc.ComponentDefinition
Dim oFileManager As FileManager = ThisApplication.FileManager
strLastActiveLOD = oFileManager.GetLastActiveLevelOfDetailRepresentation(ThisDoc.PathAndFileName(True))
If oAsmCompDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.LevelOfDetail <> kCustomLevelOfDetail Then
For Each custLod In oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations
If custLod.Name = strLastActiveLOD Then
If custLod.LevelOfDetail = 56072 Then
custLod.Activate(True)
customLoDExsits = True
Exit For
End If
Else
If custLod.LevelOfDetail = 56072 Then
customLoDExsits = True
custLod.Activate(True)
Exit For
End If
End If
Next custLod
If customLoDExsits = False Then
Dim nLOD As LevelOfDetailRepresentation
nLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
oLOD = nLOD
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic").Activate(True)
End If
End If
InventorVb.DocumentUpdate()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello @Anonymous,
Before running the code, did you manually deleted customized LOG named as "iLogic" which is you are trying to get from this line:
oFileManager.GetLastActiveLevelOfDetailRepresentation(ThisDoc.PathAndFileName(True))
If you have activated LOD named as iLogic, then change LOD to the other one with deleting "iLogic" LOD to do test, the line of getting last active LOD would raise an error when you run the rule because it is actually deleted.
If the name of customized LOD is certain, recommend you to use the name string directly:
strLastActiveLOD = "iLogic"

Jane Fan
Inventor QA Engineer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I think the rule I have is a little more complex than I need. All i need is a LOD Rule that will set the LOD to iLogic whenever the assembly is opened. The LOD will always be called iLogic. Is there a simpler Rule I can use for that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Something like this should work.
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition = doc.ComponentDefinition
Try
oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic").Activate(True)
Catch
nLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
nLOD.Activate
End try
InventorVb.DocumentUpdate()
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Looking into it further I think the error is linked to the BOM, the error only pops up when I have "Run these rules when events occur" checked in Event Triggers. But I only see the error when in the drawing or when accessing the BOM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Seems very probably!
This code should be able to tell you where the issue is happening.
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition = doc.ComponentDefinition
Try
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic")
Catch
MsgBox("No iLogic LOD Found or error accessing it... Attemptin to add it!")
Try
nLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
Catch
MsgBox("Unable to Add iLogic LOD!")
Exit Sub
End try
End try
Try
oLOD.Activate
Catch
MsgBox("Error ACTIVATING LOD")
Exit Sub
End try
InventorVb.DocumentUpdate()
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
There was a small typo in what I previously posted.
But yeah, it's telling us that it's seeing everything; just not letting us activate it. And if you were to try to activate an LOD while you have a BOM open, you would notice you can't, so that is certainly the issue.
You can make the rule work by trapping it in an error, or by using control definitions in a error loop to close the BOM. There is no function call I can see that actually lets you know when the BOM is open, so you pretty much have to deal with the error trapping.
Dim doc as AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition = doc.ComponentDefinition
Try
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic")
Catch
MsgBox("No iLogic LOD Found or error accessing it... Attemptin to add it!")
Try
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
Catch
MsgBox("Unable to Add iLogic LOD!")
Exit Sub
End try
End try
Try
oLOD.Activate
Catch
MsgBox("Error ACTIVATING LOD")
Exit Sub
End try
InventorVb.DocumentUpdate()
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The issue to begin with is likely using LOD's for things other than memory management. It's not a supported workflow by autodesk and you are bound to run into more headaches than it's worth. Additionally, not very many people actually understand what it does, so they may mistakenly think that it removes the suppressed files from the BOM (it doesn't), or that it's a good method for hiding things in drawings (it isn't - that's what view reps were made for).
I tested things out.
If I put the rule into an assembly (TestLODAsm), and add the "after open" trigger to it, opening and closing that FILE itself runs the rule just file.
If I then put TestLODAsm into an assembly as a child, as soon as I start trying to switch the LOD in the top level assembly, it throws errors.
I believe the issue is because of the fact it's opening up multiple DOCUMENTS that belong to the same file name or improperly closing them, and it therefore gets confused and errors out.
The code below "KIND-OF" works, but only in the sense that on initial open of the document (ie; while its the active edit document), does it work.
Dim doc as AssemblyDocument = ThisDoc.Document
If Not doc.Equals(ThisApplication.ActiveEditDocument)
Exit Sub
End If
Dim oAsmCompDef As ComponentDefinition = doc.ComponentDefinition
Try
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("iLogic")
Catch
Try
oLOD = oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add("iLogic")
Catch
Exit Sub
End Try
End Try
Try
oLOD.Activate
Catch
MsgBox("Error ACTIVATING LOD")
Exit Sub
End Try
InventorVb.DocumentUpdate()
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm using rules to suppress and un-suppress parts, subassemblies, and parts within subassemblies when certain options are selected in a form. Its basically a generator we use with design assistant to easily create new drawings. The only way i figured out how to get it to work was using a custom LOD. Is there a more correct way of doing this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've never been too involved with workflows with a large number of different configurations; but It seems like Inventor likes functioning best if you have a unique model file for all unique part numbers. This would point to a workflow where you use multiple project files to manage a "Save & replace" type process.
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type