For loop for repeated operation

For loop for repeated operation

ArunS2DHBM
Enthusiast Enthusiast
1,401 Views
8 Replies
Message 1 of 9

For loop for repeated operation

ArunS2DHBM
Enthusiast
Enthusiast

I have an i-logic rule to be executed for 20 different parts.

 

 

Select Case N01_Dia


''N01_Dia=10.3
Case 10.3 
If  N01_Sch = "sch-5" Then
	N01_Thk = 1.24
Else If  N01_Sch = "sch-10" Then
	N01_Thk = 1.24
Else If  N01_Sch = "sch-20" Then
	N01_Thk = 1.24
Else If  N01_Sch = "sch-30" Then
	N01_Thk = 1.24
Else If  N01_Sch = "sch-40" Then
	N01_Thk = 1.73
End If

''N01_Dia=13.7
Case 13.7
If N01_Sch = "sch-5" Then
N01_Thk = 1.65
Else If N01_Sch = "sch-10" Then
N01_Thk = 1.65
Else If N01_Sch = "sch-20" Then
N01_Thk = 1.65
Else If N01_Sch = "sch-30" Then
N01_Thk = 1.65
Else If N01_Sch = "sch-40" Then
N01_Thk = 2.24
End if

End Select

The above same conditions needs to apply for Part name N02, N03, N04... up to N20.
if write individually the rule size will be big,

i will be selecting parameter number of pipe <=20 depending on my requirement, to which the rule should run for that many number of pipe

Please help me with a for-loop condition
0 Likes
1,402 Views
8 Replies
Replies (8)
Message 2 of 9

J.Pelfrene
Enthusiast
Enthusiast

 

Dim sch_list As List(Of String) = New List(Of String)({N01_sch, N02_sch, N03_sch})
Dim thk_list As List(Of Double) = New List(Of Double)({N01_thk, N02_thk, N03_thk})
Dim dia_list As List(Of Double) = New List(Of Double)({N01_dia, N02_dia, N03_dia})

For i As integer = 0 To sch_list.Count
    Select Case dia_list.Item(i)    
    'N01_Dia=10.3
    Case 10.3 
        If  sch_list.Item(i) = "sch-40" Then
            thk_list.Item(i) = 1.73
        Else 
            thk_list.Item(i) = 1.24
        End If

    'N01_Dia=13.7
    Case 13.7 
        If  sch_list.Item(i) = "sch-40" Then
            thk_list.Item(i) = 2.24
        Else 
            thk_list.Item(i) = 1.65
        End If

   End Select
Next

 

 

Something like this could work?
There may be different ways to define and initialize a List, IEnumerable or ObjectCollection. Depends a bit on what kind of objects these are / come from.

0 Likes
Message 3 of 9

ArunS2DHBM
Enthusiast
Enthusiast

Thanks for the reply,

 

I'm getting the below error when I run the code

 

Error in rule: Rule0, in document: Mainassembly_Assembly.iam

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

 

Can you please help me with that, I'm using inventor 2020 version

 

also, I have total of 20 pipes, I don't want to run the rule for all the 20 pipes, I will be having a parameter "Num_of Pipe" based on that number say 5, then the rule should run for the first 5 pipes in the list.

0 Likes
Message 4 of 9

fullevent
Advisor
Advisor

Hallo @ArunS2DHBM,

 

this could do it..

Dim temp As String, temp_sch As String, temp_thk As String, j As String

For i = 1 To 20

	j = Format(i, "00")

	temp = "N" & j & "_Dia"
	temp_sch = "N" & j & "_sch"
	temp_thk = "N" & j & "_thk"

	Select Case temp

		''N01_Dia=10.3
		Case 10.3 
		If  temp_sch = "sch-5" Then
			temp_thk = 1.24
		Else If  temp_sch = "sch-10" Then
			temp_thk = 1.24
		Else If  temp_sch = "sch-20" Then
			temp_thk = 1.24
		Else If  temp_sch = "sch-30" Then
			temp_thk = 1.24
		Else If  temp_sch = "sch-40" Then
			temp_thk = 1.73
		End If

		''N01_Dia=13.7
		 Case 13.7
		 If temp_sch = "sch-5" Then
		 temp_thk = 1.65
		 Else If temp_sch = "sch-10" Then 
		temp_thk = 1.65 
		Else If temp_sch = "sch-20" Then
		temp_thk = 1.65
		 Else If temp_sch = "sch-30" Then
		 temp_thk = 1.65
		 Else If temp_sch = "sch-40" Then
		 temp_thk = 2.24
		End If

	End Select
	
Next


I hope it helps you.
Enjoy

 
Edit: I was to slow ^^


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 5 of 9

ArunS2DHBM
Enthusiast
Enthusiast
j = Format(i, "00")

having issue in this line

Error on Line 5 : Too many arguments to 'Public ReadOnly Default Property Chars(index As Integer) As Char'.

 

0 Likes
Message 6 of 9

fullevent
Advisor
Advisor

I can't understand this error..
I tried now this short iLogic

i = 5
j = Format(i, "00")
MsgBox(j)

..and it works for me..

2022-07-19 10_02_13-Window.png


I'm sorry, but i don't know what could be wrong with that simple line.. 😕

 


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 7 of 9

ArunS2DHBM
Enthusiast
Enthusiast

Hi @fullevent

 

That error is rectified, but the program doesn't take the value to the parameter. i.e my N01_thk is not updating.

 

 

0 Likes
Message 8 of 9

ArunS2DHBM
Enthusiast
Enthusiast

The rule is running, but the value is not updating, I think the reason is  Sch_list.Item(i) takes its value, instead of the parameter name.

 

i.e Sch_list.Item(i) Should be N01_Sch, instead, it takes Sch_list.Item(i) as Sch-5,

 

is any way to update this...

 

Thanks in advance.

0 Likes
Message 9 of 9

fullevent
Advisor
Advisor

Hi @ArunS2DHBM,

 

you mean N01_thk in your code is an user-parameter?
Didn't know that, but then you can do something like this

 

Dim temp As String, temp_sch As String, temp_thk As String, j As String

For i = 1 To 20

	j = Format(i, "00")

	temp = "N" & j & "_Dia"
	temp_sch = "N" & j & "_sch"
	temp_thk = "N" & j & "_thk"

	Select Case temp

		''N01_Dia=10.3
		Case 10.3 
		If  Parameter("temp_sch") = "sch-5" Then
			Parameter("temp_thk") = 1.24
		Else If  Parameter("temp_sch") = "sch-10" Then
			Parameter("temp_thk") = 1.24
		Else If  Parameter("temp_sch") = "sch-20" Then
			Parameter("temp_thk") = 1.24
		Else If  Parameter("temp_sch") = "sch-30" Then
			Parameter("temp_thk") = 1.24
		Else If  Parameter("temp_sch") = "sch-40" Then
			Parameter("temp_thk") = 1.73
		End If

		''N01_Dia=13.7
		 Case 13.7
		If Parameter("temp_sch") = "sch-5" Then
			Parameter("temp_thk") = 1.65
		Else If Parameter("temp_sch") = "sch-10" Then 
			Parameter("temp_thk") = 1.65 
		Else If Parameter("temp_sch") = "sch-20" Then
			Parameter("temp_thk") = 1.65
		Else If Parameter("temp_sch") = "sch-30" Then
			Parameter("temp_thk") = 1.65
		Else If Parameter("temp_sch") = "sch-40" Then
			Parameter("temp_thk") = 2.24
		End If

	End Select
	
Next

 

 

Best regards,


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes