Error getting BOMRows

Error getting BOMRows

Anonymous
Not applicable
904 Views
6 Replies
Message 1 of 7

Error getting BOMRows

Anonymous
Not applicable

Can someone please help with an error I'm getting when I try to access the BOMRowsEnumerator object ???

 

Dim oAsmComp As ComponentDefinition = oRefDoc.ComponentDefinition

 

Dim oBOM As BOM = oAsmComp.BOM

oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False

 

Dim oBOMView As BOMView = oBOM.BOMViews("Structured")

 

Dim oBOMRows As BOMRowsEnumerator = oBOMView.BOMRows

 

The error is generated on the red line and the details of it are:

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.BOMView.get_BOMRows()
at Costing.LmiRuleScript.PartCount(AssemblyDocument oRefDoc, StreamWriter oWrite, Int32& oCount, Int32& oManuPartCount, Int32& oAssemblyCount, Int32& oFastenerCount, Int32& oComponentCount)
at Costing.LmiRuleScript.OpTime(Document oRefDoc, StreamWriter oWrite, Int32 Amount)
at Costing.LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
905 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor

this works:

 

Dim oRefDoc As Inventor.AssemblyDocument
oRefDoc = ThisDoc.Document

Dim oAsmComp As Inventor.AssemblyComponentDefinition = oRefDoc.ComponentDefinition
 
Dim oBOM As BOM = oAsmComp.BOM


oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False

 
Dim oBOMView As BOMView = oBOM.BOMViews("Structured")
 
Dim oBOMRows As BOMRowsEnumerator = oBOMView.BOMRows

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 7

Anonymous
Not applicable

I run this rule in a sequence along with other rules. What I was finding is that it worked just fine when ran on its own. When run in sequence with other it would generate the error.

 

I got down to the bottom of which other rule was causing this one to fail. The rule that runs just before this one contained this:

 

AddVbFile "RunAllRulesUnderDocument.txt"

 

Dim ruleRunner = New RunAllRulesUnderDocument(iLogicVb, Component, "Base Data.ipt")
Dim doc = ThisDoc.Document ' This is required (indirectly) by the external rule so that it can use Inventor objects.

ruleRunner.RunAllRules("Top")

 

After commenting this out I don't get the error anymore when run in sequence. Any idea why this could cause that error?

 

 

0 Likes
Message 4 of 7

bradeneuropeArthur
Mentor
Mentor

Hi,

 

Be careful with declaring always as "document".

if meant Part than as "partDocument"

If meant Assembly as "Assemblydocument"

If meant drawing as "DrawingDocument"

 

This will be  the issue I think!

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 7

MechMachineMan
Advisor
Advisor

To further elaborate, it has been outlined in a blog by an Autodesk employee that the GENERIC document class does not work with the ComponentDefinition method in all cases, and is prone to issues. It is therefore better to use the specific document type if you are going to be accessing the component definition.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
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
Message 6 of 7

bradeneuropeArthur
Mentor
Mentor

we say toppie, for the explanation!

 

Again!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 7 of 7

FRFR1426
Collaborator
Collaborator

This can also happen when there is some missing references in the assembly (on 2021. On 2016, there is no exception thrown).

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
0 Likes