iLogic for controlling number of occurences

iLogic for controlling number of occurences

fridtjofZM5ME
Collaborator Collaborator
566 Views
2 Replies
Message 1 of 3

iLogic for controlling number of occurences

fridtjofZM5ME
Collaborator
Collaborator

There are KH_nAIV number of holes equally spaced along the length L, thus the distance KH_spIV between the holes is given by KH_spIV = L/(KH_nAIV-1).

 

The condition KH_spIV ≤ 530 is given

the number KH_nAIV is to be as low as possible while still meeting the prior condition.

 

My code is as follows and it doesen't work:

 

Parameter("LMV - SK5-KH:1", "KH_TAI") = 268

If TerskelType = "Kvilldalterskel" Then
		Parameter("LMV - SK5-KH:1", "KH_BAI") = 250
	Else If TerskelType = "014-terskel" Then
		Parameter("LMV - SK5-KH:1", "KH_BAI") = TerskHøyde + 235
End If 

SharedVariable("KH_BAI") = Parameter("LMV - SK5-KH:1", "KH_BAI")
SharedVariable("KH_TAI") = Parameter("LMV - SK5-KH:1", "KH_TAI")
SharedVariable("KH_spIV") = Parameter("LMV - SK5-KH:1", "KH_spIV")
SharedVariable("KH_nAIV") = Parameter("LMV - SK5-KH:1", "KH_nAIV")

Dim KH_BAI As Double = SharedVariable("KH_BAI")
Dim KH_TAI As Double = SharedVariable("KH_TAI")
Dim KH_spIV As Double = SharedVariable("KH_spIV")
Dim KH_nAIV As Integer = SharedVariable("KH_nAIV")


If KH_spIV < 530 and KH_nAIV >= 3 Then
	While KH_spIV < 530
		KH_nAIV = KH_nAIV - 1
	End While
Else If	KH_spIV > 530
	While KH_spIV > 530
		KH_nAIV = KH_nAIV + 1
	End While
End If

InventorVb.DocumentUpdate()

iLogicVb.UpdateWhenDone = True

 

The goal is to have the rule adjust KH_nAIV to meet the condition for KH_spIV in the case of both increasing and decreasing the length L regardless of the initial value of KH_nAIV.

 

Is the an "as little as possible" operator I don't know about I can use to set a condition for KH_nAIV?

0 Likes
Accepted solutions (1)
567 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

im not so sure your formula for calculating KH_spIV is correct. i expectit has to be KH_spIV = L/(KH_nAIV+1)

 

anyway try this:

' KH_spIV ≤ 530
' KH_nAIV is to be as low as possible
Dim KH_spIV As Double 'distance between the holes (pitch)
Dim KH_nAIV As Integer ' number of holes
Dim L As Double = 1000 ' length

' Math.Ceiling function rounds up to the nearest integer
KH_nAIV = Math.Ceiling(L / 530) 
' remove the +1 if you want the holes to be on the length distance
KH_spIV = L/(KH_nAIV + 1) 

Dim msg As String = String.Format("L={0}, KH_nAIV={1}, KH_spIV={2}",
	L,KH_nAIV,KH_spIV)
msgbox(msg)

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

fridtjofZM5ME
Collaborator
Collaborator

Thanks, the method works mathematically and renders the desired result in the model, but for some reason my typecasting doesen't seem to work. It seems I need to use the parameters in the subassembly component the rule applies to directly for anything to work, so

parameter("subassembly component", "number_of_holes") = Math.Ceiling(parameter("subassembly component", "Length") /530)

works like expected, but

dim number_of_holes as integer = parameter("subassembly component", "number_of_holes")
dim Length as double = parameter("subassembly component", "Length")

number_of_holes = Length/530

does absolutely nothing.

 

Is there a part of the concept typecasting somewhere that I've missed...?

0 Likes