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?')
定義函數
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
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
!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
!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)
!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 $*字串類型的編輯框
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
設置控制項初始值
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')
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
$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
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
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
0 Comments:
Post a Comment
<< Home