Another case of 80004005 Exception that i don't know how to debug

Another case of 80004005 Exception that i don't know how to debug

Maxim-CADman77
Advisor Advisor
210 Views
4 Replies
Message 1 of 5

Another case of 80004005 Exception that i don't know how to debug

Maxim-CADman77
Advisor
Advisor

Dear @MjDeck 
Could you, please, help to debug another case of 80004005 Exception

 

Dim invApp As Inventor.Application = ThisApplication

Logger.Info("invApp.Documents.Count-1: " & invApp.Documents.Count)
Dim aDoc As AssemblyDocument = ThisDoc.Document
Dim aDef As AssemblyComponentDefinition = aDoc.ComponentDefinition
Logger.Info("aDoc.ReferencedDocuments.Count: " & aDoc.ReferencedDocuments.Count)

For Each refDoc As Document In aDoc.ReferencedDocuments
	Logger.Info(vbTab & System.IO.Path.GetFilename(refDoc.FullFilename) & " -- IsiPartMember: " & If(refDoc.ComponentDefinition.IsiPartMember = True, "+", "-"))

	If TypeOf refDoc Is PartDocument And refDoc.ComponentDefinition.IsiPartMember = False Then

        Dim refDocOccs As ComponentOccurrencesEnumerator = aDef.Occurrences.AllReferencedOccurrences(refDoc)

		If refDocOccs.Count = 0 Then Continue For ' not a direct component (Factory etc)

		' For Each rdo As ComponentOccurrence In refDocOccs
		For i = 1 To refDocOccs.Count
			Dim rdo As ComponentOccurrence = refDocOccs.Item(i)
			Logger.Info("rdo: " & If(rdo Is Nothing, "-", "+"))

			' Try
				rdo.Excluded = True ' Unspecified error (0x80004005 (E_FAIL))
			' Catch ex As Exception : Logger.Warn(ex.Message) : End Try
		Next

		RefDoc.Close(True) ' "Public member 'Close' on type 'PartDocument' not found." if RefDoc.Close(SkipSave := True)
		RefDoc.ReleaseReference
	End If
Next
Logger.Info("invApp.Documents.Count-2: " & invApp.Documents.Count)

 

This works OK for some IAMs but not for attached.

What I'm missing?

Please vote for Inventor-Idea Text Search within Option Names

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

jwingateRJECD
Enthusiast
Enthusiast
Accepted solution

It's possible it didn't translate when you exported the files that you shared in the ZIP folder, but it looks like this assembly isn't an iAssembly. when you start to type rdo.Excluded the intellisense pops up with a description that states if the assembly is not an iAssembly that this command will not work. Can you verify this on your end?

 

 

 

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

Hi @Maxim-CADman77.  I am not allowed to download or open ZIP files from forums on my work PC, due to corporate security policies, but I might still be able to point out a couple little details that may potentially cause a problem.

  • No document type check is being used (at beginning of rule), but if a different type of document was encountered, it would be a different type of error.
  • Just inside the main 'loop' of referenced documents, you are using a 'Logger' line of code, in which you are accessing the 'IsiPartMember' property.  If the referenced document was not a regular part, or sheet metal part, such as if it were a sub assembly, then that property would not be available, so it would throw an error at that point.
  • Inside the loop, in your line of code which is checking document type, and checking if it is an iPartMember, you should replace the 'And' keyword with 'AndAlso'.
    • When using 'And', the expression on both sides of its will 'always' be checked, and since that is the case, if it was not a part (such as a sub assembly), then once again, that 'IsiPartMember' property would not be available, so it would throw an error.
    • If you were using 'AndAlso' there, then the second expression would only get checked if the first expression evaluated to True.  Since that is the case, it would already be established that it is a part, and it would always have that Property available, which would avoid that potential error.
  • When getting 'AllReferencedOccurrences', some of those referenced occurrences may be down within lower level sub assemblies.  And if that lower level sub assembly was 'ReadOnly' for some reason, or maybe a 'ModelState member', which is often treated as ReadOnly, then when you try to modify the 'Excluded' property of that component that is in the context of that lower level assembly, it may not be allowed.  Maybe not the only possible reason why accessing or setting the value of that property may throw an error, but likely one of the possibilities.
  • Near the end of the loop of referenced documents, you are attempting to close each one, then release the reference to each one.  That will not work.  All of those documents are being actively referenced by the active assembly, so they have all been loaded into Inventor's session memory automatically when you opened that assembly.  In this situation, the Close method would only 'visibly' close the document, if it was 'visibly' opened, but otherwise it would remain 'open' in the background (so invisibly open).  And we can not use the 'ReleaseReference' method on documents that are actively being referenced by another document that we have open, because we would need to purge the assembly of all components and related references to that document first.  Because of this, it is likely throwing an error...if it reaches that point.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5

Maxim-CADman77
Advisor
Advisor

Yes, I confused Excluded with Suppress. I missed that this only applies to iAssemblies.

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 5

Maxim-CADman77
Advisor
Advisor

Thank you. Most notes are definitely valuable (And instead of AndAlso in the context is just childish error).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes