Author Topic: Creating an sbsar node in a graph through the Python API  (Read 6657 times)

Hi, I am trying to create an sbsar node inside a graph using the Python API. I am not sure this is currently possible, I would appreciate any info about this. Currently here is what I am doing:

  • I have the sbsar manually imported as a resource inside the current package. By inspecting package content I can see the sbsar and its graphs are imported as SDResourceCustom, which is not a good sign for what follows as the doc defines custom resources as "A valid resource whose type is not natively supported"
  • I made code to access current graph and create a new instance inside it using SDGraph.newInstanceNode(sbsar) (sbsar being of type SDResourceCustom). As a result, I get an exception saying "not supported".

So it seems to me we cannot currently create sbsar instances in a graph, is this right?

So it seems to me we cannot currently create sbsar instances in a graph, is this right?

Nope, it's absolutely possible and you almost had it.
The fault lies with the documentation, as it's lacking and really unclear for this process.

Code: [Select]
pkg_mgr = aContext.getSDApplication().getPackageMgr()
pkg = pkg_mgr.getUserPackages()[0]
graph = pkg.getChildrenResources(False)[0]
# Load graph instance.
my_sbsar_pkg = pkg_mgr.loadUserPackage('path_to_sbsar')  # Load the pacakge.
my_sbsar_node = graph.newInstanceNode(my_sbsar_pkg.findResourceFromUrl('name_of_graph'))  # Create graph instance.

# Cleanup.
pkg_mgr.unloadUserPackage(my_sbsar_pkg)  # Unload the package.

Note: I don't remember how I figured this out as it was months ago.
There may even be other/better ways of doing this now, but it works well enough.

Maybe I grep'd through the examples directory? Can't remember.

Last Edit: October 23, 2019, 04:36:17 pm

Thanks a lot NevTD, it is working perfectly! I didn't realize the sbsar was considered as a package which needed to be loaded.

Neither did I.
It's a huge assumption on my part so it's possible there's an easier way, but I haven't come across one so far.

Well the way you found looks logical and is doing exactly what I need so as far as I am concerned the solution is perfect! Thanks again.