Change JSON Import in Python Script with OSC

Hey there Touchdesigners!
I have a pretty simple python script that does some basic calculations based on imported JSON data. I want to change this imported JSON data based on OSC input. I tried that by using a Switch DAT, which could be controlled by the OSC. Unfortunately the data in the script didn’t change, when the Switch DAT was changed.

I also tried to make the setup with a CHOP Execute DAT, but since I had to write the script inside the onValueChange() function, I wasn’t able to import the script results to other nodes with the MOD class (as in the image).

Maybe anyone has some ideas on how to solve one of these problems. I am thankful for any advice!

You can directly call the jsonObject method of the jsonDat holding the wanted information. This also is a dependable method and updates correctly:

This also work correctly using your moduleapproach:

And also with json.loads. So not 100% sure where you are tripping.

Can you maybe upload your file with an easy to reporduce case?

In general I would refrain from this approach. You have nodes, so use them to make stuff easier to read. I highly suggest using a scriptDAT to parse your jsonData in to a nicely readable table and refferencing the data from there.

Thanks for the explanation!
I tried to build an easy reproduce case with a button (insted of the OSC) and here it actually works.
But if I am using an OSC In instead of a button, the switch value changes, but the final result doesn’t.

JSON_import_Python_OSC.toe (4.6 KB)


Color me surprised, this is indeed not working. When connecting directly it works, with OSC in between it does not:

When adding a null with cookType set to always it works again.

This def is a bug. Pinging @JetXS

1 Like

Thanks for the report. Will log this.


1 Like

Oh well, didn’t see that coming.
Thanks for the solution and for reporting!

So we dug pretty deep into this. Turns out there’s a subtle bug with modules and nodes that constantly cook, like OSC. The module is not being triggered to recompile, which is what is necessary to change the module member. The best practice here is to use a function in the module instead of a member. Attached is an example showing the two methods side by side.
JSON_import_Python_OSC (2).1.toe (6.8 KB)

The actual bug is in the queue, but certainly won’t be fixed until the next experimental at earlies as it’s a low level change to how cooking triggers recompilation of modules.

Thanks everyone for reports and help!

1 Like