Skip to main content
Known Participant
July 20, 2025
Question

SBS splitting

  • July 20, 2025
  • 1 reply
  • 106 views

I am trying to  persuade chatGPT to write me a python editor script that would split  big sbs  files into separate ones for each graph each own  except those used inside other graphs of same sbs  to be included only in those splitted sbs files that  may need them.   

Chat informed me : In Substance Designer 14.1.2 (build 8986, April 2025)
Neither the sd nor substance_designer Python API modules are available in the Python Editor, so scripting graph/package management is not possible.

 

Could somebody comment please 

1 reply

Community Expert
July 21, 2025

Hey Kirill,

I don't understand your error message, but ChatGPT is definitely lying to you 😉 of course the Python API is available in the Python Editor, that is the whole reason that editor exists.

 

Please do yourself a favour and don't rely on ChatGPT alone, read the API Documentation and try to understand what you do and also how the API works, ChatGPT is trained on a lot of documents and it speaks really good "Python" but the SD API Documentation is always been offline, so not really in the training data, that means ChatGPT will make things up.

 

Here is a short breakdown of how you achieve what you want:

  • Loop through the current Package and get all Children of the package
  • For each Child find all the nodes in the graph
  • loop through all the nodes, get their referenced package
  • if the referenced package is the current package, you can stop the loop and mark that graph as neccessary, so it stays
  • if not, add that graph to a list, which will be used to create a new file

 

I don't have much time but here is a short script, which should get you on the right track:

import sd

ctx = sd.getContext()
app = ctx.getSDApplication()
package_mgr = app.getPackageMgr()

user_packages = package_mgr.getUserPackages()

for package in user_packages:
    print(f"CURRENT PACKAGE: {package.getFilePath()}")
    children_resources = package.getChildrenResources(isRecursive=True)
    if children_resources:
        print("PACKAGE CHILDREN:")
        for child_resource in children_resources:
            print(
                f"  => CHILD RESOURCE: {child_resource.getIdentifier()} ({child_resource.getClassName()})"
            )
            if child_resource.getClassName() == "SDSBSCompGraph":
                graph_nodes = child_resource.getNodes()
                print("     GRAPH NODES:")
                for node in graph_nodes:
                    print(f"    => NODE: {node.getIdentifier()}")
                    print(f"       NODE CLASS: {node.getClassName()}")
                    print(f"       NODE REFERENCED RESOURCE: {node.getReferencedResource()}")
                    if node.getReferencedResource():
                        print(f"       NODE REFERENCED RESOURCE CLASS: {node.getReferencedResource().getClassName()}")
                        print(f"       NODE REFERENCED RESOURCE IDENTIFIER: {node.getReferencedResource().getIdentifier()}")
                        print(f"       NODE REFERENCED RESOURCE PACKAGE: {node.getReferencedResource().getPackage()}")
                        print(f"       NODE REFERENCED RESOURCE PACKAGE PATH: {node.getReferencedResource().getPackage().getFilePath()}")
                    print(f"       NODE DEFINITION: {node.getDefinition()}")
                    print(f"       NODE ID: {node.getDefinition().getId()}")
                    print(f"       NODE LABEL: {node.getDefinition().getLabel()}")
Stay healthy and creative Marco