# Dash API

Dash 的代码库是由原生 Python 代码、C++ 库、UE Python API 代码等混合组成的。\
为了便于浏览，我们构建了一个简单的接口类，通过它你可以访问大多数有用的功能。在深入之前，有几点需要记住：

* Dash 是一个仅限编辑器的插件，不在运行时工作。

## 使用 API

DashAPI 是一个接口类，汇集了你可能想要交互的大多数常用且有用的功能。Dash 使用了大量类、函数和库，你可以查看它们，我们经常在各处添加简短的文档字符串。\
然而，DashAPI 的目标是避免在大多数基础操作上出现这种需要。

```python
from GN.DashAPI import DashAPI

# 获取场景中所有工具的列表。
scene_tools = DashAPI.getActiveTools()

# 遍历每个工具，并打印其容器类型属性的名称。
for tool in scene_tools:
    props = tool.getPropertiesByType(DashAPI.PropertyTypes.SceneContainer)
    for prop in props:
        print(f"{prop.getName()} - {prop.getValue()}")

# 获取在工具面板中可见的活动工具。
active_tool = DashAPI.getActiveTool()

# 找到它的属性 "Surface"，并将其值设置为当前场景选择。
surface_prop = active_tool.getProperty("surface")
selection = DashAPI.Scene.fromSelection()
if surface_prop and selection:
    surface_prop.setValue(selection)

# 重命名该属性
surface_prop.setName("Selection")

# 选择该活动工具生成的对象
tool_output = DashAPI.getToolOutput(active_tool)

# 隐藏其结果
tool_output.setVisibility(False)

# 删除活动工具
DashAPI.deleteTool(active_tool)

# 通过名称创建一个新工具
tool = DashAPI.createTool("surface scatter", show=True)
# 调整其属性
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())

# 将设置保存为预设。这不会保存容器属性。
new_preset = DashAPI.saveToolPreset(tool)

# 创建一个新工具
new_tool = DashAPI.createTool("Surface Scatter")
# 将预设分配给它
DashAPI.setToolPreset(new_tool, new_preset)

```

## 创建工具

### 实例化工具

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

### 网格生成工具

```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/dash-documentation-zh/gao-ji/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.
