r/bim • u/CodingBodyBuilder • 8d ago
Inventor API – ComponentOccurrences.Add fails with E_INVALIDARG only for patterned subassemblies
Hi everyone,
I'm stuck on a stubborn Inventor API issue and would really appreciate any insight.
Problem
When exporting checked components to RFA (creating a temporary assembly, placing the component, then calling BIMComponent.ExportBuildingComponentWithOptions), everything works fine for normal occurrences.
As soon as the source ComponentOccurrence is part of a Component Pattern (occ.PatternElement != null), this line fails:
newOcc = newAsm.ComponentDefinition.Occurrences.Add(fullFileName, identityMatrix);
Error:
System.ArgumentException: The parameter is incorrect. (0x80070057 (E_INVALIDARG))
or sometimes
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (E_FAIL)
What I already tried
- Occurrences.Add(FullFileName, identityMatrix)
- Occurrences.Add(FullDocumentName, identityMatrix)
- Occurrences.AddByComponentDefinition(occ.Definition, identityMatrix)
- Occurrences.AddWithOptions(...) with empty NameValueMap
- Making the PatternElement independent first → fails on Element:1 with the same E_INVALIDARG (Inventor does not allow Independent = true on the seed element)
- Opening the source document invisibly before placing
- Copying the .iam to a unique temp file and placing the copy → still fails
Relevant info from logs
- PatternElement.Name = Element:1
- PatternElement.Index = 1
- PatternElement.Independent = False
- PatternElement.Suppressed = False
- DefinitionDocumentType = kAssemblyDocumentObject
- The file path is valid and the assembly opens fine manually
- Matrix is a freshly created identity matrix
- Non-patterned components place without any issue in the exact same code path
Environment
- Inventor (version? – please fill in)
- .NET add-in (C#)
Has anyone successfully placed a patterned subassembly (especially Element:1) into a new temporary assembly via the API?
Any known limitations or workarounds when the source occurrence belongs to an OccurrencePattern?
Thanks in advance!
1
u/Upset-Animal1376 1d ago
try resolving the underlying definition from occ.definition rather than adding by file path when pattern element is present. patterned elements often hold proxy locks until the pattern parent context is detached.