NodeCreationType.LOAD-- distinguishing between copy/paste and program load

Use case:
I have a piece of data stored in the program node’s data model that needs to be unique for a program— it’s a path to an image stored locally where each image needs to be unique. So in the data model, I store the path to this image.
So if I copy/paste the node, the image path is also copied. This is not the behavior I desire. I’d like to be able to copy all of the data except that image path. However when a program is loaded, I want to be able to keep that image path.

I can’t distinguish between the program load state and the copy/paste state, they both show up as NodeCreationType.LOAD

Potential solutions:
Keep global state of all the image paths in use. In the program node constructor, if the context is NodeCreationType.LOAD, then check this global state. If the path is there in the global state, remove the image path from this node’s data model.

why this doesn’t work:
multiple loadings of the same program. The second loading of the program would think that every node was being copy/pasted since the image paths would already be in this global state

what I would need for it to work:
an ability to hook into some event upon program load so that I could clear out this global state
Does this exist?

or-- an ability to hook into program node removal so that I could clear this particular node’s image path out of the global state.
Does this exist? (finalize is not sufficient)

In the program node constructor, if the context is NodeCreationType.LOAD

  • if the image path is not empty, create a new image path and copy the old file to it (the old file path can’t be deleted though because this could be a copy/paste situation)

this completely litters the filesystem with unused image files. this is not tenable.

So in summary–
Are there any solutions available to either
1- when the context is NodeCreationType.LOAD, to distinguish between load and copy/paste?
2- an ability to hook into some event upon program load so that I could perform an action?
3- an ability to hook into program node removal so that I could perform an action? (the finalize method is not sufficient)



This feature of having a callback to read load state vs copy/paste currently does not exist. One potential work around, is to write to a temp file in the resource folder when the program is stopped. Then, create a callout to read the variable when the program is running so it holds the latest image file in some temp storage.

And what sort of “onProgramStop” method is available? You can somewhat leverage generateScript() to capture onPlay (though it also can’t distinguish between save and play), but I haven’t seen anything that fires on stop. Only the IO. Unless you’re suggesting to implement a thread that monitors some IO set to go High when running or something. In my experience, management of the program tree is one of the biggest short comings in the CAP API.

But the issue would still be present if a program is not actually run, just loaded. For example:

  • Load program.
  • Change mind.
  • Load another program.
  • Realize you were right the first time.
  • Load first program again and run.

Hopefully this feature gets added in the future, or at the very least, update the API documentation so that it clarifies that it considers copy/paste as LOAD:


Since the manual is not telling the whole truth there.

1 Like

@eric.feldmann @janna

I would suggest everyone wanting or needing some sort of feature like this in the API to take couple seconds to upvote the topics such as this one in the product whist list section of the forum. This will let dev teams know the importance of such features.

Work arounds do exist but are complicated, limited and need to be well though to limit problems with Polyscope.
I see a lot of applications and cases where we would be able to provide a better overall experience to users.

I went ahead and liked the post. Hopefully it’s understood though that a 2 year old post with no response from an official UR rep doesn’t exactly instill confidence in end users like ourselves that anything is being done about it.