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: 

Select and delete all iMates

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
JDORFMAn3
961 Views, 10 Replies

Select and delete all iMates

I am placing imates along all work points using ilogic but everytime I update the parameters and the rule auto updates it keeps copying over again all the imates made previously. 

I figured if I could just add in the beginning of the code to delete all imates before regenerating new ones it should be fine. 

Any advice or help?

10 REPLIES 10
Message 2 of 11
FINET_Laurent
in reply to: JDORFMAn3

Hi,

 

I had this issue not so long ago..
My work around was to split the rule in two :

 

One for building the assemby (Adding parts, constraints, etc..). On this rule I turned the autorun off.

One for driving the parameters of each parts. This one has autorun on.

 

It did the trick for me.

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 3 of 11
JDORFMAn3
in reply to: FINET_Laurent

Thanks for your reply but sorry I don't understand how it would help me.
Here's the code
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Define the work point object
Dim oWorkPoint As WorkPoint

'Define the numbers used to create the work point names
Dim i As Integer
Dim Max_Count As Integer
Max_Count = Row_Count * Column_Count

'Set the first value to zero to negate the Origin Point
i = 0

'Define the iMate creation object
Dim oiMate As MateiMateDefinition

'Cycle through each work point in the pattern and rename them
For i = 0 To Max_Count
For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
'Create a new iMate
oiMate = oCompDef.iMateDefinitions.AddMateiMateDefinition(oWorkPoint, 0, , ,"MatePoint")
oWorkPoint.Name = "Work Point" & i
i = i + 1
Next
Next

iLogicVb.UpdateWhenDone = True

Message 4 of 11
FINET_Laurent
in reply to: JDORFMAn3

If you only need to fire the rule once you can simply turn the auto run off.

 

Capture.JPG

 

Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 5 of 11
JDORFMAn3
in reply to: FINET_Laurent

No not what I need.
I need it to update parameters and the maintain iMates always. this is for a custom component that I will need to adjust it a lot.
Message 6 of 11
FINET_Laurent
in reply to: JDORFMAn3

Hi,

 

Checking if the iMate you want to create by it's name  already exist or not whould do the trick?


Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

Message 7 of 11
dutt.thakar
in reply to: JDORFMAn3

@JDORFMAn3 

 

Are you looking for something like this at the beginning of your code? This code will delete all the iMates that are present in the assembly.

 

Dim oDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

Dim oMate As iMateResult

For Each oMate In oDef.iMateResults
	oMate.Delete
Next

 If this is not something you want, please describe exactly what you are trying to achieve? 

 

Hope this will be helpful.

If this answer has solved your problem please ACCEPT SOLUTION and hit like if you found it helpful..!


Regards,
Dutt Thakar
LinkedIn
Message 8 of 11
JDORFMAn3
in reply to: dutt.thakar

Dim oDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition

Dim oMate As iMateResult

For Each oMate In oDef.iMateResults
	oMate.Delete
Next

Should this also work if I am working on part? 

Message 9 of 11
J-Camper
in reply to: JDORFMAn3

I don't do a lot with iMates, so I'm not sure how they react in the assembly when you delete a used iMate and remake it to be named the same.

 

I would just add a check to see if any iMates are already using the workpoint in question.  Then you only make new ones:

 

Sub Main

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Define the work point object
Dim oWorkPoint As WorkPoint

'Define the numbers used to create the work point names
Dim i As Integer
Dim Max_Count As Integer
Max_Count = Row_Count * Column_Count

'Set the first value to zero to negate the Origin Point
i = 0

'Define the iMate creation object
Dim oiMate As MateiMateDefinition

Dim AlliMates As iMateDefinitions = oCompDef.iMateDefinitions

'Cycle through each work point in the pattern and rename them
For i = 0 To Max_Count
	For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
		'Create or update iMate
		If ExistingImate(AlliMates, oWorkPoint) = False
			oiMate = oCompDef.iMateDefinitions.AddMateiMateDefinition(oWorkPoint, 0, , , "MatePoint")
		Else
			'iMate exists, don't remake
		End If
		oWorkPoint.Name = "Work Point" & i
		i = i + 1
	Next
Next

iLogicVb.UpdateWhenDone = True

End Sub

Function ExistingImate(iMates As iMateDefinitions, Source As Object) As Boolean
	Dim Result As Boolean = False
	For Each imd As iMateDefinition In iMates
                'Assumes all iMates are all based on Geometry Which can be named.
		If imd.Entity.Name = Source.Name Then Result = True : Exit For
	Next
	Return Result
End Function

 

If you have iMates built off of objects which don't have a "Name" Property, you might have to adjust the Custom Function, but if not this should work for you

 

Let me know if you have any questions, or if it is not working as intended.

Message 10 of 11
JDORFMAn3
in reply to: J-Camper

it works great just 

'Set the first value to zero to negate the Origin Point
i = 0

this line did not work. it still creates on the origin point 
Message 11 of 11
J-Camper
in reply to: JDORFMAn3

I didn't know that was something you wanted to avoid.  I would set another work point Object to the center point and just add into the For Each Loop to check and avoid Center Point by name:

 

Sub Main

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Define the work point object
Dim oWorkPoint As WorkPoint

'Define the Center point object
Dim oCenterPoint As WorkPoint = oCompDef.WorkPoints.Item(1) : Logger.Trace(oCenterPoint.Name)

'Define the numbers used to create the work point names
Dim i As Integer
Dim Max_Count As Integer
Max_Count = Row_Count * Column_Count

'Define the iMate creation object
Dim oiMate As MateiMateDefinition

Dim AlliMates As iMateDefinitions = oCompDef.iMateDefinitions

'Cycle through each work point in the pattern and rename them
For i = 0 To Max_Count
	For Each oWorkPoint In oCompDef.WorkPoints
		'Avoid CenterPoint
		If oWorkPoint.Name <> oCenterPoint.Name
			'Create or update iMate
			If ExistingImate(AlliMates, oWorkPoint) = False
				oiMate = oCompDef.iMateDefinitions.AddMateiMateDefinition(oWorkPoint, 0, , , "MatePoint")
				oWorkPoint.Name = "Work Point " & i
			Else
				'iMate exists, don't remake
			End If
			i = i + 1
		End If
	Next
Next

iLogicVb.UpdateWhenDone = True

End Sub

Function ExistingImate(iMates As iMateDefinitions, Source As Object) As Boolean
	Dim Result As Boolean = False
	For Each imd As iMateDefinition In iMates
		'Assumes all iMates are all based on Geometry Which can be named.
		If imd.Entity.Name = Source.Name Then Result = True : Exit For
	Next
	Return Result
End Function

 

 

FYI: That line you are referring to gets over written later in the code @ "For i = 0 To Max_Count" Where you are setting i = 0 again.  It might as well not be there.

 

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

Post to forums  

Autodesk Design & Make Report