- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi folks,
I have some code with an array whose values changes with the movement of a plane.
SyntaxEditor Code Snippet
If Start= True Then InventorVb.DocumentUpdate(True) While Afstand_tot_center_Ruit <5 Dim MyArrayList(3) As Double 'Hier maak je een lijstje aan met de waarden van je parameter. MyArrayList(0) = X_Afstand_1_Ruit MyArrayList(1) = X_Afstand_2_Ruit MyArrayList(2) = X_Afstand_3_Ruit MyArrayList(3) = X_Afstand_4_Ruit Array.Sort(MyArrayList) 'Hier sorteer je het lijstje dat je hebt aangemaakt van klein naar groot. For Each Str As Double In MyArrayList Next MessageBox.Show(MyArrayList(1), "Co�rdinaat links") 'Hier wordt het linker X-co�rdinaat getoont in een venstertje. MessageBox.Show(MyArrayList(2), "Co�rdinaat rechts") 'Hier wordt het rechter X-co�rdinaat getoont in een venstertje. If MyArrayList(1)<0 Then 'Hier zorg je ervoor dat wanneer de waard op plaats MyArrayList(1) negatief is dus kleiner dan 0, hij positief wordt door te vermenigvuldigen met -1. B1=MyArrayList(1) *-1 Else If MyArrayList(1) >=0 Then B1=MyArrayList(1)*1 End If If MyArrayList(2)<0 Then 'Hier zorg je ervoor dat wanneer de waard op plaats MyArrayList(2) negatief is dus kleiner dan 0, hij positief wordt door te vermenigvuldigen met -1. H1=MyArrayList(2) *-1 Else If MyArrayList(2) >= 0 Then H1=MyArrayList(2)*1 End If 'Bereken van de hoek " formule Sin(alpha)= X/(straal+laagdikte). A1=((Binnen_diameter_Ruit/2)+Laagdikte_Ruit) I1=B1/A1 'Hier deel je de X-waarde door de de straal + laagdikte. J1=Asin(I1) 'Hier neem je de Boogsinus van de X-waarde gedeeld door de straal + laagdikte. K1=J1*180 L1=K1/3.1415 'De uitkomst wordt maal 180 en gedeeld door Pi om van radialen naar graden te gaan. M1=H1/A1 N1=Asin(M1) O1=N1*180 P1=O1/3.1415 Q1=P1+L1 MessageBox.Show(Q1, "hoek") 'De hoeken van de 2 X-waardes wordt samengeteld Afstand_tot_center_Ruit= Afstand_tot_center_Ruit+0.5 End While End If
Afstand_tot_center_Ruit is the parameter of the plane that moves.
now when it moves 1mm the values in my array have to change with the movement of the plane but i can't get it work.
I tried a while loop so when the Afstand_tot_center_Ruit is smaller then 5mm it would run the code and each time it has looped trought it. It would add 0.5 mm to the Afstand_tot_center_Ruit and then run the code again. But my problem here is that the values of my array do'nt change they stay the same until Afstand_tot_center_Ruit is equal to 5mm.
Can someone help me ?
thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey. This whole idea stinks to me, so I'd like to dig into it a bit, if you don't mind:
1) What are you trying to calculate?
2) What for?
3) How are the points attached to the plane (or whatever the gray object is, sheet metal maybe?)?
4) "X_Afstand_1_Ruit"... are the parameters the values come from, right?
5) How are you triggering / running this rule?
This (*1*):
If MyArrayList(1)<0 Then B1=MyArrayList(1) *-1 Else If MyArrayList(1) >=0 Then B1=MyArrayList(1)*1 End If
Is the same as this (*2*):
B1 = Abs(MyArrayList(1))
Shorten your code wherever you can, for the sake of readability.
Read the last line of my signature. You're from Ieper, Belgium, right?
Few tips:
A) If you want to write some comments in the code, write them like this below. The text should fit in your screen without the need to scroll to the side.
'Some very long comment which really can't fit to one row, 'so we have to split it to two Dim A As Integer = 1 'This is the place for short notes
B) Use declarations, so you can see right away what object type you're working with.
You can also use the first letter of the type as a prefix for the variable ("i" for Integer, "d" for Double, ...)
Dim iNumber As Integer = -1 'Accepts whole numbers only Dim dNumber As Double = 0.5 'Accepts decimals Dim sText As String = "some text" 'Accepts text (and numbers) Dim oDoc As Document
C) Don't use any special symbols in code and make the names of your variables (and parameters) as short as possible.
It also wouldn't hurt to use English names (specially when you're posting the code on international forum and asking for help).
'Wrong:
Afstand_tot_center_Ruit = 0.5
'Right
Dim dToCenter As Double = 0.5
Here's the picture you've posted in your last post, so others can relate:
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
first of all thanks for you're repsonse.
1) What are you trying to calculate?
I try to calculate the angle between 2 points that intersect with an edge and a plane ( that moves back and forward)
2) What for?
For my thesis i have to make a postprocessor for a lasercladder and they want to be able to laserclad figures like a square on a round object but such a postprocessor costs a lot of money thus they want me to try and make one.
3) How are the points attached to the plane (or whatever the gray object is, sheet metal maybe?)?
the points are actually made by an intersection of that plane and i measure the distance of that point to the origin and thats my x-coordinate.
4) "X_Afstand_1_Ruit"... are the parameters the values come from, right?
Yes the values come from the paramter X_afstand_1_Ruit...
5) How are you triggering / running this rule?
i should be triggerd by a true or false paramete lik start = true and then the code runs. Thats my idea.
I made some changes do the code would read easier and is smaller like u said.
Wrote also my comments in english and changed some parameter names to englisch.
But i didn't understand what you ment whit:
'Wrong:
Afstand_tot_center_Ruit = 0.5
'Right
Dim dToCenter As Double = 0.5
SyntaxEditor Code Snippet
SyntaxEditor Code Snippet
If Start= True Then While Distance_to_center <5 'This is the distance that the plane can travel to so max 5mm 'So when ever this value changes the values in MyArrayList should change with it. 'To the values that belong to then new values of the new intersection Dim MyArrayList(3) As Double 'Here i define my values as double it accepts decimals. MyArrayList(0) = X_Afstand_1_Ruit MyArrayList(1) = X_Afstand_2_Ruit MyArrayList(2) = X_Afstand_3_Ruit MyArrayList(3) = X_Afstand_4_Ruit Array.Sort(MyArrayList) For Each Str As Double In MyArrayList Next MessageBox.Show(MyArrayList(1), "Co�rdinate left") MessageBox.Show(MyArrayList(2), "Co�rdinate right") B1 = Abs(MyArrayList(1)) 'X-Coordinate left side H1 = Abs(MyArrayList(2)) 'X-Coordinate right side 'I want to calculate the angle between MyArrayList(1)and MyArrayList(2) and i do that with triangulation.'Formula Sin(alpha)=MyArrayList(1)/((Diameter/2)+Layerthicknes) A1=((Diameter/2)+Layerthicknes) I1=B1/A1 J1=Asin(I1) K1=J1*180 L1=K1/3.1415 M1=H1/A1 N1=Asin(M1) O1=N1*180 P1=O1/3.1415 Q1=P1+L1 MessageBox.Show(Q1, "angle") Distance_to_center = Distance_to_center+0.5 'This should add 0.5mm to the planes distance.'My idea is when it adds 0.5mm to Distance_to_center the code would run again but with the new values of the new intersection'it made End While End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
By the code below I wanted to show you an example of bad and good variables' names:
'Wrong:
Afstand_tot_center_Ruit = 0.5
'Right
Dim dToCenter As Double = 0.5
If you calculate the angle every time the parameter "Distance_to_center" changes, you'll better to so by triggering the rule by the parameter change.
Put this line at the start of your rule and every time this parameter changes, this rule will trigger.
s = Distance_to_center
Now if you want to run the rule only if the "Distance_to_center" is less than 5 you can do it like this:
s = Distance_to_center Dim dCenter As Double = Distance_to_center If dCenter > 5 Then Exit Sub 'If the value is greater then 5, quit
Now if you want to trigger the rule again, all you need to do is change the the "Distance_to_center" parameter.
BUT, the change have to be the last line of the code.
Here's an example of mid-code self triggering:
(1) - this is the instance of the rule, aka the order in which it did run
Rule (1) starts
Rule (1) changes the parameter "Distance_to_center"
Rule (2) starts
Rule (2) finishes (if it doesn't trigger the rule again)
Rule (1) finishes
It works the same as calling any sub-functions, so keep that ALWAYS in mind.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
**** my spelling... Besides others:
@Owner2229 wrote:
If you want to calculate the angle every time the parameter "Distance_to_center" changes, you'll better do so by triggering the rule by the parameter change.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Would you perhaps know what this ERROR means ? ERROR: MyArrayList is not declared. The item may not be available due to the related security.
My code:
SyntaxEditor Code Snippet
If Start= True Then Dim MyArrayList(3) As Double MyArrayList(0) = X_Afstand_1_Ruit MyArrayList(1) = X_Afstand_2_Ruit MyArrayList(2) = X_Afstand_3_Ruit MyArrayList(3) = X_Afstand_4_Ruit Array.Sort(MyArrayList) For Each Str As Double In MyArrayList Next MessageBox.Show(MyArrayList(1), "Co�rdinate left") MessageBox.Show(MyArrayList(2), "Co�rdinate right") I1=Abs(MyArrayList(1))/((Binnen_diameter_Ruit/2)+Laagdikte_Ruit) J1=(Asin(I1)*180)/3.1415 M1=Abs(MyArrayList(2))/((Binnen_diameter_Ruit/2)+Laagdikte_Ruit) N1=(Asin(M1)*180)/3.1415 If MyArrayList(2)<0 And MyArrayList(1)< 0 Then Q1=J1-N1 Else If MyArrayList(2)>0 And MyArrayList(1)> 0 Then Q1=N1-J1 Else If MyArrayList(2) <0 And MyArrayList(1)>0 Then Q1=J1+N1 End If MessageBox.Show(Q1, "angle")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What's the "If Start..." still doing there?
Trigger it with the "Distance_To_Center" parameter change.
s = Distance_To_Center Dim MyList(3) As Double MyList(0) = X_Afstand_1_Ruit MyList(1) = X_Afstand_2_Ruit MyList(2) = X_Afstand_3_Ruit MyList(3) = X_Afstand_4_Ruit Array.Sort(MyList) MessageBox.Show(MyList(1), "Co�rdinate left") MessageBox.Show(MyList(2), "Co�rdinate right")
'Don't repeat calculations, pre-calculate them
Dim G As Double = (Binnen_diameter_Ruit / 2) + Laagdikte_Ruit Dim I As Double = Abs(MyList(1)) / G Dim J As Double = (Asin(I) * 180) / PI Dim M As Double = Abs(MyList(2)) / G Dim N As Double = (Asin(M) * 180) / PI
'The mess that used to be here was your (current) problem
'Formate your formulas to be HUMAN readable
'In formulas: shorter =/= better
Dim Q As Double = Nothing If (MyList(2) < 0) And (MyList(1) < 0) Then
Q = J - N
ElseIf (MyList(2) > 0) And (MyList(1) > 0) Then
Q = N - J ElseIf (MyList(2) < 0) And (MyList(1) > 0) Then
Q = J + N End If MessageBox.Show(Q, "angle")
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
could you help me with that automation of the code in don't realy know how to tell the code to run when the distance_to_center parameter changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I already did (in the last code).
This line does it:
s = Distance_To_Center
Just create a new rule:
s = Distance_To_Center
MsgBox("It works, the new value is: " & distance_to_center)
And now change the value of the parameter (in model or in parameters).
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
and how can i tell in the code when it reached Max distance it stops the code ? so S= Distance_to_center automates it but i would like to have it stop at a certain value like Max_Distance_to_center.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Quite easily, actually:
s = Distance_To_Center
If distance_to_center >= 5 Then Exit Sub
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods