Skip to content

CLI 典型使用示例

以下示例覆盖远程场景交互和本地数据处理两大场景,演示 dimine CLI 的常见工作流。

前置条件

  • 已安装 dimine-python-sdk
  • 远程命令示例:Dimine 已启动并开启 WebSocket 服务
  • 本地命令示例:已设置 DIMINE_HOME 环境变量

场景一:获取场景信息

从打开文件到获取图层再到获取几何体的完整工作流。

1. 查看当前打开的文件和图层树

$ dimine file-tree
{
  "file_count": 1,
  "files": [
    {
      "id": "f-20240527-001",
      "name": "矿山模型.dmf",
      "layers": [
        {"id": "l-001", "name": "地表"},
        {"id": "l-002", "name": "矿体"},
        {"id": "l-003", "name": "巷道"}
      ]
    }
  ]
}

2. 列出指定文件的所有图层

$ dimine layers --file-id f-20240527-001
{
  "file_id": "f-20240527-001",
  "layer_count": 3,
  "layers": [
    {"id": "l-001", "name": "地表"},
    {"id": "l-002", "name": "矿体"},
    {"id": "l-003", "name": "巷道"}
  ]
}

3. 获取图层中所有几何体

$ dimine geometry-get --file-id f-20240527-001 --layer-id l-002 --entity-types shell
{
  "file_id": "f-20240527-001",
  "layer_id": "l-002",
  "entity_count": 2,
  "geometries": [
    {
      "id": "0-158",
      "file": "f-20240527-001",
      "layer": "l-002",
      "feature": "矿体1",
      "type": "shell",
      "color": [255, 128, 0],
      "properties": [...],
      "points": [[...]],
      "faces": [[...]]
    }
  ]
}

场景二:实体选择与管道操作

利用管道将 get-selected 的输出直接传递给 hidedelete

1. 获取当前选中的实体

$ dimine get-selected
{
  "total_count": 3,
  "page_size": 100,
  "page_num": 1,
  "count": 3,
  "entities": [
    {"id": "0-158", "file": "f-001", "layer": "l-002", "entity_type": "shell", "feature": "矿体1"},
    {"id": "0-159", "file": "f-001", "layer": "l-002", "entity_type": "shell", "feature": "矿体1"},
    {"id": "0-160", "file": "f-001", "layer": "l-003", "entity_type": "line", "feature": "巷道中线"}
  ]
}

2. 隐藏选中的实体

$ dimine get-selected | dimine hide --ids -
{
  "success": true,
  "action": "hide",
  "action_cn": "隐藏",
  "count": 3,
  "message": "已成功隐藏 3 个实体"
}

3. 使用简写格式批量删除

$ dimine delete --ids f-001/0-158,f-001/0-159
{
  "success": true,
  "deleted_count": 2,
  "message": "已成功删除 2 个实体"
}

场景三:创建几何体

从 JSON 文件读取几何体定义并创建到 Dimine 场景中。

1. 准备几何体 JSON 文件

new_points.json

[
  {
    "type": "point",
    "file": "f-20240527-001",
    "layer": "l-001",
    "feature": "勘探点",
    "geometry": {"point": [1000.5, 2000.3, 1250.0]},
    "color": [255, 0, 0]
  },
  {
    "type": "point",
    "file": "f-20240527-001",
    "layer": "l-001",
    "feature": "勘探点",
    "geometry": {"point": [1005.0, 2010.0, 1248.5]},
    "color": [255, 0, 0]
  }
]

2. 创建几何体

$ dimine geometry-create --geometries @new_points.json
{
  "success": true,
  "created_count": 2,
  "result": "...",
  "message": "已成功创建 2 个几何体"
}

3. 直接在命令行传入 JSON

$ dimine geometry-create --geometries '[{"type":"line","file":"f-001","layer":"l-003","feature":"巷道中线","geometry":{"points":[[0,0,0],[100,50,30]]},"color":[0,255,0]}]'

场景四:图层可见性控制

快速聚焦到目标图层,隐藏其他所有图层。

1. 排他显示指定图层

$ dimine layer-exclusive-show --id l-002
{
  "success": true,
  "action": "exclusive_show",
  "action_cn": "排他显示",
  "layer_id": "l-002",
  "layer_name": "矿体",
  "count": 2,
  "message": "已成功排他显示图层 矿体 中的 2 个实体"
}

2. 恢复显示全部图层

先显示目标图层,再显示其他图层:

$ dimine layer-show --id l-001
$ dimine layer-show --id l-003

场景五:本地数据处理

无需 Dimine 运行,直接处理本地文件。

1. 检查钻孔数据库

$ dimine drill-info --file "D:/Data/drill.mdb"
{
  "file": "D:/Data/drill.mdb",
  "drill_count": 156,
  "total_length": 28560.5,
  "collar_table": {
    "record_count": 156,
    "fields": ["工程号", "横坐标", "纵坐标", "高程", "总深度", "勘探线"]
  },
  "survey_table": {
    "record_count": 1248,
    "fields": ["工程号", "测斜深度", "方位角", "倾角"]
  },
  "lithology_table": {
    "record_count": 3420,
    "fields": ["工程号", "起始", "结束", "岩性编号"]
  }
}

2. 查看具体表的数据

$ dimine drill-info --file "D:/Data/drill.mdb" --table collar

3. 转换文件格式

将 Dimine .dmf 转换为 AutoCAD .dwg

$ dimine convert-file --source "D:/Data/model.dmf" --target "D:/Output/model.dwg"
{
  "success": true,
  "source": "D:/Data/model.dmf",
  "target": "D:/Output/model.dwg",
  "overwrite": true,
  "message": "文件已转换: D:/Data/model.dmf -> D:/Output/model.dwg"
}

4. 计算巷道断面轮廓

$ dimine laneway-section --type 0 --width 4.5 --height 3.8
{
  "success": true,
  "section_type": 0,
  "width": 4.5,
  "wall_height": 3.8,
  "width_up": 0.0,
  "wide_arch_ratio": 2,
  "point_count": 20,
  "points": [
    [-2.25, 0.0, 0.0],
    [-2.25, 1.0, 0.0],
    ...
  ]
}

场景六:巷道建模并导入 Dimine

在 Dimine 中选中巷道中心线,生成立体巷道模型并自动导入。

1. 在 Dimine 中选中中心线

手动选中一条代表巷道中心线的多段线。

2. 生成巷道模型并导入(默认行为)

$ dimine laneway-tunnel --type 0 --width 4.5 --height 3.8 --close --connectivity
{
  "success": true,
  "section_type": 0,
  "width": 4.5,
  "wall_height": 3.8,
  "center_line_points": 12,
  "total_faces": 420,
  "total_vertices": 380,
  "imported": {
    "status": "ok",
    "file": "矿山模型.dmf",
    "layer": "巷道",
    "feature": "巷道",
    "entity_count": 1
  }
}

3. 仅生成本地模型,不导入 Dimine

$ dimine laneway-tunnel --type 0 --width 4.5 --height 3.8 --close --no-import
{
  "success": true,
  "section_type": 0,
  "width": 4.5,
  "wall_height": 3.8,
  "center_line_points": 12,
  "total_faces": 420,
  "total_vertices": 380,
  "imported": false
}

4. 使用自定义中心线(不依赖 Dimine 选中)

$ dimine laneway-tunnel --type 4 --width 5.0 --center-lines '[[0,0,100],[50,0,100],[100,50,100]]' --method 1

如果不提供 --center-lines,CLI 会自动尝试从 Dimine 当前选中的线段获取;如果 Dimine 未运行且未提供 --center-lines,命令会报错。


场景七:数据表批处理

.dmd 数据表文件进行批量增删改查。

1. 查看数据表结构

$ dimine datatable-info --file "D:/Data/sample.dmd"
{
  "file": "D:/Data/sample.dmd",
  "field_count": 5,
  "record_count": 128,
  "fields": ["ID", "名称", "品位", "厚度", "深度"]
}

2. 查看某一列的值

$ dimine datatable-info --file "D:/Data/sample.dmd" --column 品位
{
  "column": "品位",
  "count": 128,
  "values": [0.52, 1.23, 0.89, ...]
}

3. 批量添加记录

$ dimine datatable-add-record --file "D:/Data/sample.dmd" --data '[{"ID": 129, "名称": "ZK-129", "品位": 2.15, "厚度": 5.2, "深度": 320.0}]'
{
  "success": true,
  "file": "D:/Data/sample.dmd",
  "added_count": 1,
  "total_records": 129,
  "message": "已添加 1 条记录并保存"
}

4. 批量修改字段值

$ dimine datatable-set --file "D:/Data/sample.dmd" --data '[{"index": 0, "field": "品位", "value": 0.55}, {"index": 1, "field": "品位", "value": 1.30}]'
{
  "success": true,
  "file": "D:/Data/sample.dmd",
  "updated_count": 2,
  "total_records": 129,
  "message": "已更新 2 个字段并保存"
}

场景八:块模型估值与储量计算

对本地块模型文件进行地质统计学和储量计算。

1. 检查块模型信息

$ dimine block-info --file "D:/Data/ore_model.dmb"
{
  "file": "D:/Data/ore_model.dmb",
  "origin": [1000.0, 2000.0, 500.0],
  "xyz_length": [500.0, 400.0, 200.0],
  "max_level": 5,
  "min_size": [5.0, 5.0, 5.0],
  "rotation": [0.0, 0.0, 0.0],
  "field_definitions": ["Cu", "Au", "density"],
  "total_block_count": 320000
}

2. 反距离加权(IDW)估值

$ dimine block-eval-idw --block-file "D:/Data/ore_model.dmb" --constraint '{"region": [...]}' --params '{"power": 2, "search_radius": 100, "min_samples": 3}'
{
  "success": true,
  "block_file": "D:/Data/ore_model.dmb",
  "method": "idw",
  "message": "IDW 估计完成"
}

3. 储量计算

$ dimine block-reserves --block-file "D:/Data/ore_model.dmb" --constraint '{"grade_field": "Cu", "cutoff": 0.3}' --params '{"density_field": "density", "volume_factor": 1.0}'
{
  "success": true,
  "block_file": "D:/Data/ore_model.dmb",
  "message": "储量计算完成"
}

提示与技巧

  1. 管道链式操作dimine get-selected | dimine hide --ids - 是最常用的快捷操作。
  2. 文件路径:支持相对路径、绝对路径(Windows D:\\D:/ 均可),以及用户目录 ~/
  3. JSON 参数大体积时:优先使用 @path 文件引用,避免命令行长度限制。
  4. Windows CMD 单引号:JSON 参数外层用单引号包裹,CLI 内部会自动去除并解析。
  5. 错误排查:远程命令失败时先检查 dimine file-tree 是否能正常返回,确认 Dimine 已启动且 WebSocket 服务正常。