"DerivedAssemblyComponents.Add" Fails to Function Reliably
Hello,
As part of my custom add-in, I need to derive an assembly file to the new or existing part. Below is a code I am using simplified to the basics, it appears to work for a lot of people, but in my case it only works with periodic success, meaning that while it sometimes works, it can also result in "Error 0x80004005", or just outright crash Inventor completely. So far the only consistent logic I was able to observe is that "Error 0x80004005" is being thrown every time I try to use the command in Sheet Metal Parts, but only if at least one Sheet Metal Command (Face, Flange, etc.) has been used, if the document is completely empty, the command appears to be working normally, albeit with the risk of Inventor crashing.
Public Sub DeriveAssy() Dim oPartDoc As PartDocument Set oPartDoc = ThisApplication.ActiveDocument Dim oDerAsDef As DerivedAssemblyDefinition Set oDerAsDef = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition("<< Insert Assembly Full Path Here>>") Dim oPartDef As PartComponentDefinition Set oPartDef = oPartDoc.ComponentDefinition Dim oDerivedAssembly As DerivedAssemblyComponent Set oDerivedAssembly = oPartDef.ReferenceComponents.DerivedAssemblyComponents.Add(oDerAsDef) End Sub
I have tried running it on multiple computers, with different files, as well as in multiple versions of Inventor, and the issue is present in every case I tried, which is strange seeing that there is a number of mentions for this command everywhere, even in one of the samples that Autodesk provides, but not a single mention of any issues that I could find.
Right now I am mostly curious to see if anyone else ran into any issues trying to derive an assembly to the part with a VBA code, or if anyone else could try and replicate the issues described.
Any information would be helpful!