PML基础练习 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

PML 基础练习

一个简单的 Macro

NEW EQUIP /FRED


NEW BOX
XLEN 300 YLEN 400 ZLEN 600
NEW CYL DIA 400 HEI 600
CONN P1 TO P2 OF PREV

参数化宏 Parameterized Macro


NEW EQUIP /$1
NEW BOX
XLEN $2 YLEN $3 ZLEN $4
NEW CYL DIA $3 HEI $4
CONN P1 TO P2 OF PREV

变量给属性赋值

New Pipe
Desc 'My Description'
Temp 100
Pspec /A3B
Purp PIPI

!desc = desc
!temp = temp
!pspec = pspec
!purp = purp

New Pipe
Desc '$!desc'
Temp $!temp
!pspec $!pspec
!purp $!purp

字符串方法实例

!line = 'hello how are you'


!newline = !line.after('hello').trim().upcase()
q var !newline
!newline = !newline.replace('how', 'where').replace('you', 'you?')

2007-6-5 1-12
PML 基础练习

定义函数

define function !!Area( !Length is REAL, !Width is REAL ) is REAL


!Area = !Length * !Width

return !Area $*函数!!Area 有两个参数一个返回值

Endfunction

练习-新建函数计算园的面积,测试函数
define function !!circleArea( !radius is REAL) is REAL
!Area = PI * pow(!radius,2)
return !Area
Endfunction

条件判断语句(If Construct)

!Type = Type
!OwnType = Type of Owner
IF (!Type eq 'BRAN') THEN
$P CE is Branch.
ELSEIF (!OwnType eq 'BRAN') THEN
$P CE is Branch member.
ELSE
$P CE is $!Type,Pls select Branch.
ENDIF

练习-条件判断

!n = 0
!type = type
if(!type eq 'BRAN') then
!href = href
!tref = tref
if(!href.set()) then
!n = !n + 1
add href
endif
if(!tref.set()) then
!n = !n + 1
add tref
endif

2007-6-5 2-12
PML 基础练习

endif
if(!type eq 'NOZZ') then
!cref = cref
if(!cref.set()) then
!n = !n + 1
add cref
endif
endif
$p Total $!n reference

循环赋值

!Total = 0
Do !x From 1 To 100 By 1
!Total = !Total + !x
Enddo

中断循环 Break

!Total = 0
Do !x From 1 To 100
!Total = !Total + !x
If(!Total gt 500) then

Break $*或者 Break if(!Total gt 500)

Endif
Enddo

用 skip 跳过奇数

Do !x From 1 To 100
If(Int(!x / 2) NE (!x / 2)) then

Skip $*或者 Skip If(Int(!x / 2) NE (!x / 2))

Endif
!Total = !Total + !x
Enddo

练习-跳转

!n = 0
label /start

2007-6-5 3-12
PML 基础练习

!type = type
if(!type eq 'BRAN') then
!href = href
!tref = tref
if(!href.set()) then
!n = !n + 1
add href
endif
if(!tref.set()) then
!n = !n + 1
add tref
endif
endif
if(!type eq 'NOZZ') then
!cref = cref
if(!cref.set()) then
!n = !n + 1
add cref
goto cref
golabel /start
endif
endif
$p Total $!n reference

错误提示

Next
$p OK

错误处理(Error Handling)

Next
Handle (2,113)
$p Last element.
EndHandle
$p OK

数组(Array)

!Str = 'Benz,Bmw,Audi'
!BestCar = !Str.Split(',')
Q var ! BestCar

2007-6-5 4-12
PML 基础练习

!BestCar[4] = 'Cadillac'
!BestCar.Append('Lincoln')

赋值循环 Do value

do !Name values !BestCar


$p Array element is $!Name
Enddo

索引循环 Do indices

do !n indices !BestCar
!Car = !BestCar[!n]
$p Array element $!n is $!Car
Enddo

管道排序

Var !Pipes Coll all Pipe for ce


Var !Names Eval name for all from !Pipes
!Name.sort().invert()
Do !n indices !Names
reorder $!names[$!n] before $!n
EndDo

练习-选择一个设备,将所有 Nozzle 连接的管道添加进来

Var !nozzles Coll all nozzle for ce


Do !nozzle value !nozzles
Add cref of $!nozzle
EndDo

文件处理(Handling Files)

!Input = object FILE('%pdmsexe%abc.txt')

!Lines = !Input.ReadFile() $* ReadFile 将文件内容写到字符串数组中

!ResultArray = ARRAY() $* 声明新数组

do !Line VALUES !Lines


!Column1 = !Line.Part(1)

2007-6-5 5-12
PML 基础练习

!ResultArray.Append( !Column1)
Enddo
!Output = object FILE('%pdmsexe%def.txt')

!Output.WriteFile('WRITE', !ResultArray) $* WriteFile 将数组写到文件

练习-文件处理

!Input = object FILE('%pdmsexe%abc.txt')


!Lines = !Input.ReadFile()
do !Line VALUES !Lines
$p $!line
Enddo

显示输出窗口

var !isshown form _CADCBTH display


if(!isshown eq 'Off') then
show _CADCREQ
endif
var !date clock date
var !time clock time
$p Begin report at $!date $!time

一个简单的对话框(Form)

setup form !!hello


Title 'Hello'
paragraph .Message text 'Hello world'
button .bye 'Goodbye' OK
exit

缺省构造方法(Constructor method)

setup form !!hello


Title 'Hello'
paragraph .Message text 'Hello world'

text .input 'Enter text' width 10 is string $*字符串类型的编辑框

2007-6-5 6-12
PML 基础练习

button .bye 'Goodbye' OK


exit

Define method .hello() $*缺省构造方法,与 Form 同名,不带参数

!this.input.callback = ‘!this.doinput()’ $*Callback 指明响应操作

endmethod

Define method .doinput() $*响应操作

!this.message.val = !this.input.val $*!this = !!hello, val 表示 value

endmethod

控件定位

setup form !!hello


Title 'Hello'
paragraph .Message text 'Hello world'
text .input 'Enter text' at x0 ymax width 10 is string
button .bye 'Goodbye' at x0 ymax OK
exit

控件定义

setup form !!addvolumn


title 'Add volumn'
button .ce 'CE' at x0 ymax tooltip 'Select pipe'
paragraph .cename text 'no name' width 15
text .input 'Enter text' at x0 ymax width 10 is string
Frame .frame1 'Include' at x0 ymax
toggle .bran 'Branch'
toggle .equi 'Equipment'
Exit
list .list 'Drawlist' at x0 ymax+0.3 width 18 height 5
button .ok 'OK' at x0 ymax OK
path right
button .apply 'Apply' apply
button .cancel 'Cancel' Cancel

!modifyOnIcon = !!pml.getpathname('modmodeon16.png')
button .pick pixmap /$!modifyonicon at x0 ymax
exit

2007-6-5 7-12
PML 基础练习

设置控件初始值

setup form !!addvolumn


title 'Add volumn'
button .ce 'CE' at x0 ymax tooltip 'Select pipe'
paragraph .cename text 'no name' width 15
text .input 'Enter text' at x0 ymax width 10 is string
Frame .frame1 'Include' at x0 ymax
toggle .bran 'Branch'
toggle .equi 'Equipment'
Exit
list .list 'Drawlist' at x0 ymax+0.3 width 18 height 5
button .ok 'OK' at x0 ymax OK
path right
button .apply 'Apply' apply
button .cancel 'Cancel' Cancel

!modifyOnIcon = !!pml.getpathname('modmodeon16.png')
button .pick pixmap /$!modifyonicon at x0 ymax
exit
define method .addvolumn()
!this.bran.val = true
!this.input.val = '1500'
endmethod

按钮的应用实例

setup form !!addvolumn


title 'Add volumn'
button .ce 'CE' at x0 ymax tooltip 'Select pipe'
paragraph .cename text 'no name' width 15
text .input 'Enter text' at x0 ymax width 10 is string
Frame .frame1 'Include' at x0 ymax
toggle .bran 'Branch'
toggle .equi 'Equipment'
Exit
list .list 'Drawlist' at x0 ymax+0.3 width 18 height 5
button .ok 'OK' at x0 ymax OK
path right
button .apply 'Apply' apply
button .cancel 'Cancel' Cancel

!modifyOnIcon = !!pml.getpathname('modmodeon16.png')

2007-6-5 8-12
PML 基础练习

button .pick pixmap /$!modifyonicon at x0 ymax


exit
define method .addvolumn()
!this.bran.val = true
!this.input.val = '1500'
!this.ce.callback = '!this.ce()'
endmethod
define method .ce()
!this.cename.val = fullname
endmethod

对话框控制属性-Apply

setup form !!addvolumn


title 'Add volumn'
button .ce 'CE' at x0 ymax tooltip 'Select pipe'
paragraph .cename text 'no name' width 15
text .input 'Enter text' at x0 ymax width 10 is string
Frame .frame1 'Include' at x0 ymax
toggle .bran 'Branch'
toggle .equi 'Equipment'
Exit
list .list 'Drawlist' at x0 ymax+0.3 width 18 height 5
button .ok 'OK' at x0 ymax OK
path right
button .apply 'Apply' apply
button .cancel 'Cancel' Cancel

!modifyOnIcon = !!pml.getpathname('modmodeon16.png')
button .pick pixmap /$!modifyonicon at x0 ymax
exit
define method .addvolumn()
!this.bran.val = true
!this.input.val = '1500'
!this.ce.callback = '!this.ce()'

!this.apply.callback = '!this.apply()' $*不关闭对话框

endmethod
define method .ce()
!this.cename.val = fullname
endmethod
define method .apply()
!dist = !this.input.val
!name = !this.cename.val

2007-6-5 9-12
PML 基础练习

$p CE is $!name ,Dist = $!dist


endmethod

多选框的应用实例

setup form !!addvolumn


title 'Add volumn'
button .ce 'CE' at x0 ymax tooltip 'Select pipe'
paragraph .cename text 'no name' width 15
text .input 'Enter text' at x0 ymax width 10 is string
Frame .frame1 'Include' at x0 ymax
toggle .bran 'Branch'
toggle .equi 'Equipment'
Exit
list .list 'Drawlist' at x0 ymax+0.3 width 18 height 5
button .ok 'OK' at x0 ymax OK
path right
button .apply 'Apply' apply
button .cancel 'Cancel' Cancel

!modifyOnIcon = !!pml.getpathname('modmodeon16.png')
button .pick pixmap /$!modifyonicon at x0 ymax
exit
define method .addvolumn()
!this.bran.val = true
!this.input.val = '1500'
!this.ce.callback = '!this.ce()'

!this.apply.callback = '!this.apply()' $*不关闭对话框

endmethod
define method .ce()
!this.cename.val = fullname
endmethod
define method .apply()
!name = !this.cename.val
!dist = !this.input.val
!elements = array()
if(!this.bran.val) then
var !elements append coll all bran Within Volume $!name $!dist
endif
if(!this.equi.val) then
var !elements append coll all equip Within Volume $!name $!dist
endif
var !names eval name for all from !elements

2007-6-5 10-12
PML 基础练习

do !element value !elements


add $!element
enddo
endmethod

列表框应用实例

setup form !!addvolumn


title 'Add volumn'
button .ce 'CE' at x0 ymax tooltip 'Select pipe'
paragraph .cename text 'no name' width 15
text .input 'Enter text' at x0 ymax width 10 is string
Frame .frame1 'Include' at x0 ymax
toggle .bran 'Branch'
toggle .equi 'Equipment'
Exit
list .list 'Drawlist' at x0 ymax+0.3 width 18 height 5
button .ok 'OK' at x0 ymax OK
path right
button .apply 'Apply' apply
button .cancel 'Cancel' Cancel

!modifyOnIcon = !!pml.getpathname('modmodeon16.png')
button .pick pixmap /$!modifyonicon at x0 ymax
exit
define method .addvolumn()
!this.bran.val = true
!this.input.val = '1500'
!this.ce.callback = '!this.ce()'

!this.apply.callback = '!this.apply()' $*不关闭对话框

!this.list.callback = '!this.doselection()'
endmethod
define method .ce()
!this.cename.val = fullname
endmethod
define method .apply()
!name = !this.cename.val
!dist = !this.input.val
!elements = array()
if(!this.bran.val) then
var !elements append coll all bran Within Volume $!name $!dist
endif
if(!this.equi.val) then

2007-6-5 11-12
PML 基础练习

var !elements append coll all equip Within Volume $!name $!dist
endif
var !names eval name for all from !elements
!this.list.dtext = !names
do !element value !elements
add $!element
enddo
endmethod
define method .doselection()
!name = !this.list.selection()
$!name
endmethod

Alpha Views

Setup Form !!alphaview


title ' Input & Output'
view .Input ALPHA hei 10 width 40
channel REQUESTS
channel COMMANDS
Exit
button .apply 'Apply' at x0 ymax Apply
button .Dismiss 'Cancel' at Xmax form-size Cancel
Exit

Volumn View

setup form !!poptest


view .vol volume width 50 hei 9
exit
path down
button .press 'swap popup' call '!this.popswap()'
menu .popmenu
add 'hello' ' '
add 'world' ' '
exit
exit
define method .popswap()
!this.vol.popup = !this.popmenu
endmethod

2007-6-5 12-12

You might also like