# Python scripts

**URL:** <https://forum.visualcomponents.com/t/python-scripts/1456>\
**Category:** Academy\
**Created:** [June 20, 2020, 8:56pm UTC](https://forum.visualcomponents.com/t/python-scripts/1456 "2020-06-20T20:56:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 20, 2020, 8:56pm UTC](https://forum.visualcomponents.com/t/python-scripts/1456/1 "2020-06-20T20:56:20Z")

</div>

How can i arrange the execution of several python scripts in my system?

I have 3 python scripts, one in the robot and the other two are in two different sensors

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [June 21, 2020, 12:31pm UTC](https://forum.visualcomponents.com/t/python-scripts/1456/2 "2020-06-21T12:31:56Z")

</div>

> [@OmarTaher](#):
>
> How can i arrange the execution of several python scripts in my system?

Hy,

maybe control it with condition or triggercondition?

Regards  
Feature

---

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 24, 2020, 12:57am UTC](https://forum.visualcomponents.com/t/python-scripts/1456/3 "2020-06-24T00:57:46Z")

</div>

@captain_feature I tried but the whole program stops and does not respond.  
I have to reopen my file again.  
I am using:  
while app.Simulation.IsRunning== True:  
when i remove it the problem doesn’t occur but my program doesn’t loop

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [June 24, 2020, 6:24am UTC](https://forum.visualcomponents.com/t/python-scripts/1456/4 "2020-06-24T06:24:37Z")

</div>

> [@OmarTaher](#):
>
> while app.Simulation.IsRunning== True:

Post your code the maybe the problem can be found…

Regards  
Feature

---

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 24, 2020, 11:22am UTC](https://forum.visualcomponents.com/t/python-scripts/1456/5 "2020-06-24T11:22:57Z")

</div>

@captain_feature signals 111 and 112 are used to switch between this and the other python script.

```
vcScript import *
from vcHelpers.Robot2 import *
def OnRun():
  app = getApplication()
  size=18
  x,y,z=0,0,0
  #getting the robot
  robot_comp = app.findComponent("IRB 4600-45/2.05")
  robot = getRobot(robot_comp)
  robot.SignalMapOut.output(111, True)

  while app.Simulation.IsRunning== True:
   if robot.SignalMapOut.output(111, True):

#start by getting the part
 comp = getComponent()
 sensor_signal = comp.findBehaviour("SensorComponentSignal")
 triggerCondition(lambda : sensor_signal.Value != None)
 part = sensor_signal.Value
 #Pick Part
 robot.pick(part)
#Get the parent pallet
 conveyorOut = app.findComponent("Conveyor 5")
 pallet = conveyorOut.ComponentChildren[-3]
 # Place pattern on pallet
 robot.placeInPattern(pallet,x,y,z,3,3,2)
 size -= 1
 if x < 2:
  x += 1
 else:
  x = 0
  y += 1
 if y > 2: 
  y = 0
  z += 1
  #nullifying the variables and allowing the pallet out to accept new one
 if size == 0:
   size=18
   robot.SignalMapOut.output(110, True)
   delay(5.0)
   x,y,z=0,0,0 
   delay(0.5) 
   #motor on to accept new parts
 robot.SignalMapOut.output(109, True)
 robot.SignalMapOut.output(111, False)
 
 robot.SignalMapOut.output(112, False)
 
 #sensor_comp = app.findComponent("Sensor")
 #sensor = sensor_comp.findBehaviour("PythonScript_2")`Preformatted text`
```

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [June 24, 2020, 2:06pm UTC](https://forum.visualcomponents.com/t/python-scripts/1456/6 "2020-06-24T14:06:33Z")

</div>

Hy,

is this one script you posted? -\> If so please format the first part so as the second!

Regards  
Feature

---

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 24, 2020, 2:22pm UTC](https://forum.visualcomponents.com/t/python-scripts/1456/7 "2020-06-24T14:22:44Z")

</div>

Just did it. I have also tried replacing the robot signals 111 and 222 with simple flags, but the program still break down.  
The problem is in using flags with the while app,isSimulation.IsRunning statement I think

---

<div class="post-metadata">

**Author:** ![captain\_feature](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/captain_feature/32/5547_2.png) [@captain\_feature](https://forum.visualcomponents.com/u/captain_feature)\
**Post date:** [June 24, 2020, 2:28pm UTC](https://forum.visualcomponents.com/t/python-scripts/1456/8 "2020-06-24T14:28:15Z")

</div>

> [@OmarTaher](#):
>
> The problem is in using flags with the while app,isSimulation.IsRunning statement I think

Try insert “delay(0.1)” in the while loop?

Regards  
Feature

---

<div class="post-metadata">

**Author:** ![OmarTaher](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@OmarTaher](https://forum.visualcomponents.com/u/OmarTaher)\
**Post date:** [June 24, 2020, 4:11pm UTC](https://forum.visualcomponents.com/t/python-scripts/1456/9 "2020-06-24T16:11:58Z")

</div>

Luckily the program doesn’t stop anymore But, the if condition is never true to execute the task  
I am not connecting signals 111 and 112 of the robot to anything.  
Could this be the problem?
