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?
Solved! Go to Solution.
Solved by J-Camper. Go to Solution.
Solved by J-Camper. Go to Solution.
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"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
If you only need to fire the rule once you can simply turn the auto run off.
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"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"
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.
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?
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.
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.