Author Topic: Replace a Dependency with Another  (Read 135 times)

I'm stuck trying to replace dependencies. I'm creating permutations of template graphs, and I need to replace the dependency and update it's associated comp node instances with the correct graph path.

I first create my new dependency with
Code: [Select]
Then I update references using
Code: [Select]
sbs_doc.declareDependencyUIDChanged(dependency.mUID, new_dependency.mUID)
I can query for dependent nodes using
Code: [Select]
sbs_doc.getAllReferencesOnDependency(dependency) but I can't figure out how to update the path to the graph.

My comp node instance looks something like this:

Code: [Select]
<path v="pkg:///Old_Graph?dependency=1348955762"/>
but I need to update to something like this:
Code: [Select]
<path v="pkg:///New_Graph?dependency=1348955762"/>

I've still been trying for a while this morning to get this to work. I'm either missing something completely, or it's trickier than I imagined.

I've tried to get the comp instance nodes, and change their paths, but it's not working as expected.

Code: [Select]
dependant_nodes = sbs_doc.getAllReferencesOnDependency(dependency) # type: list[pysbs.compnode.compnode.SBSCompNode]
for dependant in dependant_nodes:
    comp_instance = dependant.getCompImplementation() # type: pysbs.compnode.compimplementation.SBSCompInstance
    comp_instance.changeInstancePath(new_dependency_doc, sbs_doc, new_dependency_graph_path)

I know the graph exists, because I've parsed the new parent graph, and computed it's internal graph path using the API in a helper function.. that is what is being assigned to 'new_dependency_graph_path' and passed in as the 'aGraphRelPath' parameter.

Code: [Select]

But I'm still getting exceptions trying to update the path

Code: [Select]
  File "D:\Pipeline\Dev\_Colossus\Python\python27Lib\Lib\site-packages\pysbs\compnode\", line 303, in changeInstancePath
    raise SBSImpossibleActionError('Failed to change the instance path to '+aGraphRelPath)
pysbs.api_exceptions.SBSImpossibleActionError: Failed to change the instance path to pkg:///new_graph_to_assign

I think I got it. I misread the parameters.. "Parent Doc" to me sounded like the source, containing doc, not the doc to hold the instance. I interpreted the parameters opposite of their intention.

swapping the document parameters results in the expected outcome now

Code: [Select]
comp_instance.changeInstancePath(sbs_doc, new_dependency_doc, new_dependency_graph_path)

And, using this method reduced the code a bit, since it create's the new dependency for me and updates UIDs and paths. I only need to remove the old one now.
Last Edit: May 06, 2019, 05:00:23 pm