WinCC画面图层的显示和隐藏
发布时间:2024-11-05
如何将整个画面作为对象画面中图层号和脚本中索引值的关系画面图层随机显示条目描述软件版本wincc7.5 SP1创建项目打开wincc 7.5 Advance软件,创建对应的项目,项目名称为LayerVisible。创建变量.先创建变量组Function,然后创建两个变量(红色框框),其他变量为其他画面用到的,不用于此项目画面。创建画面,画面名称为Layer01,切记此画面名称,后面创建画面对象时,需要用到。按钮列表对象对象名称数量描述图形对象控件默认1显示图片静态文本默认2显示画面名称和图层颜色介绍按钮默认9控制图层的隐藏/显示矩形默认66个矩形处于画面的6个图层,通过颜色区分按钮描述按钮名称作用图层1点击此按钮,隐藏其他五个矩形,只显示红色矩形图层2点击此按钮,隐藏其他五个矩形,只显示蓝色矩形图层3点击此按钮,隐藏其他五个矩形,只显示黄色矩形图层4点击此按钮,隐藏其他五个矩形,只显示绿色矩形图层5点击此按钮,隐藏其他五个矩形,只显示紫色矩形图层6点击此按钮,隐藏其他五个矩形,只显示白色矩形红绿黄点击此按钮,隐藏其他三个矩形,显示红绿黄三个颜色的矩形蓝白紫点击此按钮,隐藏其他三个矩形,只显示蓝白紫三个颜色的矩形随机点击此按钮,隐藏其他五个矩形,显示一个随机颜色的矩形按钮脚本图层1Dim SobjDim VisibleOnSet Sobj = hmiruntime.Screens("Layer01") '获取画面对象,Set VisibleOn = HMIRuntime.Tags("VisibleOn") '获取变量VisibleOn.Write 1 '变量值写1If VisibleOn.Value = 1 Then '逻辑判断 Sobj.Layers(1).visible = True '显示图层0 Sobj.Layers(2).visible = False '隐藏图层1 Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElse Sobj.Layers(1).visible = FalseEnd If 图层2Dim SobjDim VisibleOnSet Sobj = hmiruntime.Screens("Layer01")Set VisibleOn = HMIRuntime.Tags("VisibleOn")VisibleOn.Write 2If VisibleOn.Value = 2 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = True Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElse Sobj.Layers(2).visible = FalseEnd If 图层3Dim SobjDim VisibleOnSet Sobj = hmiruntime.Screens("Layer01")Set VisibleOn = HMIRuntime.Tags("VisibleOn")VisibleOn.Write 3If VisibleOn.Value = 3 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = True Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElse Sobj.Layers(3).visible = FalseEnd If图层4Dim SobjDim VisibleOnSet Sobj = hmiruntime.Screens("Layer01")Set VisibleOn = HMIRuntime.Tags("VisibleOn")VisibleOn.Write 4If VisibleOn.Value = 4 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = True Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElse Sobj.Layers(4).visible = FalseEnd If图层5Dim SobjDim VisibleOnSet Sobj = hmiruntime.Screens("Layer01")Set VisibleOn = HMIRuntime.Tags("VisibleOn")VisibleOn.Write 5If VisibleOn.Value = 5 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = True Sobj.Layers(6).visible = FalseElse Sobj.Layers(5).visible = FalseEnd If图层6Dim SobjDim VisibleOnSet Sobj = hmiruntime.Screens("Layer01")Set VisibleOn = HMIRuntime.Tags("VisibleOn")VisibleOn.Write 6If VisibleOn.Value = 6 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = TrueElse Sobj.Layers(6).visible = FalseEnd If红绿黄Dim SobjDim VisibleOnSet Sobj = hmiruntime.Screens("Layer01")Set VisibleOn = HMIRuntime.Tags("VisibleOn")VisibleOn.Write 7If VisibleOn.Value = 7 Then Sobj.Layers(1).visible = True Sobj.Layers(2).visible = False Sobj.Layers(3).visible = True Sobj.Layers(4).visible = True Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElse Sobj.Layers(1).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = FalseEnd If蓝白紫Dim SobjDim VisibleOnSet Sobj = hmiruntime.Screens("Layer01")Set VisibleOn = HMIRuntime.Tags("VisibleOn")VisibleOn.Write 8If VisibleOn.Value = 8 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = True Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = True Sobj.Layers(6).visible = TrueElse Sobj.Layers(2).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseEnd If随机Dim SobjSet Sobj = HMIRuntime.Screens("Layer01")HMIRuntime.Tags("ColorNumber").Write MyRnd(1,6)Msgbox HMIRuntime.Tags("ColorNumber").ReadIf HMIRuntime.Tags("ColorNumber").Read = 1 Then Sobj.Layers(1).visible = True Sobj.Layers(2).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElseif HMIRuntime.Tags("ColorNumber").Read = 2 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = True Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElseif HMIRuntime.Tags("ColorNumber").Read = 3 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = True Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElseif HMIRuntime.Tags("ColorNumber").Read = 4 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = True Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseElseif HMIRuntime.Tags("ColorNumber").Read = 5 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = True Sobj.Layers(6).visible = FalseElseif HMIRuntime.Tags("ColorNumber").Read = 6 Then Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = True Else Sobj.Layers(1).visible = False Sobj.Layers(2).visible = False Sobj.Layers(3).visible = False Sobj.Layers(4).visible = False Sobj.Layers(5).visible = False Sobj.Layers(6).visible = FalseEnd If在使用随机按钮时,需要先创建项目函数MyRnd(min,max),此函数会出现一个随机函数,min代表随机数的下限,max为上限,产生的随机数为int型。
展开全文
其他新闻
- 用SCL语言设计一键启停功能块, 2024-11-05
- S7-200 SMART如何清除带密码的CPU的内容 2024-11-05
- 博途软件S7-1200 利用“在运行模式下下载”功能 2024-11-05
- 6种S7-200PLCZui基础的编程实例图 2024-11-05
- WinCC过程画面的基本配置 2024-11-05
- S7-200 SMART 编程软件符号表的使用方法 2024-11-05
- 触摸屏与PLC时间同步的简单方法 2024-11-05
- 西门子PLC博途TRACE功能 2024-11-05
- 西门子PLC自由口通讯+中断 2024-11-05
- 新手必读|西门子PLC入门级必学案例 2024-11-05