You need to enable JavaScript to run this app. Modelica模型中DynamicSelect实现动态文本显示的正确设置方法
优惠活动
大模型
产品
解决方案
定价
更多

Modelica模型中DynamicSelect实现动态文本显示的正确设置方法

Modelica DynamicSelect 动态文本不生效的修正方案

核心错误原因

  • 类型不匹配:textString 为字符串类型,原代码中 DynamicSelect 第一个参数为整数 10(非字符串),导致表达式类型校验失败,仿真器直接跳过动态逻辑。
  • 视图查看错误:Diagram 层的动态文本需在仿真动画视图中展示,静态编辑的 Diagram 页面不会渲染动态更新。

修正后的代码示例

Modelica.Blocks.Sources.Sine sine(amplitude=100, freqHz=1)
    annotation (Placement(transformation(extent={{-124,-10},{-104,10}})));
equation 
  annotation (
    Diagram(graphics={
      Text(
        extent={{-22,60},{98,10}},
        lineColor={28,108,200},
        fillColor={238,46,47},
        fillPattern=FillPattern.None,
        (* 修正:两个参数均为字符串类型,第一个为编辑时的默认文本 *)
        textString=DynamicSelect("10", String(sine.y))
      )
    }),
    (* 兼容多数仿真工具的动画视图渲染要求 *)
    Animation(graphics={
      Text(
        extent={{-22,60},{98,10}},
        lineColor={28,108,200},
        fillColor={238,46,47},
        fillPattern=FillPattern.None,
        textString=DynamicSelect("10", String(sine.y))
      )
    }),
    uses(Modelica(version="3.2.3"))
  );
end fsdaf;

关键注意事项

  • 仿真完成后,需切换到工具的动画/仿真可视化视图:如 OpenModelica 点击仿真结果页的「Animation」标签,Dymola 切换到「Simulation」视图并启用动画开关。
  • DynamicSelect 的两个参数必须类型一致(此处需统一为 String 类型),否则仿真器会静默失效。
  • 旧版本仿真工具需确认支持 Annotation 中 DynamicSelect 的动态文本渲染(Modelica 3.2+ 规范已原生支持该用法)。

内容的提问来源于stack exchange,提问作者Jack

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.07 12:06:04