reset 'invisible' parameters

reset 'invisible' parameters

GeertvanderHeide
Advocate Advocate
519 Views
6 Replies
Message 1 of 7

reset 'invisible' parameters

GeertvanderHeide
Advocate
Advocate

for a piece of code i have a pick function that keeps running with a while true command. 

found this solution here :https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/to-select-multiple-items-from-a-drop...

 

only thing is, when i have 2 of these functions running after each other it seems te second while loop doesn't run.

 

my question: what parameter  is checked in the 'while true' statement? 

how is it possible i can change this parameter with the esc key? does this parameter stays false during the rest of the code?

 

ik know there is a similar way of notation with an 'if Boolean then' statement, but then i know what parameter to change.

 

kind regards

geert

 

0 Likes
Accepted solutions (1)
520 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @GeertvanderHeide.  I'm not sure I understand your question, but it sounds to me like you do not understand the condition of the loop for escaping the loop.  The example you pointed out is not a good example, because it does not really provide a way to escape the loop other than using the 'Exit While' phrase once you have not selected something.  In the 'While True' opening phrase, you can replace the word 'True' with an actual conditional statement that you want to be tested before each loop.  If the condition does not pass the test, it will not loop again, and will continue with whatever code may be after the loop.  Below is a good link about some of the most popular ways to form loops using vb.net coding (which is what iLogic uses).  On that web page you will find links to more information about each of those looping techniques.  Some of them, such as the While...End While & Do...Loop, let you put the conditional test either at the start or end of the loop, whichever works best for your situation.

Loop Structures (Visual Basic) 

VB.Net - Loops 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

GeertvanderHeide
Advocate
Advocate

so the code i have is to hide bodies inside an assembly.

here you are still able to click a body unless Esc is pressed. 

but there is no way to tell what parameter i change when pressing Esc. 

AppActivate(ThisApplication.Caption)
Dim odoc As PartDocument = ThisDoc.Document
Dim Pcomp As PartComponentDefinition = odoc.ComponentDefinition

While True

Dim oBody As SurfaceBody = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Select Body, Esc to continue")
If oBody Is Nothing Then Exit Sub
	
	obody.Visible = False
	
End While

 main problem is that i have two seperate rules with a function like this in the beginning.

both rules are run after each other bij a 3rd rule. 

Somehow when i click Esc to exit the first rule, than it seems like it also skips over the second rule. 

i tried putting a sleep in rule nr3 but this doesnt seem to fix it. 

 

so it does work but i don't know how. 

If i can reset a temp parameter between rule 1 and 2 i can make sure that it doesn't skip over the second rule.

 

kind regards.

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

OK. In this example, the only thing that happens/changes when you press the escape key is that it sets the oBody variable's Value to 'Nothing', instead of a SurfaceBody object.  Then your next line of code after the Pick function, is checking to see if the oBody variable 'Is Nothing', which will be True if you have pressed the escape key.  Because the oBody variable is being created within that loop, it will only have a value if it has been assigned a value by the Pick function.  If it has not been assigned a value, due to you not picking something, then it 'Is Nothing', so then it obeys the 'Exit Sub' code, which will exit the Sub routine.  If you have not included Sub Main or End Sub within your rule, those are implied for you in the background, so Exit Sub is essentially exiting the whole rule, just like if you had used 'Return' instead of 'Exit Sub'.  If you have more code that needs to run after that loop, then you need to replace "Exit Sub" with something like "Exit While".  Calling 'Exit While' will cause it to exit that loop, and move on to whatever other code may be beyond that loop.

 

PS.  Also, even though I hinted at this in post, I just wanted to reiterate that if you are declaring the variable within the loop, that variable will not be recognized outside of that loop.  If you want to use that variable, and any value assigned to it outside of that loop, you will need to declare that variable before the loop, then just set its value within the loop.  But keep in mind that if you use the loop more than once, it other times it will just be replacing the variable's value, not adding multiple values to it.  If you want to select multiple SurfaceBodies, you will need to create something like an ObjectCollection, or New List(Of SurfaceBody), or something similar before the loop, then add each selection to that collection object within the loop, so that the collection will retain its values after the loop has exited.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

GeertvanderHeide
Advocate
Advocate

oke so i did some testing and changed it a bit

will give a short example:

Dim oBool as Boolean = true

while oBool
dim oBody as SurfaceBody = pickcommand(bladibla)

if oBody is nothing then
oBool = false
Exit While
end if

'do stuff with oBody'

end while

 

but this does not seem to fix my problem. 

contents of my third rule:

ilogicvb.runrule("rule1")
ilogicvb.runrule("rule2")

when rule 1 and 2 consist of the same kind of function it skips the second rule. 

in this case i also tried to change the name of 'oBool' and 'oBody'  so there should be no parameter be floating somewhere in some temp memory or something like that. 

i also tried running the 2 pieces of code in one rule, still skips the second part.

even tried putting in:

ThisApplication.CommandManager.StopActiveCommand
thisapplication.CommandManager.ClearPrivateEvents

this also doesn't seem to do anything. 

 

if there might be a solution to this i would love to know it.

 

kind regards,

 

geert

 

0 Likes
Message 6 of 7

GeertvanderHeide
Advocate
Advocate

so i finnaly found the solution! 

somehow the selection remenbered that the surfacebody in the second rule was also nothing after the selection in the first rule was canceled. 

to reset the selection/ body is nothing statement in the second rule i just defined the body in the second rule

Dim odoc As PartDocument = ThisDoc.Document
Dim Pcomp As PartComponentDefinition = odoc.ComponentDefinition
Dim oCel As SurfaceBody = Pcomp.SurfaceBodies.Item(1)

oCel = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "select cel, Esc to exit")

 

now the default doesnt see that oCel is empty and it initalizes the pick command.

0 Likes
Message 7 of 7

GeertvanderHeide
Advocate
Advocate
Accepted solution

so what i thought that worked in fact didn't. 

i built in a second layer of checks to prevent the first being empty. 

Dim oCel As SurfaceBody 
Dim counter As Integer = 1 
Dim oBool As Boolean = True
While oBool
oCel = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Cel nummeren, Esc to exit")
If oCel Is Nothing Then 
	If counter > 1
		Logger.Info("oCel is niks")
		Iets = False
		Exit While
	Else
		counter = counter + 1
	End If
Else 
	changenumber(oCel, Pcomp)
End If
end while

i agree that the counter could also be a boolean. 

this way the first check if the body is empty doesn't exit the function, and the code works as intended.

0 Likes