Community
HI, I get "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
error when adding the mate constraint in the following.
Please let me know if you see a problem with the code or have a possible solution.
Dim iMates As iMateDefinitionsEnumerator iMates = Comp.iMateDefinitions For Each iMate As iMateDefinition In iMates MsgBox("This is iMate: " & iMate.Name) ' Check if the iMate name matches the desired one If iMate.Name = "MyInsert" Then MsgBox("This is the iMate to use: ") ' Attempt to cast the COM object to an Inventor.Edge Dim circularEdge As Inventor.Edge circularEdge = TryCast(oPick1, Inventor.Edge) ' Check if the casting was successful If circularEdge IsNot Nothing Then MsgBox("EDGE has been created: ") ' The COM object was successfully cast to an Inventor.Edge ' Add a mate constraint between the iMate and the edge Dim constraints As AssemblyConstraints constraints = ThisDoc.Document.ComponentDefinition.Constraints Dim mateConstraint As AssemblyConstraint ' Start a transaction for adding the mate constraint Dim oTrans As Transaction oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Add Mate Constraint") Try ' Add the mate constraint mateConstraint = constraints.AddMateConstraint(iMate, circularEdge, 0) oTrans.End() ' Commit the transaction if successful Catch ex As Exception oTrans.Abort() ' Abort the transaction if there is an error MsgBox("Error adding mate constraint: " & ex.Message) End Try Else MsgBox("There is NO EDGE: ") ' The casting failed ' Handle the failure accordingly End If End If Next
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
Hi @tbrausen
I don't know your exact test case but this is working for an imate on a face and circular edge.
Dim comp As ComponentOccurrence = ThisApplication.CommandManager.Pick _
(SelectionFilterEnum.kAssemblyLeafOccurrenceFilter, "Select an occ")
If comp Is Nothing Then Return
Dim iMates As iMateDefinitionsEnumerator = comp.iMateDefinitions
For Each iMate As iMateDefinition In iMates
MsgBox("This is iMate: " & iMate.Name)
' Check if the iMate name matches the desired one
If iMate.Name = "MyInsert" Then
MsgBox("This is the iMate to use: ")
Dim edProxy As EdgeProxy = ThisApplication.CommandManager.Pick _
(SelectionFilterEnum.kPartEdgeFilter, "Select an occ")
'Check if the casting was successful
If edProxy IsNot Nothing Then
MsgBox("EDGE has been created: ")
'Add a mate constraint between the iMate and the edge
Dim oAssyDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim constrs As AssemblyConstraints = oAssyDef.Constraints
'Start a Transaction For adding the mate Constraint
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisDoc.Document, "Add Mate Constraint")
Try
'Add the mate constraint
Dim mateConstr As MateConstraint = constrs.AddMateConstraint(iMate, edProxy, 0,InferredTypeEnum.kInferredPoint,InferredTypeEnum.kInferredPoint)'circularEdge
oTrans.End() ' Commit the transaction if successful
Catch ex As Exception
oTrans.Abort() ' Abort the transaction if there is an error
MsgBox("Error adding mate constraint: " & ex.Message)
End Try
Else
MsgBox("There is NO EDGE: ") ' The casting failed
'Handle the failure accordingly
End If
End If
Next
Can't find what you're looking for? Ask the community or share your knowledge.