Skip to content

CLI 命令行工具

diminedimine-python-sdk 提供的命令行入口,无需编写 Python 脚本即可完成绝大部分远程场景交互和本地数据处理任务。

1. 安装与入口

安装 SDK 后,dimine 命令自动注册到系统 PATH:

pip install dimine-python-sdk

直接使用:

dimine --help

或使用 python -m 方式(适合虚拟环境未激活时):

python -m dimine_python_sdk.cli --help

2. 全局选项

所有子命令均继承以下全局选项:

选项 说明 默认值
--format {json,text} 输出格式 json
-h, --help 显示帮助信息 -

示例:

dimine file-tree --format text
dimine entity-types --format text

3. 运行模式说明

CLI 子命令分为两大类,前置条件不同:

远程命令(需 Dimine 运行)

通过 WebSocket 与已启动的 Dimine 桌面应用通信。需满足:

  1. Windows 操作系统
  2. 已设置 DIMINE_HOME 环境变量
  3. Dimine 软件已启动并开启 WebSocket 服务(默认 ws://localhost:8000

远程命令列表entity-types, get-selected, select, delete, show, hide, exclusive-show, file-tree, file-save, file-open, file-close, file-create, layers, layer-create, layer-delete, layer-show, layer-hide, layer-exclusive-show, feature-list, feature-create, feature-update, feature-delete, geometry-get, geometry-create, geometry-update, geometry-upsert

本地命令(仅需 DIMINE_HOME

直接调用本地 C++ 扩展 DmPyBindInterface.pyd 进行数据处理,无需 Dimine GUI 运行。需满足:

  1. Windows 操作系统
  2. 已设置 DIMINE_HOME 环境变量指向 Dimine 安装目录

本地命令列表datatable-info, datatable-save, datatable-add-record, datatable-set, drill-info, drill-sample-combine, drill-step-combine, drill-highgrade, block-info, block-create, block-constrain, block-eval-idw, block-eval-kriging, block-reserves, convert-file, project-plot, laneway-section

混合命令

laneway-tunnel 默认在本地生成模型后自动导入到 Dimine,因此同时需要本地 SDK 和远程 SDK 可用;仅当指定 --no-import 时才是纯本地命令。

4. 命令分类详解

4.1 实体操作

entity-types — 列出实体类型枚举及中文名

dimine entity-types

get-selected — 获取当前选中实体

dimine get-selected [--page-size 100] [--page 1]
参数 说明 默认值
--page-size 每页返回数量 100
--page 页码 1

select — 选中/取消选中实体

dimine select <file_id> <entity_ids> [--mode {replace,add,remove}]
参数 说明
file_id 文件 ID
entity_ids 逗号分隔的实体 ID 列表,如 entity_id1,entity_id2
--mode 选择模式:replace(替换)、add(追加)、remove(移除)

delete — 删除实体

dimine delete --ids <entity_ids>
参数 说明
--ids JSON 数组格式的实体列表,或 file_id/entity_id 逗号分隔格式,或 - 从 stdin 读取

show / hide / exclusive-show — 显示 / 隐藏 / 排他显示实体

dimine show --ids <entity_ids>
dimine hide --ids <entity_ids>
dimine exclusive-show --ids <entity_ids>

--ids 参数支持格式与 delete 一致。exclusive-show 会将指定实体以外的所有实体隐藏。


4.2 文件操作

file-tree — 获取打开文件及图层树

dimine file-tree

file-save — 导出文件到本地

dimine file-save --output <path> [--file-id <id>]
参数 说明
--output 保存/导出目标路径,需包含文件扩展名
--file-id 文件 ID,多个文件打开时必填

file-open — 打开文件到 Dimine 场景

dimine file-open --path <path>

file-close — 关闭 Dimine 中的文件

dimine file-close --file-id <id>

file-create — 在 Dimine 中创建新的空文件

dimine file-create --path <path>

4.3 图层操作

layers — 列出图层

dimine layers [--file-id <id>]

不提供 --file-id 时,使用当前打开的第一个文件。

layer-create — 创建图层

dimine layer-create --name <name> [--file-id <id>]

layer-delete — 删除图层

dimine layer-delete --name <name> [--file-id <id>]

layer-show / layer-hide / layer-exclusive-show — 图层可见性控制

dimine layer-show --id <layer_id> [--file-id <id>]
dimine layer-hide --id <layer_id> [--file-id <id>]
dimine layer-exclusive-show --id <layer_id> [--file-id <id>]
参数 说明
--id 图层 ID
--file-id 文件 ID,提供则跳过文件查找

4.4 要素操作

feature-list — 列出要素定义

dimine feature-list [--file-id <id>]

feature-create — 创建要素定义

dimine feature-create --file-id <id> --name <name> --defines <json>
参数 说明
--defines JSON 属性定义数组,如 '[{"name":"field","type":"string"}]'

feature-update — 更新要素定义

dimine feature-update --file-id <id> --name <name> --defines <json>

feature-delete — 删除要素定义

dimine feature-delete --file-id <id> --name <name>

4.5 几何体操作

geometry-get — 获取图层中的几何体

dimine geometry-get --file-id <id> [--layer-id <id>] [--entity-types <types>] [--features <names>]
参数 说明
--file-id 文件 ID(必填)
--layer-id 图层 ID,不提供则获取文件下所有图层的模型基础信息(不含几何数据)
--entity-types 逗号分隔的实体类型过滤,如 point,line,shell
--features 逗号分隔的要素名称过滤

geometry-create — 创建几何体

dimine geometry-create --geometries <json>
参数 说明
--geometries JSON 几何体数组,支持 JSON 字符串、文件路径(@path.json)或 stdin(-

JSON 格式示例:

[
  {
    "type": "point",
    "file": "file-id",
    "layer": "layer-id",
    "feature": "要素名",
    "geometry": {"point": [10, 20, 30]},
    "color": [255, 0, 0]
  },
  {
    "type": "line",
    "file": "file-id",
    "layer": "layer-id",
    "feature": "要素名",
    "geometry": {"points": [[0,0,0], [10,10,10]]},
    "color": [0, 255, 0]
  }
]

geometry-update — 更新几何体

dimine geometry-update --geometries <json>

JSON 需包含 id 字段以定位要更新的实体。

geometry-upsert — 创建或更新几何体

dimine geometry-upsert --geometries <json>

根据 related 字段判断是创建还是更新。


4.6 数据表(本地)

datatable-info — 加载并检查 .dmd 数据表文件

dimine datatable-info --file <path> [--column <name>] [--to-json]
参数 说明
--file .dmd 数据表文件路径
--column 提取指定列的值
--to-json 同时输出全部记录数据

datatable-save — 保存 .dmd 数据表文件

dimine datatable-save --file <path>

datatable-add-record — 向 .dmd 数据表添加记录并保存

dimine datatable-add-record --file <path> --data <json>
参数 说明
--data JSON 数组,每条为 {"字段名": "值", ...}

datatable-set — 设置 .dmd 数据表字段值并保存

dimine datatable-set --file <path> --data <json>
参数 说明
--data JSON 数组 [{"index": 0, "field": "字段名", "value": 值}, ...]

4.7 钻孔数据库(本地)

drill-info — 检查钻孔数据库文件

dimine drill-info --file <path> [--table {collar,survey,lithology}]
参数 说明
--file 钻孔 .dmf 文件路径
--table 显示指定表的记录

drill-sample-combine — 样品长度组合

dimine drill-sample-combine --params <json>

--params JSON 字段:input_file, combine_length(>0), combine_percent(0-1), output_file

drill-step-combine — 台阶/分段组合

dimine drill-step-combine --params <json>

--params JSON 字段:input_file, step_height, start_height, end_height, calculate_model, low_dip, output_file

drill-highgrade — 高品位异常值处理

dimine drill-highgrade --params <json>

--params JSON 字段:input_file, grade_field, process_mode, average_multiple, frequency, replace_method(0-5), assign_value, result_field


4.8 块模型(本地)

block-info — 检查块模型文件

dimine block-info --file <path>

block-create — 创建空块模型

dimine block-create --params <json>

--params JSON 字段:file_name, origin_x/y/z, rotate_x/y/z, size_x/y/z, length_x/y/z

block-constrain — 创建块模型约束文件

dimine block-constrain --block-file <path> --params <json> --output <path>
参数 说明
--block-file 块模型文件路径
--params JSON BlockModelConstraint
--output 输出 .dmc 文件路径

block-eval-idw — 反距离加权估计

dimine block-eval-idw --block-file <path> --constraint <json> --params <json>

block-eval-kriging — 克里金估计

dimine block-eval-kriging --block-file <path> --constraint <json> --params <json>

block-reserves — 储量/吨位计算

dimine block-reserves --block-file <path> --constraint <json> --params <json>

4.9 文件转换(本地)

convert-file — 转换采矿文件格式

dimine convert-file --source <path> --target <path> [--overwrite <bool>]
参数 说明 默认值
--source 源文件路径 -
--target 目标文件路径(扩展名决定格式) -
--overwrite 是否覆盖已存在的目标文件 true

支持格式:dmfdwg, dmfdtm(Surpac), dmfSTR(MicroMine), dmfDAT(DataMine), dmfmgis(MapGIS)


4.10 工程绘图(本地)

project-plot — 工程数据绘图

dimine project-plot --input <path> --layout <json> --setup <json> --output <path>
参数 说明
--input 输入文件路径
--layout JSON LayoutParamorigin, normal, x_axis, y_axis, thicknesses
--setup JSON SetupParams(绘图配置)
--output 输出文件路径

4.11 巷道建模(本地 + 可选导入)

laneway-section — 计算巷道断面轮廓点

dimine laneway-section --type <int> --width <float> [--height <float>] [--width-up <float>] [--wide-arch-ratio <int>] [--point-count <int>]
参数 说明 默认值
--type 断面类型:0=矩形拱, 1=梯形拱, 2=圆形拱, 3=圆弧拱, 4=三心拱, 5=六边形拱, 6=自定义 -
--width 巷道宽度(米) -
--height 墙高(米),不提供则默认 width * 0.8 -
--width-up 上宽度(米) 0.0
--wide-arch-ratio 宽度/拱高比 2
--point-count 轮廓采集点数 20

laneway-tunnel — 生成巷道三维模型并导入 Dimine

dimine laneway-tunnel --type <int> --width <float> [--height <float>] [--center-lines <json>] [--width-up <float>] [--wide-arch-ratio <int>] [--point-count <int>] [--close] [--connectivity] [--method {0,1,2}] [--no-import]
参数 说明 默认值
--type 断面类型编号 -
--width 巷道宽度(米) -
--height 墙高(米) width * 0.8
--center-lines 中心线 JSON 数组,如 '[[x1,y1,z1],[x2,y2,z2],...]';不指定则自动获取当前选中的线段 从选中获取
--width-up 上宽度(米) 0.0
--wide-arch-ratio 宽度/拱高比 2
--point-count 轮廓采集点数 20
--close 巷道尽头是否封口 false
--connectivity 交叉口是否自动联通 false
--method 建模方法:0=整体连接, 1=拐点分离, 2=顶墙分离 0
--no-import 仅生成本地模型,不导入到 Dimine false

5. JSON 参数输入技巧

CLI 中大量命令需要 JSON 参数。由于 Windows CMD 对双引号的特殊处理,推荐以下输入方式:

5.1 外层单引号包裹(推荐)

在 Windows CMD 中,用单引号包裹整个 JSON,保护内部双引号:

dimine delete --ids '[{"id":"0-158","file":"file-1"}]'

CLI 内部会自动去掉外层单引号并解析 JSON。

5.2 从文件读取(@path.json

将 JSON 保存到文件,通过 @ 前缀或 .json 扩展名引用:

dimine geometry-create --geometries @geometries.json
dimine geometry-create --geometries ./data/geos.json

5.3 从 stdin 读取(-

通过管道从 stdin 传入 JSON:

cat entities.json | dimine delete --ids -
dimine get-selected | dimine hide --ids -

注意:get-selected 的完整 JSON 输出会被自动提取 entities 字段。

5.4 常见错误修复

CLI 内部 parse_json_arg 会自动修复以下常见格式错误:

  • 外层单引号包裹
  • \" 转义(LLM 在 Windows 上生成的常见错误)
  • 单引号代替双引号(如 [{'id':'0-158'}]

如果仍解析失败,请确保使用标准双引号 JSON。

6. 输出格式对比

json 格式(默认)

$ dimine file-tree --format json
{
  "file_count": 1,
  "files": [
    {
      "id": "file-1",
      "name": "test.dmf",
      "layers": [
        {"id": "layer-1", "name": "图层1"}
      ]
    }
  ]
}
  • 结构化、机器可读
  • 支持管道传递到下游命令(dimine get-selected | dimine hide --ids -
  • 错误输出到 stderr,格式为 {"success": false, "error": "..."}

text 格式

$ dimine file-tree --format text
file_count: 1
files:
  -
    id: file-1
    name: test.dmf
    layers:
      -
        id: layer-1
        name: 图层1
  • 人类可读,适合直接查看
  • 字典递归打印为缩进文本
  • 错误输出到 stderr,格式为 Error: ...

7. 实体 ID 格式说明

--ids 参数支持三种实体引用格式:

  1. JSON 数组'[{"id":"0-158","file":"file-1"}]'
  2. 简写格式file-1/0-158,file-1/0-159(逗号分隔的 file_id/entity_id
  3. 管道输入dimine get-selected | dimine hide --ids -

简写格式在快速操作单个文件下的多个实体时最为方便。