Dash API

Dash's codebase is a mix of native Python code, C++ libraries, UE Python API code, etc... To make it easier to navigate, we've built a simple interface class through which you can access most useful functionalities. Before we dig in, a few things to keep in mind:

  • Dash is an editor-only plugin, and doesn't operate at runtime.

Using the API

DashAPI is an interface class that groups all the most common and useful features you'll want to interact with. There's a wide range of classes, functions and libraries that Dash uses, and you can go through them as we often add simple docstrings a bit everywhere. However, the goal of DashAPI is to avoid that need for most basics.

from GN.DashAPI import DashAPI

# Get a list of all tools in the scene.
scene_tools = DashAPI.getActiveTools()

# Iterate over each tool, and print the name of its container type properties.
for tool in scene_tools:
    props = tool.getPropertiesByType(DashAPI.PropertyTypes.SceneContainer)
    for prop in props:
        print(f"{prop.getName()} - {prop.getValue()}")

# Get the active tool that's visible in the Tools Panel.
active_tool = DashAPI.getActiveTool()

# Find its property "Surface", and set its value to the current scene selection.
surface_prop = active_tool.getProperty("surface")
selection = DashAPI.Scene.fromSelection()
if surface_prop and selection:
    surface_prop.setValue(selection)

# Rename the property
surface_prop.setName("Selection")

# Select the objects that the active tool generates
tool_output = DashAPI.getToolOutput(active_tool)

# Hide its result
tool_output.setVisibility(False)

# Delete the active tool
DashAPI.deleteTool(active_tool)

# Create a new tool by its name
tool = DashAPI.createTool("surface scatter", show=True)
# Adjust its properties
tool.setValue("surface", DashAPI.Scene.fromObjectNames(["ground_plane"]))
tool.setValue("scatter", DashAPI.Scene.fromSelection())
tool.setValue("density", 0.75)
tool.setValue("min scale", 0.70)
tool.setValue("seed", DashAPI.randomSeed())

# Save the settings as a preset. This won't save the container properties.
new_preset = DashAPI.saveToolPreset(tool)

# Create a new tool
new_tool = DashAPI.createTool("Surface Scatter")
# Assign the preset to it
DashAPI.setToolPreset(new_tool, new_preset)

Creating a Tool

Instancing Tool

from GN.GNL.ToolCreation import ToolDescriptor, ToolRunner

class GraphNTool(ToolRunner):

    def __init__(self):
        super(GraphNTool, self).__init__()

    def run(self, *args, **kwargs):
        return

    @staticmethod
    def createDescriptor():
        tool = ToolDescriptor(identifier=128930, name='Compound Tool',
                              description='This is a simple test tool')
        tool.setCompoundTool(True)

        return tool

Mesh Generation Tool

from GN.GNL.ToolCreation import ToolDescriptor, ToolRunner

class GraphNTool(ToolRunner):

    def __init__(self):
        super(GraphNTool, self).__init__()

    def run(self, *args, **kwargs):
        return

    @staticmethod
    def createDescriptor():
        tool = ToolDescriptor(identifier=128930, name='Compound Tool',
                              description='This is a simple test tool')
        tool.setCompoundTool(True)

        return tool

Last updated

Was this helpful?