Skip to main content
Inspiring
February 28, 2025
해결됨

Access library node ids using the Python API

  • February 28, 2025
  • 1 답변
  • 472 조회

Hi, I would need to access the ids of the graphs present in the default node library in Designer using the Python API. For example nodes such as "Cells 4" or "Switch". I can see Designer is able to extract the relevant ids from packages located into the resources/packages system folder when we right-click on a library node, we can see both the .sbs path and the graph id. For example the "auto_crop.sbs" package contains both "auto_crop_color" and "auto_crop_grayscale" graph ids. I would basically need to access this same information from the Python API, I don't think this is possible right-now.

최고의 답변: Luca Giarrizzo

Hello Olivier,

 

Unfortunately, there is indeed no way to directly the data in Designer's library database through the Python API.

To list the identifiers of graphs from Designer's default library, you may manually load its content and read it, which can be slow dependending on what you access.

 

Here is a sample script that does just that:

import os
from os import path

import sd
from sd.api.sdapplication import SDApplicationPath
from sd.api import SDSBSCompGraph

app = sd.getContext().getSDApplication()
pkgMgr = app.getPackageMgr()

pkgDirPath = os.path.join(app.getPath(SDApplicationPath.DefaultResourcesDir), "packages")

for pkgFilename in os.listdir(pkgDirPath):
	if pkgFilename[0] == "a":
		pkgPath = os.path.join(pkgDirPath, pkgFilename)
		
		pkg = pkgMgr.loadUserPackage(pkgPath)
		print(pkgFilename)
		for rsc in pkg.getChildrenResources(isRecursive=True):
			if isinstance(rsc, SDSBSCompGraph):
				print(f"  - {rsc.getIdentifier()}")
		pkgMgr.unloadUserPackage(pkg)

 

Alternatively, you may read from the database directly in Python, without going through the API. The database uses the simple JSON format which is easy to parse. It is the resources.json file in Designer's user data:

 

(Windows) %LOCALAPPDATA%/Adobe/Adobe Substance 3D Designer/databases/resources.json

(macOS) ~/Library/Application Support/Adobe/Adobe Substance 3D Designer/databases/resources.json

 

The graph identifiers are stored in the "basename" key.

 

I hope this is helpful!

1 답변

Luca Giarrizzo
Community Manager
Community Manager
March 5, 2025

Hello Olivier,

 

Unfortunately, there is indeed no way to directly the data in Designer's library database through the Python API.

To list the identifiers of graphs from Designer's default library, you may manually load its content and read it, which can be slow dependending on what you access.

 

Here is a sample script that does just that:

import os
from os import path

import sd
from sd.api.sdapplication import SDApplicationPath
from sd.api import SDSBSCompGraph

app = sd.getContext().getSDApplication()
pkgMgr = app.getPackageMgr()

pkgDirPath = os.path.join(app.getPath(SDApplicationPath.DefaultResourcesDir), "packages")

for pkgFilename in os.listdir(pkgDirPath):
	if pkgFilename[0] == "a":
		pkgPath = os.path.join(pkgDirPath, pkgFilename)
		
		pkg = pkgMgr.loadUserPackage(pkgPath)
		print(pkgFilename)
		for rsc in pkg.getChildrenResources(isRecursive=True):
			if isinstance(rsc, SDSBSCompGraph):
				print(f"  - {rsc.getIdentifier()}")
		pkgMgr.unloadUserPackage(pkg)

 

Alternatively, you may read from the database directly in Python, without going through the API. The database uses the simple JSON format which is easy to parse. It is the resources.json file in Designer's user data:

 

(Windows) %LOCALAPPDATA%/Adobe/Adobe Substance 3D Designer/databases/resources.json

(macOS) ~/Library/Application Support/Adobe/Adobe Substance 3D Designer/databases/resources.json

 

The graph identifiers are stored in the "basename" key.

 

I hope this is helpful!

Luca Giarrizzo | Quality Engineer - Substance 3D Designer | Adobe
_Olivier_L작성자
Inspiring
March 5, 2025

Thank you Luca! This looks great, I will try this and let you know.