Second call to BOMQuantity.GetBaseQuantity unhandled exception

Second call to BOMQuantity.GetBaseQuantity unhandled exception

prussellZXB3F
Enthusiast Enthusiast
604 Views
4 Replies
Message 1 of 5

Second call to BOMQuantity.GetBaseQuantity unhandled exception

prussellZXB3F
Enthusiast
Enthusiast

I'm on Inventor 2019.4.1 using ilogic trying to get the BOM quantity/length, I can get the length of the first item but after that any call to BOMQuantity.GetBaseQuantity() fails.

 

Is this a known bug?

 

Cut and paste code if you want to test

Dim doc As AssemblyDocument
If ThisApplication.ActiveDocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
	doc = ThisApplication.ActiveDocument
Else
	MessageBox.Show("You've got to have an assembly as the active document to run the tool")
	Exit Sub
End If

Dim allParts As ComponentOccurrencesEnumerator
allParts = doc.ComponentDefinition.Occurrences.AllLeafOccurrences

For Each part As ComponentOccurrence In allParts
	If part.Definition.BOMQuantity.BaseUnits = "m" Or part.Definition.BOMQuantity.BaseUnits = "mm" Then
		MessageBox.Show(part.Name)
		MessageBox.Show(part.Definition.BOMQuantity.BaseUnits)
		Dim val As Inventor.Parameter
		Dim type As BOMQuantityTypeEnum
		part.Definition.BOMQuantity.GetBaseQuantity(type, val)
		MessageBox.Show(val.Value)
	End If
Next

 

0 Likes
Accepted solutions (1)
605 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @prussellZXB3F.  You may need to check the returned value of the variable "type", before trying to use the variable "val", because if "type" is not based on a parameter (like 'Each'), it won't return a parameter, therefore "val" is still Nothing, and you are trying to show its value in a message box when the variable's value hasn't been set yet.  Check out the online help page for the method (BOMQuantity.GetBaseQuantity()).

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

prussellZXB3F
Enthusiast
Enthusiast

Cheers for taking a look .

 

I don't thing that is the issue as I'm checking for base unit is either mm or m before trying to pull the parameter.

 

Also I through testing I'm pretty sure it only works on the first component it hits.

I've got several CC parts in an assembly that have length property as their BOM qty. I got the error but couldn't see any difference between the part it worked on and those it didn't. I then deleted the component that worked from the assembly and now the part that followed and was failing now works, everything after it still fails?!

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Next I'm thinking that maybe one or both of the variables 'val' &/or 'type' may not be getting cleared before/after each loop.  I know it doesn't seem right, since they are being created within the loop, but I have seen stuff like that happen before.  So maybe try setting initial nullifying values to them just to be sure.

Something like this maybe:

Dim val As Inventor.Parameter = Nothing
Dim type As BOMQuantityTypeEnum = 0

Nullifying an Enum variable can be a bit tricky, because they often can have two types of acceptable values (Integer or Enum variation).  In this case the 'BOMQuantityTypeEnum' only has two possible values/variations, and neither of them have a value of zero (0), so this should work.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

prussellZXB3F
Enthusiast
Enthusiast

Declaring the parameter and expressly setting to nothing fixed it 🙂

 

This somewhat undermines some of what I thought I knew about programming but happy with the fix.

0 Likes