Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic fails to attach iMate

1 REPLY 1
SOLVED
Reply
Message 1 of 2
tbrausen
115 Views, 1 Reply

iLogic fails to attach iMate

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

 

1 REPLY 1
Message 2 of 2
A.Acheson
in reply to: tbrausen

Hi @tbrausen 

I don't know your exact test case but this is working for an imate on a face and circular edge. 

AAcheson_0-1715307892875.png

	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

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report