Running script in the background
![onix](https://secure.gravatar.com/avatar/bba3a42aeab8a0f2abd8d289e8b4c596?&r=pg&s=100&d=https%3A%2F%2Fvanillicon.com%2Fbba3a42aeab8a0f2abd8d289e8b4c596_100.png)
I can't find any way to put a script in the background so that it could keep running without blocking interface.
Since all scripts behave the same way I guess it is not possible, so maybe Daz developers could fix that problem?
Ideally, even multiple scripts could be allowed to run at the same time. Technically I do not see any problems with that.
If scripts inevitably block interface it severely limits their usability. even when using something that does not require user interaction it is preferable to bring the main on to top so see what is happening there sometimes it may be useful to halt script. or kill it if it does not respond anymore, now if script hangs, you are screwed and lose your work, there is no way to access DAZ interface anymore.
Nonblocking scripts potentially can introduce some problems with race conditions but I think they can be safely ignored and dealt on individual basis.
This feature could bring Daz scripting to an entirely new level making scripts almost as functional as plugins. As a bonus, it can improve CPU utilization because Daz only uses 2 threads most of the time so it will not hurt performance at all even if the script does complex CPU intensive work.
Comments
There was some discussion on non-modal scripts, essentially the advice was be very, very careful if you try it - and it's probably better not to. Depending on your goal you might want to look at the post-load callback samples: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/start#elements
Thanks, looks like I am finding some info about that but I would love to get some reference to any information on how it can be done.
My goal is actually to create a controller interface for something that resembles VR gloves. So the script itself must run all the time, react to the information it gets from outside and perform appropriate tasks.
for example, I select some body part or item in the scene and use VR glove to manipulate it transferring my hand pose into the pose of that object
or alternatively can link various scene objects with individual controllers
Here's a link to Rob's post on this topic. Summary: The official way to do what you described is to use the SDK to create a new plug-in DzPane.
BUT: The post-load callbacks mechanism referred to by Richard may do all or most of what you want?: It lets your script(s) get control any time an event occurs whose signal is exposed to script. Your event-handler script does whatever you want (quickly, so as to appear to be non-blocking) and returns control to DS. Its not as flexible as a plug-in, but it is cross-platform, and potentially very useful. I'm surprised that there's very little mention of its use in the forums Here is an outline of one way I've used it:
Give it a try!
Oh, what luck, just found your previous discussion about that issue and you replied here.
If I understand correctly, Scene::timeChanging() is some sort of timer event which can be used for polling, so that may work because this is what my script should be doing by itself. But I wonder if the script will be reloaded over 4000 times a second how it will affect performance.
Creating a plugin is kinda out fo question for several reasons. so I am keeping all options open. I will have to try it and see what happens.
p.s. Since you were trying to do it did you ever encountered any problems?
p.p.s. timeChanging() seems to be not a timer but timeline so it is not useful here.
p.p.p.s Great, in the simple test, everything seems to work without any problems or crashes so far. Also, scripts can be unblocked with just a few small changes.
the next goal is to actually make things go wrong to test Rob's theory.
Yes, timeChanging() is triggered only at each Frame of an animation. You probably want DzTimer instead.
I've had no problems - but I'm not using Scene::timeChanging() or DzTimer::timeout(). My CallBacks project is just a Sun control that does a better job than the built-in Iray Sun Dial - it only has to respond to occasional User-initiated events such as changing the Latitude slider value, etc. You VR project is much more ambitious - Good Luck!
Since you said "it seemed like a good idea at the time, but it wasn't." I expected that you encountered some problems. But I guess I will be the first who ever made such a thing.
But thanks anyway because your post made it possible :)