用 SDK 创建和编辑模型
模型不是一组可以脱离工作台空间随意拼装的 JSON。元件类型、参数默认值、端口和全局参数都来自工作台空间定义。比较稳妥的脚本顺序是:先读取定义,再编辑 SDK 内存中的模型,校验当前草稿,最后保存。
本页沿着一条完整流程展开:
- 读取可访问的工作台空间及元件定义;
- 创建新模型,或按模型 ID 读取已有模型;
- 管理图纸,添加普通元件并设置参数;
- 根据定义中的端口 Key 建立连接;
- 按需添加线型元件和说明性连线;
- 设置全局参数;
- 校验、保存、另存并重新读取核验。
开始前应已完成 SDK 安装和认证配置,参见安装 SDK 并完成认证。
先分清工作台空间定义、模型草稿和服务器模型
SDK 同时处理三类容易混淆的数据:
| 数据 | 作用 | 何时变化 |
|---|---|---|
| 工作台空间定义 | 给出可用元件、参数、端口、指令和全局参数定义 | 由空间维护者发布;SDK 会缓存读取结果 |
当前 Model 对象 | 当前 Python 进程中的模型草稿 | 调用添加、连接、改参数、删图纸等方法时立即变化 |
| 服务器模型 | 平台中其他页面和进程能够重新读取的模型记录 | 创建模型、save()、save_as() 或 delete() 时变化 |
client.create_model(...) 会立即在服务器创建一条模型记录,并返回带服务器模型 ID 的 Model。此后调用 add_component()、connect()、set_global() 等方法,只修改当前内存对象;必须调用 save(),这些变化才会写回原模型。
client.get_model(model_id) 会读取服务器中的当前快照。读取完成后,本地对象与服务器记录不会自动双向同步:其他人保存的变化不会自行进入当前对象,当前对象的变化也不会自动上传。需要最新内容时,应重新调用 get_model()。
读取空间和元件定义
先列出当前账号可以使用的工作台空间:
workspace_items = client.meta.list_workspace_types(scope="access")
for item in workspace_items:
print(item.get("type"), item.get("name"))
选定 workspace_type 后读取空间定义和元件字典:
workspace_definition = client.meta.get_workspace_definition(
workspace_type,
refresh=True,
)
component_definitions = client.meta.list_components(workspace_type)
for class_id, definition in component_definitions.items():
print(class_id, definition.get("label"))
这里的字典键就是创建元件时使用的 class_id。不要从界面名称推测 class_id。端口也应读取 portsDefinition 中的 key,不要把端口显示名称当成 Key:
component_definition = client.meta.get_component_definition(
workspace_type,
class_id,
)
for port in component_definition.get("portsDefinition", []):
print(port.get("key"), port.get("name"), port.get("type"))
SDK 会缓存空间和元件定义。空间维护者刚发布新定义时,用 refresh=True 重新读取空间定义;随后从同一客户端取得的元件字典会使用这次刷新的内容。
创建模型或读取已有模型
创建新模型
model = client.create_model(
name="SDK 建模示例",
workspace_type=workspace_type,
description="从工作台空间定义创建",
publicity="private",
)
print(model.id)
创建时,SDK 会读取当前空间的全局参数默认值,生成一张 ID 为 sheet_0、名称为“图纸1”的默认图纸,并立即创建服务器模型。可用 global_params 覆盖部分全局默认值:
model = client.create_model(
name="SDK 建模示例",
workspace_type=workspace_type,
global_params={global_key: desired_value},
)
global_key 和值的类型仍应来自当前空间的全局参数定义。
读取已有模型
model = client.get_model(model_id)
print(model.id, model.name, model.workspace_type)
读取后先检查 model.workspace_type,避免把为另一工作台空间准备的元件类型和参数写入当前模型。需要查找模型时可以使用 client.list_models(**params);列表参数应按当前模型列表接口的公开约定传入。
管理图纸
新模型已经包含默认图纸:
main_sheet = model.default_sheet
model.rename_sheet(main_sheet, "主流程")
note_sheet = model.add_sheet("说明")
print([(sheet.id, sheet.name) for sheet in model.sheets])
常用图纸方法如下:
| 方法 | 结果 |
|---|---|
model.get_sheet(sheet_id) | 按稳定的图纸 ID 取图纸 |
model.add_sheet(name=None) | 新增图纸;不传名称时由 SDK 生成 |
model.rename_sheet(sheet_or_id, name) | 修改显示名称,不改变图纸 ID |
model.copy_sheet(sheet_or_id, name=None) | 复制图纸内容,并为副本生成新的图纸、元件和边 ID |
model.remove_sheet(sheet_or_id) | 从当前草稿删除图纸及其中内容;模型至少保留一张图纸 |
普通物理连线只能连接同一张图纸中的元件。不要用 model.connect() 强行创建跨图纸边;当前 SDK 能构造出这类本地对象,但统一校验会把它识别为无效拓扑。
如果当前工作台空间支持端口标签或信号参数,可用相同名称表达跨图纸逻辑关系。名称匹配会去除首尾空格,但区分大小写。复制图纸会保留这些名称,因此副本可能意外加入原来的逻辑网络;保存副本前应检查标签和信号参数。
添加普通元件并设置参数
使用选定元件定义的 class_id 添加普通元件:
source = main_sheet.add_component(
source_class_id,
label="入口实例",
position=(80, 120),
mode="node",
)
target = main_sheet.add_component(
target_class_id,
label="出口实例",
position=(520, 120),
mode="node",
)
mode="node" 明确要求使用普通图标形态。添加元件时,SDK 会根据该元件定义生成参数默认值,再用 params 中提供的值覆盖同名顶层参数:
source = main_sheet.add_component(
source_class_id,
params={parameter_key: desired_value},
)
默认值的生成也由定义决定:优先使用 defaultValue,其次使用 default;对象参数会递归生成已定义的子字段,显式对象默认值只覆盖这些已知子字段;没有默认值的表格参数使用空列表,其他参数使用空字符串。全局参数默认值采用同一套定义规则。
创建后也可以逐项或批量修改:
source.set_param(parameter_key, desired_value)
source.set_params(**{another_parameter_key: another_value})
print(source.get_param(parameter_key))
参数 Key 来自元件定义中各参数组的 argsDefinition[].key。set_param() 会更新本地字典,但不会自行判断 Key 是否存在、数值是否越界、表格列是否完整或对象子字段是否有效;这些规则要以统一校验结果为准。
元件定义还决定条件端口。修改控制参数后,可以用 component.active_ports 查看 SDK 本地表达式求值认为已启用的端口:
for port in source.active_ports:
print(port.key, port.name, port.type, port.direction)
这个结果适合交互式检查,不是最终合法性证据。空间定义中的表达式语法可能超过本地求值器的处理范围,最终仍应调用 model.validate()。
区分稳定标识和显示名称
自动化脚本应保存稳定标识,用显示名称帮助人阅读。图纸、元件和连线等内部 ID 只在所属模型内定位资源;记录这些 ID 时,应同时记录模型 UUID:
| 对象 | 稳定标识 | 显示名称或标签 |
|---|---|---|
| 模型 | model.id | model.name |
| 图纸 | sheet.id | sheet.name |
| 元件类型 | component.class_id | 元件定义中的 label |
| 元件实例 | component.id | component.label |
| 端口 | port.key | port.name |
连接保存的是元件实例 ID 和端口 Key,不是元件标签和端口名称。重命名图纸或修改元件 label 不应作为改变拓扑标识的手段。
save_as() 会创建新的模型 UUID,但它复制当前快照时不会重新生成图纸、元件、连线和说明性连线等内部 ID。因此,原模型与副本中可能出现相同的 sheet.id、component.id 或边 ID。跨模型保存定位信息时,必须使用“模型 UUID + 内部 ID”,不能把内部 ID 当成平台范围内的唯一标识。
连接端口
可以从 Component.ports 读取定义驱动的端口对象:
for port in source.ports:
print(port.key, port.name, port.type, port.direction, port.is_active)
建立普通物理连线时,传入元件对象和端口 Key:
connection = main_sheet.connect(
source,
source_port_key,
target,
target_port_key,
)
print(connection.id, connection.type)
SDK 根据源端口类型生成连线类型:FLUID、CONTROL、ELECTRICAL 分别对应流体、控制和电气连线。不存在的端口 Key 会立即触发 ValidationError;两端类型、方向、启用条件、连接数量以及同图纸约束,则以 model.validate() 的结果为准。
端口标签不是物理连线。当前工作台空间明确支持同名端口标签组网时,可这样设置:
source.set_pin_label(source_port_key, "network_A")
another_component.set_pin_label(another_port_key, "network_A")
不要同时把端口标签、信号参数和图上连线当成三种可互换的写法;应遵循当前空间定义所表达的连接方式。
按需添加线型元件
线型元件是元件实例,不是普通连接。SDK 仅接受恰好包含两个物理端口的元件定义。定义中的第一个端口对应 source 端,第二个端口对应 target 端;端口 Key 和连接规则仍需通过统一校验确认:
linear = main_sheet.add_linear_component(
linear_class_id,
label="中间线型元件",
source=(220, 120),
target=(420, 120),
)
linear.attach("source", source, source_port_key)
linear.attach("target", target, target_port_key)
attach() 的端点只能吸附到普通元件端口,不能吸附到另一个线型元件。端点也可以暂时释放到画布坐标:
linear.detach("source", point=(220, 120))
print(linear.endpoint("source"))
如果元件定义的默认形态是线型,add_component() 不传 mode 时也可能返回线型元件;需要明确选择时,普通形态用 mode="node",线型形态用 add_linear_component()。
将已有普通元件调用 component.linearize() 会保留实例 ID、标签和参数,但会移除与该普通元件相连的物理边;linear.delinearize() 也可能根据端点重建连接。这类转换应先在模型副本中验证,不要把它当成纯显示切换。
添加说明性连线
AnnotationEdge 用于画布说明,不进入物理拓扑。下面在“说明”图纸上添加一条点到点的说明性连线:
annotation = note_sheet.add_annotation(
{"x": 40.0, "y": 60.0},
{"x": 320.0, "y": 60.0},
attrs={
"line": {
"stroke": "#64748b",
"strokeDasharray": "6 4",
}
},
)
print(annotation.id)
说明性连线可以帮助整理图面,但不会补齐未连接的物理端口,也不会改变模型计算网络。
设置全局参数
先读取全局参数定义,再使用定义中的 Key:
global_definition = client.meta.get_global_definition(workspace_type)
print(global_definition)
model.set_global(global_key, desired_global_value)
print(model.get_global(global_key))
创建模型时已经写入当前定义给出的全局默认值。set_global() 只修改本地 global_params;未知 Key、类型错误、范围错误和参数间约束仍由统一校验判断。
校验当前草稿并理解 ValidationResult
result = model.validate()
print(result.valid, result.counts)
for issue in result.issues:
print(
issue.severity,
issue.code,
issue.message,
issue.sheet_id,
issue.element_id,
issue.parameter_key,
issue.path,
)
validate() 会把当前内存对象生成的、尚未保存的快照提交给平台统一校验器;它需要网络和有效权限,但不会保存模型。
ValidationResult 的主要字段如下:
| 字段 | 含义 |
|---|---|
valid | 当且仅当 error 数量为 0 时为 True |
counts | error、warning、info 三类问题的数量 |
issues | 不可变的问题序列,每项包含严重程度、代码、消息和定位信息 |
ValidationIssue 可能通过 sheet_id、element_id、component_class_id、parameter_key 和 path 指向具体位置。部分问题不一定具备全部定位字段,应以实际返回内容为准。warning 和 info 不会令 valid 变为 False,但发布或批量运行前仍应逐项确认。
只关心一个元件时可以使用:
component_result = source.validate()
这个方法仍会校验整个模型,只是返回时按该元件实例 ID 过滤问题;它不会比整模校验更少地访问服务器。
保存、另存并重新读取核验
保存当前模型有两种校验策略:
# 直接写回,不先做统一校验;这是默认行为。
model.save(validate=False)
# 先校验当前草稿;存在 error 时抛出 ValidationError,不执行保存。
model.save(validate=True)
推荐在自动化脚本的最终保存点使用 save(validate=True)。如果已经显式检查过 model.validate(),之后又有任何本地修改,应重新校验,不要复用旧的 ValidationResult。
另存为会创建新的服务器模型并返回另一个 Model 对象:
copied = model.save_as(
name=f"{model.name}-副本",
description="由 SDK 从已校验草稿另存",
publicity="private",
)
print(model.id, copied.id)
save_as() 没有 validate 参数。调用前应显式执行 model.validate() 并确认当前草稿没有错误。另存不会把原对象切换到新模型,也不会改变原模型 UUID;返回对象具有新的模型 UUID,但其快照沿用当前草稿中的图纸、元件和边 ID。
保存后重新从服务器读取,核验关键字段,而不是只检查 save() 没有抛异常:
assert model.id is not None
reloaded = client.get_model(model.id)
assert reloaded.workspace_type == model.workspace_type
assert reloaded.get_component(source.id).class_id == source.class_id
assert len(reloaded.sheets) == len(model.sheets)
如果模型可能被多人同时编辑,重新读取还能帮助发现当前保存结果是否符合预期。SDK 当前不会自动合并两个进程各自的本地草稿。
一条可运行的完整流程
下面的脚本不会写死某个业务工作台空间。运行前,从前面的元数据输出中选择两个可以作为普通元件使用的 class_id,通过环境变量传入。脚本会从元件定义中选择同类型、方向合适且本地判断为启用的端口 Key;如空间使用复杂条件表达式,也可以显式传入已经核对过的端口 Key。
| 环境变量 | 必需 | 说明 |
|---|---|---|
NEXUSFLOW_BASE_URL | 是 | 平台根地址 |
NEXUSFLOW_USERNAME | 是 | 用户名或完整邮箱 |
NEXUSFLOW_PASSWORD | 是 | 密码;应由安全机制注入 |
NEXUSFLOW_WORKSPACE_TYPE | 是 | 从可访问空间元数据读取的空间类型 |
NEXUSFLOW_SOURCE_CLASS_ID | 是 | 从元件字典选定的起点元件类型 |
NEXUSFLOW_TARGET_CLASS_ID | 是 | 从元件字典选定的终点元件类型 |
NEXUSFLOW_SOURCE_PORT_KEY | 否 | 已核对的起点端口 Key;与终点端口 Key 成对设置 |
NEXUSFLOW_TARGET_PORT_KEY | 否 | 已核对的终点端口 Key;与起点端口 Key 成对设置 |
NEXUSFLOW_LINEAR_CLASS_ID | 否 | 从元件字典选定的双端口线型元件;不设置时使用普通连线 |
NEXUSFLOW_PARAMETER_KEY | 否 | 要设置的起点元件参数 Key;不设置时选择定义中的第一个参数 |
NEXUSFLOW_PARAMETER_VALUE_JSON | 否 | 参数的 JSON 值;不设置时保留定义生成的默认值 |
NEXUSFLOW_GLOBAL_KEY | 否 | 要设置的全局参数 Key;不设置时选择定义中的第一个参数 |
NEXUSFLOW_GLOBAL_VALUE_JSON | 否 | 全局参数的 JSON 值;不设置时保留定义生成的默认值 |
源、目标元件和可选线型元件必须组成目标工作台空间认可的代表性最小拓扑。不同空间对必连端口和必填参数的要求不同,脚本不会猜测这些业务规则;校验失败时按问题定位补齐模型。
from __future__ import annotations
import json
import os
from typing import Any
from nexusflow_sdk import (
Component,
Model,
NexusFlowClient,
PortRef,
ValidationError,
ValidationResult,
)
def require_env(name: str) -> str:
value = os.getenv(name, "").strip()
if not value:
raise RuntimeError(f"缺少环境变量:{name}")
return value
def arg_definitions(args_group: Any) -> list[dict[str, Any]]:
definitions: list[dict[str, Any]] = []
if not isinstance(args_group, list):
return definitions
for group in args_group:
if not isinstance(group, dict):
continue
for item in group.get("argsDefinition", []) or []:
if isinstance(item, dict) and item.get("key"):
definitions.append(item)
return definitions
def configured_value(name: str, default: Any) -> Any:
raw = os.getenv(name)
return default if raw is None else json.loads(raw)
def choose_parameter(
component: Component,
definition: dict[str, Any],
) -> None:
definitions = arg_definitions(definition.get("argsGroup"))
requested = os.getenv("NEXUSFLOW_PARAMETER_KEY", "").strip()
if requested:
keys = {str(item["key"]) for item in definitions}
if requested not in keys:
raise RuntimeError(f"元件定义中没有参数 Key:{requested}")
key = requested
elif definitions:
key = str(definitions[0]["key"])
else:
print("起点元件没有可设置的顶层参数")
return
value = configured_value(
"NEXUSFLOW_PARAMETER_VALUE_JSON",
component.get_param(key),
)
component.set_param(key, value)
print(f"已设置元件参数:{key}={value!r}")
def requested_ports(
source: Component,
target: Component,
) -> tuple[PortRef, PortRef] | None:
source_key = os.getenv("NEXUSFLOW_SOURCE_PORT_KEY", "").strip()
target_key = os.getenv("NEXUSFLOW_TARGET_PORT_KEY", "").strip()
if bool(source_key) != bool(target_key):
raise RuntimeError("起点和终点端口 Key 必须同时设置")
if not source_key:
return None
return source.port(source_key), target.port(target_key)
def choose_direct_ports(
source: Component,
target: Component,
) -> tuple[PortRef, PortRef]:
explicit = requested_ports(source, target)
if explicit is not None:
return explicit
for source_port in source.active_ports:
if source_port.direction == "IN":
continue
for target_port in target.active_ports:
if target_port.direction == "OUT":
continue
if source_port.type == target_port.type:
return source_port, target_port
raise RuntimeError("没有找到本地可判断为启用的兼容端口,请显式设置端口 Key")
def choose_linear_ports(
source: Component,
target: Component,
linear_ports: list[PortRef],
) -> tuple[PortRef, PortRef]:
explicit = requested_ports(source, target)
if explicit is not None:
return explicit
if len(linear_ports) != 2:
raise RuntimeError("线型元件定义必须恰好包含两个物理端口")
for source_port in source.active_ports:
if source_port.direction == "IN" or source_port.type != linear_ports[0].type:
continue
for target_port in target.active_ports:
if target_port.direction == "OUT":
continue
if target_port.type == linear_ports[1].type:
return source_port, target_port
raise RuntimeError("没有找到与线型元件两端兼容的活动端口")
def set_global_parameter(client: NexusFlowClient, model: Model) -> None:
definitions = arg_definitions(
client.meta.get_global_definition(model.workspace_type)
)
requested = os.getenv("NEXUSFLOW_GLOBAL_KEY", "").strip()
if requested:
keys = {str(item["key"]) for item in definitions}
if requested not in keys:
raise RuntimeError(f"全局参数定义中没有 Key:{requested}")
key = requested
elif definitions:
key = str(definitions[0]["key"])
else:
print("当前空间没有可设置的全局参数")
return
value = configured_value(
"NEXUSFLOW_GLOBAL_VALUE_JSON",
model.get_global(key),
)
model.set_global(key, value)
print(f"已设置全局参数:{key}={value!r}")
def print_validation(result: ValidationResult) -> None:
print(f"校验通过:{result.valid},问题统计:{result.counts}")
for issue in result.issues:
location = issue.path or issue.element_id or issue.sheet_id or "model"
print(f"[{issue.severity}] {issue.code}: {issue.message} ({location})")
def main() -> None:
base_url = require_env("NEXUSFLOW_BASE_URL")
username = require_env("NEXUSFLOW_USERNAME")
password = require_env("NEXUSFLOW_PASSWORD")
workspace_type = require_env("NEXUSFLOW_WORKSPACE_TYPE")
source_class_id = require_env("NEXUSFLOW_SOURCE_CLASS_ID")
target_class_id = require_env("NEXUSFLOW_TARGET_CLASS_ID")
linear_class_id = os.getenv("NEXUSFLOW_LINEAR_CLASS_ID", "").strip()
with NexusFlowClient(base_url=base_url, timeout=30) as client:
client.login(username, password)
accessible = {
str(item["type"])
for item in client.meta.list_workspace_types(scope="access")
if isinstance(item, dict) and item.get("type")
}
if workspace_type not in accessible:
raise RuntimeError(f"当前账号不能访问工作台空间:{workspace_type}")
component_definitions = client.meta.list_components(
workspace_type,
refresh=True,
)
required_classes = {source_class_id, target_class_id}
if linear_class_id:
required_classes.add(linear_class_id)
missing = required_classes.difference(component_definitions)
if missing:
raise RuntimeError(f"空间定义中没有元件类型:{sorted(missing)}")
# 这一步立即创建服务器模型,随后编辑仍只发生在内存对象中。
model = client.create_model(
name="SDK 建模示例",
workspace_type=workspace_type,
description="由 SDK 从当前空间定义创建",
publicity="private",
)
assert model.id is not None
print(f"已创建模型:{model.name} ({model.id})")
main_sheet = model.rename_sheet(model.default_sheet, "主流程")
note_sheet = model.add_sheet("说明")
source = main_sheet.add_component(
source_class_id,
label="入口实例",
position=(80, 120),
mode="node",
)
target = main_sheet.add_component(
target_class_id,
label="出口实例",
position=(520, 120),
mode="node",
)
choose_parameter(source, component_definitions[source_class_id])
if linear_class_id:
linear = main_sheet.add_linear_component(
linear_class_id,
label="中间线型元件",
source=(220, 120),
target=(420, 120),
)
source_port, target_port = choose_linear_ports(
source,
target,
linear.ports,
)
linear.attach("source", source, source_port.key)
linear.attach("target", target, target_port.key)
print(f"已添加线型元件:{linear.id}")
else:
source_port, target_port = choose_direct_ports(source, target)
connection = main_sheet.connect(
source,
source_port.key,
target,
target_port.key,
)
print(f"已添加物理连线:{connection.id} ({connection.type})")
note_sheet.add_annotation(
{"x": 40.0, "y": 60.0},
{"x": 320.0, "y": 60.0},
attrs={
"line": {
"stroke": "#64748b",
"strokeDasharray": "6 4",
}
},
)
set_global_parameter(client, model)
# 校验的是当前未保存草稿;校验不会修改服务器模型。
validation = model.validate()
print_validation(validation)
if not validation.valid:
raise ValidationError("当前模型仍有校验错误,未执行保存")
# 最终写回前再次校验,避免在上一次校验后遗漏本地改动。
model.save(validate=True)
reloaded = client.get_model(model.id)
assert reloaded.workspace_type == workspace_type
assert reloaded.get_component(source.id).class_id == source.class_id
assert len(reloaded.sheets) == len(model.sheets)
print(f"已重新读取并核验原模型:{reloaded.id}")
# save_as() 没有 validate 参数;当前草稿已校验且保存后未再修改。
copied = model.save_as(
name=f"{model.name}-副本",
description="由 SDK 从已校验模型另存",
publicity="private",
)
assert copied.id is not None and copied.id != model.id
copied_reloaded = client.get_model(copied.id)
assert copied_reloaded.workspace_type == workspace_type
print(f"已另存并核验副本:{copied_reloaded.id}")
if __name__ == "__main__":
main()
第一次运行如果校验失败,不要跳过校验直接保存为“可运行模型”。先根据 ValidationIssue 补齐必连端口、必填参数和全局参数。示例会创建原模型和一个副本,但不会自动删除它们;确认测试完成后再按团队的数据保留规则处理。
删除和结构变更的风险
以下方法都会先改变当前草稿,随后在 save() 时写入原模型:
model.remove_component(component_id)会删除元件,移除与其相连的普通物理边和以它为锚点的说明性连线;其他线型元件吸附到它的端点会被释放到坐标;model.disconnect(connection_id)会删除普通物理连线;model.remove_annotation(annotation_id)会删除说明性连线;model.remove_sheet(sheet_or_id)会删除该图纸中的元件、物理连线和说明性连线;component.linearize()会移除该普通元件原有的物理连线。
这些方法对不存在的部分 ID 可能直接返回,不应把“没有抛异常”当成确实删除了目标。保存前先检查 model.components、model.connections、model.annotations 和各图纸内容,并再次校验。
model.delete() 不属于本地编辑:对于带服务器 ID 的模型,它会立即请求删除服务器模型,不需要再调用 save()。删除后 Python 对象仍可能留在内存中,但这不表示服务器记录仍存在。自动化脚本不应把删除放在宽泛的异常清理逻辑中;应核对模型 ID、名称、所属空间、使用者和恢复准备后再执行。
常见问题
修改参数后,页面为什么看不到
set_param() 只改当前 Model 对象。调用 model.save() 后,再从页面或另一个 SDK 客户端重新读取。
active_ports 显示端口启用,为什么校验仍失败
active_ports 是本地尽力求值结果。统一校验还会检查表达式、端口类型、方向、连接数量、跨图纸关系和其他空间规则,应以 model.validate() 返回为准。
save() 成功是否表示模型可运行
不一定。save() 默认参数是 validate=False,只证明保存请求成功。使用 save(validate=True) 可以阻止含有校验错误的草稿写回,但能否完成实际计算仍要由任务运行证明。
为什么另存后原对象的 ID 没变
save_as() 返回的是具有新模型 UUID 的 Model,原对象继续代表原模型。请保存返回值,并用返回对象的 id 操作副本。副本内部的图纸、元件和边 ID 不会因此重新生成,定位其中资源时仍应同时携带副本的模型 UUID。
能否连接不同图纸中的两个元件
不能用普通物理边直接连接。需要跨图纸表达关系时,只能使用当前工作台空间已经定义并支持的端口标签或信号参数,并通过统一校验确认。
下一步
模型保存并重新读取核验后,再按照运行任务与读取结果创建仿真任务。本页不展开任务快照、状态控制和结果消费。