iLogic to change iParts help needed

iLogic to change iParts help needed

Thomas_Savage
Advisor Advisor
584 Views
8 Replies
Message 1 of 9

iLogic to change iParts help needed

Thomas_Savage
Advisor
Advisor

Hello,

 

Looking for some help, possibly an easy solution, just can't figure it out.

 

I have a multi value list of: 1000,1500,2000

 

When i select one of these from my form i want iLogic to change the iPart to the correct size.

 

I can do this with 1000 and 1500. Because i have the names to change the iPart. But when i add 2000 then i don't have the correct part name to change them back. If this makes sense?

 

I have attached my code, if anyone could help me with my code to add 2000, so can select 1000, 1500, 2000 and will always change that would be much appreciated.

 

Thomas.

 

If iPart_Size_Change = 1500 Then
	
iPart.ChangeRow("UNLP-5132-17:6", "UNLP-5131-17")

End If


If iPart_Size_Change = 1000 Then
	
iPart.ChangeRow("UNLP-5131-17:6", "UNLP-5132-17")

End If



If iPart_Size_Change = 1500 Then
	
iPart.ChangeRow("UNLP-5132-17:5", "UNLP-5131-17")

End If

If iPart_Size_Change = 1000 Then
	
iPart.ChangeRow("UNLP-5131-17:5", "UNLP-5132-17")

End If


Thomas Savage

Design Engineer


0 Likes
Accepted solutions (2)
585 Views
8 Replies
Replies (8)
Message 2 of 9

AlexFielder
Advisor
Advisor

I assume that each of the values you want corresponds with one of 1000, 1500, 2000? - in your code you have 1000 & 1500 paired to one iPart row, but then you change what they're paired with.

 

1000 = iPart.ChangeRow("UNLP-5131-17:6", "UNLP-5132-17")

1500 = iPart.ChangeRow("UNLP-5132-17:5", "UNLP-5131-17")

2000 = ??

 

If you can supply whichever iPart row you want 2000 to refer to then we can probably arrive at a solution.

0 Likes
Message 3 of 9

Thomas_Savage
Advisor
Advisor

Thank you for the reply.

 

This is what happens. If i make 1500 part change 2000 part if works ok. But this is where i get the problem. Because then i can't change the 2000 back to 1000 or 1500. Becasue it can't find the ipart. My code below. 

 

'Change iPart

If iPart_Size_Change = 1500 Then
	
iPart.ChangeRow("UNLP-5132-17:6", "UNLP-5131-17")

End If


If iPart_Size_Change = 1000 Then
	
iPart.ChangeRow("UNLP-5131-17:6", "UNLP-5132-17")

End If



If iPart_Size_Change = 2000 Then
	
iPart.ChangeRow("UNLP-5131-17:6", "UNLP-5130-17")

End If

  



Thomas Savage

Design Engineer


0 Likes
Message 4 of 9

Thomas_Savage
Advisor
Advisor

Some more details which could help.

 

I have a pattern, i am trying to change the iPart i have patterned. But come up the error because it can't find the part to change.

 

Is they a easier way to change iParts than this??

 

I want to change it 3 times.

 

Any help much appreciated,

 

Thomas.



Thomas Savage

Design Engineer


0 Likes
Message 5 of 9

AlexFielder
Advisor
Advisor

can you share the offending part file? (or a similar example if you have IP concerns)

0 Likes
Message 6 of 9

Thomas_Savage
Advisor
Advisor

Hello,

 

I have made some parts and attached them.

 

I want to be able to change all these iParts to the different sizes without an error coming up.

 

How can i do this?

 

I know i need to apply a codes o the pattern moves with it. I have done this on my model, just stuck on this.

 

thank you for your help.

 

Thomas



Thomas Savage

Design Engineer


0 Likes
Message 7 of 9

Thomas_Savage
Advisor
Advisor
Accepted solution

I have Solved this problem.

 

Code Attached.

 

Thank you for replying to me post.

 

Thomas

'Change iPart

If iPart_Size_Change = 1000 Then
	iPart.ChangeRow("UNLP-5132-17 (iLogic)", "UNLP-5132-17")
	ElseIf iPart_Size_Change = 1500
	iPart.ChangeRow("UNLP-5132-17 (iLogic)", "UNLP-5131-17")	
	ElseIf iPart_Size_Change = 2000
	iPart.ChangeRow("UNLP-5132-17 (iLogic)", "UNLP-5130-17")
End If


If iPart_Size_Change = 1000 Then
	iPart.ChangeRow("UNLP-5132-17 (iLogic 2)", "UNLP-5132-17")
	ElseIf iPart_Size_Change = 1500
	iPart.ChangeRow("UNLP-5132-17 (iLogic 2)", "UNLP-5131-17")	
	ElseIf iPart_Size_Change = 2000
	iPart.ChangeRow("UNLP-5132-17 (iLogic 2)", "UNLP-5130-17")
End If 

 

 

 



Thomas Savage

Design Engineer


Message 8 of 9

AlexFielder
Advisor
Advisor
Accepted solution

It seems like you've solved this, but attached is an assembly I put together that might be useful to you (and others)

It has two rules:

"replace iParts"

Sub main()
	Component.Replace(Parameter("CurrentRelevantOccurrences"), ReplacingComponent(iPartToReplace & ".ipt"), False)
	iLogicVb.RunRule("get current relevant iParts")

End Sub

Function ReplacingComponent(ReplacementComp As String) As String
	Logger.Debug("replacing: " & Parameter("CurrentRelevantOccurrences") & " With: " & Parameter("iPartToReplace") & ".ipt")
	Return iPartToReplace & ".ipt"
End Function

And a second more complex rule that gets the relevant occurrences currently in the assembly:

"get current relevant iParts"

Sub main()
	GetCurrentRelevantOccurences()
End Sub

Sub GetCurrentRelevantOccurences()
	If TypeOf ThisApplication.ActiveDocument Is AssemblyDocument Then
		Dim AssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
		Dim assyDef As AssemblyComponentDefinition = AssyDoc.ComponentDefinition
		
		Dim occurrenceList As List(Of String) = New List(Of String)
		Dim allowedList As List(Of String) = ListOfAllowedOccurrences
		For Each allowedOcc As String In allowedList
			Dim DocTocheck As Document = ThisApplication.Documents.ItemByName(IO.Path.GetDirectoryName(AssyDoc.FullDocumentName) & "\" & allowedOcc)
			If Not DocTocheck Is Nothing Then
				For Each compOcc As ComponentOccurrence In assyDef.Occurrences.AllReferencedOccurrences(DocTocheck)
					Dim tmpDoc As PartDocument = compOcc.Definition.Document
					If Not tmpDoc Is Nothing Then
						occurrenceList.Add(compOcc.Name)
					End If
				Next
			End If
		Next
		occurrenceList.Sort()
		MultiValue.List("CurrentRelevantOccurrences").Clear
		MultiValue.List("CurrentRelevantOccurrences") = occurrenceList
	End If
End Sub

Function ListOfAllowedOccurrences() As List(Of String)
	Dim tmpList As List(Of String) = New List(Of String)
	tmpList.Add("1000.ipt")
	tmpList.Add("1500.ipt")
	tmpList.Add("2000.ipt")
	Return tmpList
End Function

You can edit the "ListOfAllowedOccurrences" function to affect what items appear when you run the "Click Me!" form within the assembly file.

 

🙂

0 Likes
Message 9 of 9

Thomas_Savage
Advisor
Advisor

Hello @AlexFielder 

 

thank you for those codes, and taking the time to help me.

 

Thomas.



Thomas Savage

Design Engineer