Helper script to display the object

Hello I would like to ask if anyone could help me. I have written a helper script in python to display a given object (in the simulation I need to display one object at a given time) I would be glad if someone could advise me what I need to add to the script to make the object remain invisible after it is rendered. Alternatively, if someone could advise me how to write a script to make a given object invisible. Thank you in advance and sorry for my script if not incorrect, but I don’t know much python programming

from vcScript import *

def showBox(simulation, isRunning):
if isRunning:
Block.NodeVisible = True
else:
Block.NodeVisible = False

comp = getComponent()
Block = comp.findNode(“Block”)
Block.Visible = True

app = getApplication()
sim = app.Simulation
sim.OnStartStop = showBlock

Hello, 98.
It looks like your code should allow you to make the Block disappear when you stop playback and also make the Block appear when playback starts, I didn’t quite understand what part of it you were having trouble with, if you could please elaborate on your problem.
By the way you seem to have changed the name of the function, it should be sim.OnStartStop = showBox instead of sim.OnStartStop = showBlock.

Hi Bad thank you for your reply. I am sending an example of my problem. My problem is when the robot gets to a certain position ( in the robot program) I need the object to be displayed ( my example cube) and when I reset the simulation to make the cube disappear.
Thank you for your help.
Untitled.vcmx (2.5 MB)

1 Like

It looks like there was some error in saving your file that caused the component to not show up successfully.
Please make sure that Include Components is selected in your save options.

It should already be right. Sorry I didn’t notice it

Untitled.vcmx (9.3 MB)

My task is : To make a given object appear (for example a cube) when the robot reaches a certain position. My solution is : I have written a script which should work so that when I call it in the program the given object (for example a cube) will be displayed and when I turn off the simulation or give a reset the given object (cube) will disappear.

I made a little demo that should fit your criteria (sorry, your file wasn’t finished uploading when I did it), and I’ll check out your newly posted file in the meantime.
Visible.vcmx (567.1 KB)

I may have forgotten to add the part about making the component appear when playback continues, but I’m sure you should.

If you need to continue the playback to keep it the way it was when it stopped, you can change the Python code on Block Geo to :melting_face:

from vcScript import *
comp = getComponent()
signal = comp.findBehaviour('Bool')
def OnSignal( signal ):
  pass

def OnRun():
  comp.Visible = False
  while True:
    triggerCondition(lambda:getTrigger()==signal )
    comp.Visible = signal.Value
    comp.rebuild()
def showBox(simulation, isRunning):
  if isRunning:
    comp.Visible = signal.Value
  else:
    comp.Visible = False

app = getApplication()
sim = app.Simulation
sim.OnStartStop = showBox

Thank you for your help I will try to implement this into my problem. And I’m sorry for burdening you

It’s not a hassle and you can always ask the question again. :melting_face: