Error 'parameter is incorrect' when replacing a subassembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Community,
I am creating an assembly with a configurable subassembly.
The top-level assembly does not initially contain the subassembly.
After making choices, the user clicks the button on the form to run the rule (place the subassembly).
The initial run successfully places the subassembly.
The second run fails.
The rule looks for the existence of the subassembly. If found, delete from top-level assembly.
If a local file exists, it is deleted too.
During the second run, this error occurs:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Here is the partial code. Error occurs on line 24 in the code below
' Normalized name
sNormalizedName = "Return Rails"
If ComponentExists(ThisApplication.ActiveDocument, sNormalizedName) Then
' Delete component
Components.Delete(sNormalizedName)
End If
''' Return Rails ---------------------------------------------------------------------------
' Component name
sCompName = "\\eng\Inventor_Data\Templates\NMC_ASSEMBLY.iam"
' Delete any local file
If System.IO.Directory.Exists(sWorkspaceTempPath) AndAlso _
System.IO.File.Exists(sWorkspaceTempPath & sNormalizedName & ".iam") Then
System.IO.File.Delete(sWorkspaceTempPath & sNormalizedName & ".iam")
End If
' Create component from template
Dim oReturnRailDoc As AssemblyDocument = ThisApplication.Documents.Add( _
kAssemblyDocumentObject, _
sCompName,
False
)
' Default filename to use when saved
oReturnRailDoc.FullFileName = sWorkspaceTempPath & sNormalizedName & ".iam"
''' E R R O R O C C U R S O N L I N E A B O V E U P O N S E C O N D R U N
' Add the occurrence
Dim oReturnRailOcc As ComponentOccurrence = oAsmCompDef.Occurrences.Add(oReturnRailDoc.FullDocumentName, oMatrix)
' Browser name
oReturnRailOcc.Name = sNormalizedName
' Not grounded
oReturnRailOcc.Grounded = False
' Constraints
Constraints.AddFlush("ReturnRail_YZ-Assy_YZ", "", "YZ Plane", sNormalizedName, "YZ Plane")
Constraints.AddFlush("ReturnRail_XZ-Assy_XZ", "", "XZ Plane", sNormalizedName, "XZ Plane")
Constraints.AddFlush("ReturnRail_XY-Assy_XY", "", "XY Plane", sNormalizedName, "XY Plane")
iProperties.Value(sNormalizedName, "Custom", "SortPriority") = "6"
oReturnRailDoc.Close(True)
oReturnRailDoc.ReleaseReference
Since it works the first time, I know the parameters are valid. After I delete, I suspect the file is lingering in memory, which causes the error on second run.
I welcome any insight and suggestion to correct the issue.
Regards,
Jerry