Professional Documents
Culture Documents
王元
AVEVA中国
2004.7.19
q PML介绍 q 您会具有以下知识 …
– PML概念
– PML构成及功能
– PML功能
– PML构成 – 编写简单的宏
q PML程序语言 – PML变量的定义及应用
– 变量的定义及用法 – PML函数/方法的定义及调用
– 循环Do、判断If、跳转Golabel
– PML窗体/对象的定义及调用
– 错误处理
– 文件处理
– 函数Functions、方法Method
– 对话框Forms和菜单Menu
1
1
一个简单的 Macro 参数化宏 Parameterized Macro
一个简单的 Macro ,继续,
q 宏是包含PDMS 命令序列的一个文本文件 q 宏可以参数化
ASCII 文件
ASCII 文件 NEW EQUIP /$1
MYFILE
MYFILE NEW EQUIP /FRED NEW BOX
NEW BOX XLEN $2 YLEN $3 ZLEN $4
XLEN 300 YLEN 400 ZLEN 600 NEW CYL DIA $3 HEI $4
NEW CYL DIA 400 HEI 600 CONN P1 TO P2 OF PREV
CONN P1 TO P2 OF PREV
? 文件名后面的字符串是参数(parameters)
? 运行宏
$M /MyFile NEWEQUIP 300 400 600
$M /MyFile
宏的参数 变量Variables
2
2
变量命名规则 (Naming Conventions) PDMS属性类型-系统定义变量类型
变量提取属性 变量给PDMS属性赋值
练习-变量给属性赋值 方法(Method)和函数(Function)
q 新建Pipe,设置下列属性 q 函数(Function)是执行特定功能的子程序
New Pipe
Desc 'My Description' q 方法(Method)是对象(变量)的函数
Temp 100 – 在PML2中变量是一个对象(Objects)
Pspec /A3B •每一个对象(变量)有一个唯一的名字
Purp PIPI
•每一个对象都有一套函数与之相关联,这些函数称为方法
q 从Pipe提取属性 (Methods).方法用于处理对象中的数据
– Desc
•生成对象时必须指明对象类型(Object type), 不同的对
– Temp
象类型对应不同的方法
– Pspec
– Purp – 方法并不改变对象的类型和对象中的值
q 新建Pipe,相应属性与前一个Pipe一样 q 参考手册Cadcentre Software Customisation
New Pipe Reference Manual
3
3
方法-字符串对象(String Object) 方法实例
PML表达式 表达式说明
q 开方 Sqrt()
q 函数定义成全局变量
q 乘方 Power(REAL) define function !!Area( !Length is REAL, !Width is REAL ) is REAL
!Area = !Length * !Width
q 取整 INT()
return !Area $*函数!!Area有两个参数一个返回值
Endfunction
q 文件命名和存放位置
Pmllib/NewPml
4
4
函数调用 PML通用功能-注释
q 打印 q 四种逻辑控制结构
$P This text will be output to the screen. – 条件判断语句 If… else… endif
q 换行 – 循环语句 Do … enddo
$P This is an example of a much longer message $ – 跳转 Label Golabel
that will be output to the screen
– 错误处理 Handle
q 退出程序
if ( count EQ 0 ) then
return
endif
q 判断表达式中必须是布尔值 q 判断变量值是否存在
!Type = Type !x =real()
!OwnType = Type of Owner
IF (!Type eq 'BRAN') THEN 用函数判断 用方法判断
$P CE is Branch. If(Unset(!x)) then… if(!x.Unset()) then…
ELSEIF (!OwnType eq 'BRAN') THEN If(Set(!x)) then… if(!x.Set()) then…
$P CE is Branch member. q 判断布尔值
ELSE
!MyString = 'True'
$P CE is $! Type,Pls select Branch.
ENDIF If(!MyString.Boolean()) then
…
q Elseif,else 都是可选项
5
5
判断元素是否有名字 练习-条件判断
q 判断元素是否有名字 q 判断当前元素类型(Type),添加当前元素和与之
!Name = Name
!FullName = FullName 连接的元素
If(!Name EQ ! FullName) then – 如果是'BRAN',add Href和add Tref
$p Named.
– 如果是'NOZZ',add Cref
Else
$p No name. – 打印当前元素类型
Endif
q 进一步判断
– NAMe Text(120) ALL Name of element (see NAMN)
– NAMEDb Text SYST DB name – 打印加入的元素个数
– NAMESQ Text(120) ALL Type, sequence number and name of
element
– NAMETY Text(120) ALL Type and name of element
– NAMN Text(120) ALL Name of element without leading slash
(see
– NAME)
跳转(Jump) 练习-跳转
q 用golabel可以跳转到标记行,不限制前后顺序 q 添加Nozzle连接的Branch的头尾连接元素
Label /Start
…
GoLabel /Start
q Label名最长 16 个字符,不包括'/'
q 不允许跳转到Do循环中
golabel /illegal
!Total = 0
do !x from 1 to 5
!Total = !Total + !x
label /illegal
enddo
6
6
错误提示 错误处理 (Error Handling)
q 测试程序 q 处理特定错误,使程序继续执行
Next Next
$p OK Handle (2,113)
q 可能出现的错误 $p Last element.
(2,113) List exhausted EndHandle
2 表示错误出现在PDMS中的哪个模块 $p OK
113 是错误代码 q 处理任何可能的错误
q 出现错误通常有三种结果 Next
– 出现一个警告框,用户必须确认 Handle Any
– 输出一个错误信息 EndHandle
– 从当前运行的程序中退出 $p OK
处理多个错误 数组(Array)
q 处理多个错误 q 从字符串创建数组
!Str = 'Benz,Bmw,Audi'
Next
!BestCar = !Str.Split(',')
Handle (2,113) Q var !BestCar
$p Last element. <ARRAY>
ElseHandle (2,46) [1] <STRING> 'Benz'
$p … [2] <STRING> 'Bmw'
EndHandle [3] <STRING> 'Audi' $* 数组元素,索引号
q 逐个元素添加
$p OK
!BestCar[5] = 'Cadillac'
q 数组追加
!BestCar.Append('Lincoln') $* 数组必须存在,否则提前声明
7
7
数组高级排序 VAR … SORT…
q 三个数组 q 产生新的索引数组
– !Car !Colour !Year VAR !Index SORT !Car CIASCII ! Colour !Year NUMERIC
[1] CHARIOT MUD 1926 !Index
[2] FORD RED 1978 [1] 1 CHARIOT MUD 1926
[3] VAUXHALL YELLOW 1990 [2] 7 ford GREEN (Unset)
[4] FORD YELLOW 1993 [3] 2 FORD RED 1978
[5] FORD (Unset) 1986 [4] 4 FORD YELLOW 1993
[6] (Unset) BLUE 1993 [5] 10 FORD YELLOW 1993
[7] ford GREEN (Unset) [6] 5 FORD (Unset) 1986
[8] (Unset) (Unset) (Unset) [7] 3 VAUXHALL YELLOW 1990
[9] vauxhall YELLOW 1994 [8] 9 vauxhall YELLOW 1994
[10] FORD YELLOW 1993 [9] 6 (Unset) BLUE 1993
[10] 8 (Unset) (Unset) (Unset)
排序选项 记录数组中的相同项
q 合并同类项 q 指定类型
VAR !Totals SUBTOTAL !Values !Index !Group
Var !PipeComps Collect all Branch members For CE
!Index !Group !Car !Value !Totals
生成的!PipeComps是数组,保存的是元素的参考号
[1] 1 1 CHARIOT 50000 50000
[2] 2 FORD 1000 不使用For CE则是从整个MDB 中提取
[3] 4 FORD 100 q 类型用法示例
[4] 5 FORD 8000 ALL 所有元素
[5] 10 2 FORD 7000 16100
ALL Pipe 所有的Pipe
[6] 3 3 VAUXHALL 2000 2000
[7] 7 4 ford 1000 1000 BRANCH MEMBERS 所有管件,不包括Tube
[8] 9 5 vauxhall 3000 3000 ALL BRANCH MEMBERS 所有管件,包括Tube
[9] 6 (Unset) 9000 ITEMS OF EQUI /D1201 设备中的所有基本体
[10] 8 6 (Unset) 6000 15000
8
8
继续… 求值(Evaluate)
q 限制条件 q 从参考中提取属性值
Var !Elbows Coll All Elbow With (Abor gt 100) for CE q 管道排序
With后面是一个表达式 Var !Pipes Coll all Pipe for ce $*提取参考号
q 限制区域 Var !Names Eval name for all from !Pipes $*提取属性值
Var !Elbows Coll All Elbow Within W0N0U0 to !Names.sort().invert()
W2000N2000U2000 Do !n indices !Names
Var !Elbows Coll All Elbow Exclusive Within Volume
/D1201 1500 reorder $!names[$!n] before $!n
Exclusive表示完全包含在空间内的元素才被选中 EndDo
q 追加 q 练习-选择一个设备,将所有 Nozzle连接的管道添加进
Var !Elbows Append Coll all Bend for CE 来
9
9
显示输出窗口 一个简单的对话框 (Form)
!shown = !!CADCBTH.shown ()
q 对话框是全局变量的对象
if(not !shown) then setup form !!hello
show !!CADCBTH Title 'Hello'
endif paragraph .Message text 'Hello world'
var !date clock date button .bye 'Goodbye' OK
exit
var !time clock time
$p Begin report at $!date $!time q 控件(Gadget)
Paragraph .Message文字控件和控件名
Button .bye 按钮控件和控件名
q 对话框控制属性 OK
内置属性,关闭对话框
对话框调用 控件的响应操作(Callbacks)
q 对话框存放位置 q 控件的callback成员用于指定控件的响应操作
Pmllib/NewPml
q 控件的响应可以是如下的操作
– 显示另一个对话框 form
functions forms objects
area.pmlfnc Hello.pmlfrm xxx.pmlobj !this.show.Callback= 'show !!hello'
文件名与对象名一样,后缀是小写的 pmlfrm – 直接执行一条命令command
q 将新建对话框加到索引文件Pml.index中,在命令行键入 !this.remove.Callback= 'remove all'
Pml Rehash All
– 调用一个函数function
q 显示对话框 !this.area.Callback= '!area = !!area(!length,!width)'
Show !!hello
– 调用一个方法method
q 关闭对话框 !this.apply.Callback= '!this.Apply ()'
Hide !!hello
q 增加一个输入框和方法 q 缺省构造方法
setup form !!hello
Title 'Hello' – 与Form 同名,不带参数
paragraph .Message text 'Hello world' – 在调用对话框的时候自动执行
text .input 'Enter text' width 10 is string $*字符串类型的编辑框 – 一般用于设置控件的缺省值和回调方法
button .bye 'Goodbye' OK
– 再一次显示对话框时,缺省构造方法不再执行,因为对
exit
话框的定义内容已经全部加载到内存中,
Define method .hello() $*缺省构造方法,与Form同名,不带参数
!this.input.callback= '!this.doinput()' $*Callback指明响应操作 – Kill !!hello从内存中清除已经加载的定义内容
endmethod q 重新调用对话框
Define method .doinput() $*响应操作
!this.message.val = ! this.input.val $*! this = !!hello, val 表示 value – 对话框的定义文件被修改后,需要重新加载
endmethod Pml reload form !!hello
10
10
对话框布局( Form Layout) 控件定位
q 对话框有一个隐含的定位网格,原点在Form的左 q 自动定位(Auto-placement)
上角 – PATH Down 下一个控件在前一个控件的下方
– PATH up, PATH Right(缺省), PATH Left
q 相对前一个控件定位(Relative)
setup form !!hello
Title 'Hello'
paragraph .Message text 'Hello world'
text .input 'Enter text' at x0 ymax width 10 is string
q 每个控件( Gadget) 有四个隐含变量可以用于参考 button .bye 'Goodbye' at x0 ymaxOK
定位 exit
控件自动定位举例 新的PML程序
q 添加指定空间内的设计元素
q 程序中用到的命令
Var !Comps Append Coll All pipe Within Volume /D1201
1500
q 文本框Paragraph,对于Paragraph,at必须在text前面 q 按钮Button
paragraph .cename at x0 ymaxtext 'No name' width 20 height 1 button .ce 'CE' at x0 ymaxtooltip'Select pipe'
button .ok 'OK' at x0 ymax OK $*关闭对话框 ,保留控件值
q 编辑框Text button .apply 'Apply' at x0 ymaxApply $*不关闭对话框
text .input 'Enter text' at x0 ymax width 10 is string button .cancel 'Cancel' at x0 ymaxCancel $*关闭对话框 ,不保留控件值
q 多选框Toggle q 图标按钮,png图像文件必须在Pmllib搜索路径内
toggle .bran 'Branch' !icon = !!pml.getpathname('modmodeon16.png')
toggle .equi 'Equipment' button .pick pixmap /$!icon at x0 ymax
q 框架Frame q 列表框List
Frame .frame1 'Include' at x0 ymax+ 0.2 list .list 'Drawlist' at x0 ymax width 18 height 5
toggle .bran 'Branch' q 练习-组合上述控件,生成新的对话框!!Addvolumn,比较
toggle .equi 'Equipment' Ok,Cancel的不同
Exit
11
11
设置控件初始值 按钮的应用实例
q 缺省构造方法设置控件初始值
q 新建方法,将当前元素的名字显示在文本框中
define method .addvolumn() define method .ce()
!this.bran.val = true
!this.cename.val = fullname
!this.input.val = '1500'
endmethod
endmethod
q 在缺省构造方法中指定控件的响应操作
define method .addvolumn()
…
!this.ce.callback = '!this.ce()'
endmethod
对话框控制属性-Apply 多选框状态判断
q 新建方法,调用控件的值
q 多选框(toggle)的状态通过.val 成员判断
define method .apply()
!dist = ! this.input.val !this.bran.val = true $*表示选中
!name = ! this.cename.val
$p CE is $!name ,Dist = $!dist
endmethod
q 在缺省构造方法中指定Apply按钮的响应操作
define method . addvolumn()
…
!this.apply.callback = '!this.apply()' $*不关闭对话框
endmethod
多选框的应用实例 列表框应用实例
12
12
控件的内置方法 View控件
q 控件的内置方法(Method)和成员(Member) q 四种View 控件
– 变灰一个控件
!this.apply.Active = FALSE – 输入输出显示窗口Alpha view
– 聚焦控件 – Plot图片显示窗口 Plot view
!this.input.SetFocus()
– 编辑框只读 – Design显示窗口 Volume view
!this.input.seteditable(false) – Draft显示窗口 Area View
– 清除列表框的值
!this.list.clear()
– 改变按钮上的文字
!this.apply.tag = ' Add '
– 改变按钮的背景颜色
!this.apply.backgroud = 2
q 自定义输入输出对话框 q 显示Plot图片
q Design的显示窗口 q 读写文件需要使用FILE对象
setup form !!poptest !Input = object FILE('%pdmsexe%\abc.txt')
view .vol volume width 50 hei 9 !Lines = ! Input.ReadFile() $* ReadFile将文件内容写到字符串数组中
exit !ResultArray = ARRAY() $* 声明新数组
path down do !Line VALUES !Lines
button .press 'swap popup' call '!this.popswap()' !Column1 = !Line.Part(1)
menu .popmenu !ResultArray.Append( !Column1)
add 'hello' ' ' Enddo
add 'world' ' ' !Output = object FILE('%pdmsexe% \def.txt')
exit
!Output.WriteFile('WRITE', ! ResultArray) $* WriteFile将数组写到文件
exit
define method . popswap() q ReadFile()方法可以自动打开(Open)和关闭(Close)文件
!this.vol.popup = ! this.popmenu q 写文件还有覆盖模式'OVERWRITE'和追加模式'APPEND'
endmethod
13
13
选择文件的标准函数 实例应用
q 函数定义 q 调用标准函数
define function setup form !!findfile
!!fileBrowser(!directory is STRING, title 'Find file'
!seedFile is STRING, text .filename 'File name' at x1 ymax+0.3 width 35 is string
!title is STRING, button .browser 'Brower'
!existFlag is BOOLEAN, button .ok ' OK ' at x1 ymax+0.3 OK
!callback is STRING) button .cancel 'Cancel' at x10 cancel
q 使用实例 exit
!!filebrowser('%pdmsuser %','*', define method . findfile()
'Text File',true, !this.browser.callback =
|!!filebrowser('%pdmsuser %','*','',true,'!!findfile.filename.val
'!filename = !!filebrowser.file.name()
= !! filebrowser.file.name()')|
q var !filename')
endmethod
练习-文件处理 菜单条
q 将一个文本文件的内容显示在命令行中 q 以Design菜单为例
..\AVEVA\Pdms11.5\pdmsui\DES\GEN\FSYSTEM
q 设计对话框自动执行宏程序
q 菜单条Bar
bar
add |Design| _sysDes
add |Display| _ sysView
add |Query| _sysQry
add |Settings| _sysSet
add |Utilities| _sysUtil
$M /%PDMSUI%/DES/GEN/USER BAR $*调用自定义菜单
handle ANY
endhandle
add |Create| _sysCrt
add |Modify| _sysMod
菜单项 自定义Design菜单
q 菜单项Menu q 生成自定义菜单文件
menu _sysView ..\AVEVA\Pdms11.5\pdmsui\DES\GEN\USER
add |Graphical View| '!!gphViews.addDesign()' q 文件内容示例
golabel /$1
add |View Control...| 'show !!gphControl'
Return
add |Plot View...| form !!plotView
add sep label /BAR
add |Browser...| |EXPLORER SHOW| add |User| _UserTools $* 定义菜单条标题
add |Members...| |CALLIB UFORMS MEMB _CDCMEMBER FREE| return
add |Advanced Members...| |CALLIB UFORMS MEMB
_CDCADVMEMBER FREE| label /MENU
menu _UserTools
add | Drawlist...| |CALLIB UFORMS MEMB _CDADDREM FREE|
add |Sort Pipe...| |show !!pipeorder | $* 定义菜单项
add sep exit
add |Command Line...| |show _cadcBth free| Return
14
14
自定义Draft菜单 自定义Catview菜单
q 生成自定义菜单文件 q 生成自定义菜单文件
..\AVEVA\Pdms11.5\pdmsui \DRA\GEN\USER ..\AVEVA\Catview11.3\CAT\GEN\USER
q 文件内容示例 q 文件内容示例
golabel /$1 golabel /$1
Return Return
15
15