Exception from HRESULT

Exception from HRESULT

farshidDWRFR
Enthusiast Enthusiast
599 Views
11 Replies
Message 1 of 12

Exception from HRESULT

farshidDWRFR
Enthusiast
Enthusiast

Hi all,

 

I get the error message "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))" when running the following iLogic snippet. Can anyone please help me?

 

Dim oAsmDoc As AssemblyDocument = ThisDoc.Document

Dim oAsmCompDef As AssemblyComponentDefinition = Nothing

oAsmCompDef = oAsmDoc.ComponentDefinition

	
Dim oOcc As ComponentOccurrence

    For Each oOcc In oAsmCompDef.Occurrences

    	If oOcc.Visible = False Then
			
						
			oOcc.Definition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
			
			
			
		End If
		
	Next
0 Likes
600 Views
11 Replies
Replies (11)
Message 2 of 12

aelqabbany
Advocate
Advocate

The script ran fine for me. I've made a few changes to make it more robust. If you run into any errors, please upload a screenshot of the details of the error dialog.

 

Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim oAsmCompDef As  AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

For Each oOcc As ComponentOccurrence In oAsmCompDef.Occurrences
	If oOcc.Visible = False Then
		Try
			oOcc.Definition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure
		Catch
			MessageBox.Show("Could not set " & oOcc.Name & " to phantom", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		End Try
	End If
Next
0 Likes
Message 3 of 12

farshidDWRFR
Enthusiast
Enthusiast

Hello and thanks very much for your response.

 

I need the rule to set the suppressed components in an assembly to phantom, so they are not shown in the Bill of Materials with quantity 0. However, the code does not do this but gives an error message saying "Could not set ...to phantom.". I will appreciate it if you can help me fix this.

0 Likes
Message 4 of 12

aelqabbany
Advocate
Advocate

Thank you for clarifying. Give this a shot and let me know if you run into any issues:

 

Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument

Dim oAsmCompDef As  AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

For Each oOcc As ComponentOccurrence In oAsmCompDef.Occurrences
	'Check if Occurrence is suppressed
	If oOcc.Suppressed = True Then
		Try
			'Unsuppress Occurrence
			oOcc.Unsuppress()
			'Set Occurrence BOM structure to Phantom
			oOcc.Definition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
			'Suppress Occurrence without saving
			oOcc.Suppress(True)
		Catch
			MessageBox.Show("Could not set " & oOcc.Name & " to phantom", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
		End Try
	End If
Next
0 Likes
Message 5 of 12

farshidDWRFR
Enthusiast
Enthusiast

Hello again and thanks for your response.

 

The only part of the code that works properly is the message box. It does not perform the main job which is changing the BOM structure to Phantom.

 

Any suggestions?

0 Likes
Message 6 of 12

aelqabbany
Advocate
Advocate
Thank you for the feedback.

The only way I would be able to help you further, is if you were able to upload you working file, or at the very least upload detailed screenshots.
0 Likes
Message 7 of 12

farshidDWRFR
Enthusiast
Enthusiast

Is that fine if I send you a compressed file via a OneDrive link? My assembly folder is as large as 13.4G.

0 Likes
Message 8 of 12

aelqabbany
Advocate
Advocate

Sure. Please send it to me at abdullah[dot]elq[at]gmail[dot]com.

 

Or you can share the link here if you want others with more experience to take a look at it.

0 Likes
Message 9 of 12

WCrihfield
Mentor
Mentor

Hi @farshidDWRFR & @aelqabbany .  Just a couple quick notes...you can just set the BOMStructure of the ComponentOccurrence object directly (ComponentOccurrence .BOMStrucure), instead of trying to set the BOMStructure of the component's definition.  That might help eliminate some complications.  Also, keep in mind that if you are toggling component suppression status, there will need to be either a LevelOfDetailRepresentation (pre 2022) or a ModelState (2022 and later) involved, to record those status changes.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 12

aelqabbany
Advocate
Advocate

Thank you @WCrihfield. Your knowledge is always appreciated.

0 Likes
Message 11 of 12

farshidDWRFR
Enthusiast
Enthusiast

Hi,

 

I just emailed you the download link.

0 Likes
Message 12 of 12

farshidDWRFR
Enthusiast
Enthusiast

Thanks, @WCrihfield for your advice.

0 Likes