# 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.

```python
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

```python
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

```python
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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.polygonflow.io/advanced/dash-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
