PML基础练习.docx
- 文档编号:27265320
- 上传时间:2023-06-28
- 格式:DOCX
- 页数:17
- 大小:22.16KB
PML基础练习.docx
《PML基础练习.docx》由会员分享,可在线阅读,更多相关《PML基础练习.docx(17页珍藏版)》请在冰豆网上搜索。
PML基础练习
一个简单的Macro
NEWEQUIP/FRED
NEWBOX
XLEN300YLEN400ZLEN600
NEWCYLDIA400HEI600
CONNP1TOP2OFPREV
参数化宏ParameterizedMacro
NEWEQUIP/$1
NEWBOX
XLEN$2YLEN$3ZLEN$4
NEWCYLDIA$3HEI$4
CONNP1TOP2OFPREV
变量给属性赋值
NewPipe
Desc'MyDescription'
Temp100
Pspec/A3B
PurpPIPI
!
desc=desc
!
temp=temp
!
pspec=pspec
!
purp=purp
NewPipe
Desc'$!
desc'
Temp$!
temp
!
pspec$!
pspec
!
purp$!
purp
字符串方法实例
!
line='hellohowareyou'
!
newline=!
line.after('hello').trim().upcase()
qvar!
newline
!
newline=!
newline.replace('how','where').replace('you','you?
')
定义函数
definefunction!
!
Area(!
LengthisREAL,!
WidthisREAL)isREAL
!
Area=!
Length*!
Width
return!
Area$*函数!
!
Area有两个参数一个返回值
Endfunction
练习-新建函数计算园的面积,测试函数
definefunction!
!
circleArea(!
radiusisREAL)isREAL
!
Area=PI*pow(!
radius,2)
return!
Area
Endfunction
条件判断语句(IfConstruct)
!
Type=Type
!
OwnType=TypeofOwner
IF(!
Typeeq'BRAN')THEN
$PCEisBranch.
ELSEIF(!
OwnTypeeq'BRAN')THEN
$PCEisBranchmember.
ELSE
$PCEis$!
Type,PlsselectBranch.
ENDIF
练习-条件判断
!
n=0
!
type=type
if(!
typeeq'BRAN')then
!
href=href
!
tref=tref
if(!
href.set())then
!
n=!
n+1
addhref
endif
if(!
tref.set())then
!
n=!
n+1
addtref
endif
endif
if(!
typeeq'NOZZ')then
!
cref=cref
if(!
cref.set())then
!
n=!
n+1
addcref
endif
endif
$pTotal$!
nreference
循环赋值
!
Total=0
Do!
xFrom1To100By1
!
Total=!
Total+!
x
Enddo
中断循环Break
!
Total=0
Do!
xFrom1To100
!
Total=!
Total+!
x
If(!
Totalgt500)then
Break$*或者Breakif(!
Totalgt500)
Endif
Enddo
用skip跳过奇数
Do!
xFrom1To100
If(Int(!
x/2)NE(!
x/2))then
Skip$*或者SkipIf(Int(!
x/2)NE(!
x/2))
Endif
!
Total=!
Total+!
x
Enddo
练习-跳转
!
n=0
label/start
!
type=type
if(!
typeeq'BRAN')then
!
href=href
!
tref=tref
if(!
href.set())then
!
n=!
n+1
addhref
endif
if(!
tref.set())then
!
n=!
n+1
addtref
endif
endif
if(!
typeeq'NOZZ')then
!
cref=cref
if(!
cref.set())then
!
n=!
n+1
addcref
gotocref
golabel/start
endif
endif
$pTotal$!
nreference
错误提示
Next
$pOK
错误处理(ErrorHandling)
Next
Handle(2,113)
$pLastelement.
EndHandle
$pOK
数组(Array)
!
Str='Benz,Bmw,Audi'
!
BestCar=!
Str.Split(',')
Qvar!
BestCar
!
BestCar[4]='Cadillac'
!
BestCar.Append('Lincoln')
赋值循环Dovalue
do!
Namevalues!
BestCar
$pArrayelementis$!
Name
Enddo
索引循环Doindices
do!
nindices!
BestCar
!
Car=!
BestCar[!
n]
$pArrayelement$!
nis$!
Car
Enddo
管道排序
Var!
PipesCollallPipeforce
Var!
NamesEvalnameforallfrom!
Pipes
!
Name.sort().invert()
Do!
nindices!
Names
reorder$!
names[$!
n]before$!
n
EndDo
练习-选择一个设备,将所有Nozzle连接的管道添加进来
Var!
nozzlesCollallnozzleforce
Do!
nozzlevalue!
nozzles
Addcrefof$!
nozzle
EndDo
文件处理(HandlingFiles)
!
Input=objectFILE('%pdmsexe%abc.txt')
!
Lines=!
Input.ReadFile()$*ReadFile将文件内容写到字符串数组中
!
ResultArray=ARRAY()$*声明新数组
do!
LineVALUES!
Lines
!
Column1=!
Line.Part
(1)
!
ResultArray.Append(!
Column1)
Enddo
!
Output=objectFILE('%pdmsexe%def.txt')
!
Output.WriteFile('WRITE',!
ResultArray)$*WriteFile将数组写到文件
练习-文件处理
!
Input=objectFILE('%pdmsexe%abc.txt')
!
Lines=!
Input.ReadFile()
do!
LineVALUES!
Lines
$p$!
line
Enddo
显示输出窗口
var!
isshownform_CADCBTHdisplay
if(!
isshowneq'Off')then
show_CADCREQ
endif
var!
dateclockdate
var!
timeclocktime
$pBeginreportat$!
date$!
time
一个简单的对话框(Form)
setupform!
!
hello
Title'Hello'
paragraph.Messagetext'Helloworld'
button.bye'Goodbye'OK
exit
缺省构造方法(Constructormethod)
setupform!
!
hello
Title'Hello'
paragraph.Messagetext'Helloworld'
text.input'Entertext'width10isstring$*字符串类型的编辑框
button.bye'Goodbye'OK
exit
Definemethod.hello()$*缺省构造方法,与Form同名,不带参数
!
this.input.callback=‘!
this.doinput()’$*Callback指明响应操作
endmethod
Definemethod.doinput()$*响应操作
!
this.message.val=!
this.input.val$*!
this=!
!
hello,val表示value
endmethod
控件定位
setupform!
!
hello
Title'Hello'
paragraph.Messagetext'Helloworld'
text.input'Entertext'atx0ymaxwidth10isstring
button.bye'Goodbye'atx0ymaxOK
exit
控件定义
setupform!
!
addvolumn
title'Addvolumn'
button.ce'CE'atx0ymaxtooltip'Selectpipe'
paragraph.cenametext'noname'width15
text.input'Entertext'atx0ymaxwidth10isstring
Frame.frame1'Include'atx0ymax
toggle.bran'Branch'
toggle.equi'Equipment'
Exit
list.list'Drawlist'atx0ymax+0.3width18height5
button.ok'OK'atx0ymaxOK
pathright
button.apply'Apply'apply
button.cancel'Cancel'Cancel
!
modifyOnIcon=!
!
pml.getpathname('modmodeon16.png')
button.pickpixmap/$!
modifyoniconatx0ymax
exit
设置控件初始值
setupform!
!
addvolumn
title'Addvolumn'
button.ce'CE'atx0ymaxtooltip'Selectpipe'
paragraph.cenametext'noname'width15
text.input'Entertext'atx0ymaxwidth10isstring
Frame.frame1'Include'atx0ymax
toggle.bran'Branch'
toggle.equi'Equipment'
Exit
list.list'Drawlist'atx0ymax+0.3width18height5
button.ok'OK'atx0ymaxOK
pathright
button.apply'Apply'apply
button.cancel'Cancel'Cancel
!
modifyOnIcon=!
!
pml.getpathname('modmodeon16.png')
button.pickpixmap/$!
modifyoniconatx0ymax
exit
definemethod.addvolumn()
!
this.bran.val=true
!
this.input.val='1500'
endmethod
按钮的应用实例
setupform!
!
addvolumn
title'Addvolumn'
button.ce'CE'atx0ymaxtooltip'Selectpipe'
paragraph.cenametext'noname'width15
text.input'Entertext'atx0ymaxwidth10isstring
Frame.frame1'Include'atx0ymax
toggle.bran'Branch'
toggle.equi'Equipment'
Exit
list.list'Drawlist'atx0ymax+0.3width18height5
button.ok'OK'atx0ymaxOK
pathright
button.apply'Apply'apply
button.cancel'Cancel'Cancel
!
modifyOnIcon=!
!
pml.getpathname('modmodeon16.png')
button.pickpixmap/$!
modifyoniconatx0ymax
exit
definemethod.addvolumn()
!
this.bran.val=true
!
this.input.val='1500'
!
this.ce.callback='!
this.ce()'
endmethod
definemethod.ce()
!
this.cename.val=fullname
endmethod
对话框控制属性-Apply
setupform!
!
addvolumn
title'Addvolumn'
button.ce'CE'atx0ymaxtooltip'Selectpipe'
paragraph.cenametext'noname'width15
text.input'Entertext'atx0ymaxwidth10isstring
Frame.frame1'Include'atx0ymax
toggle.bran'Branch'
toggle.equi'Equipment'
Exit
list.list'Drawlist'atx0ymax+0.3width18height5
button.ok'OK'atx0ymaxOK
pathright
button.apply'Apply'apply
button.cancel'Cancel'Cancel
!
modifyOnIcon=!
!
pml.getpathname('modmodeon16.png')
button.pickpixmap/$!
modifyoniconatx0ymax
exit
definemethod.addvolumn()
!
this.bran.val=true
!
this.input.val='1500'
!
this.ce.callback='!
this.ce()'
!
this.apply.callback='!
this.apply()'$*不关闭对话框
endmethod
definemethod.ce()
!
this.cename.val=fullname
endmethod
definemethod.apply()
!
dist=!
this.input.val
!
name=!
this.cename.val
$pCEis$!
name,Dist=$!
dist
endmethod
多选框的应用实例
setupform!
!
addvolumn
title'Addvolumn'
button.ce'CE'atx0ymaxtooltip'Selectpipe'
paragraph.cenametext'noname'width15
text.input'Entertext'atx0ymaxwidth10isstring
Frame.frame1'Include'atx0ymax
toggle.bran'Branch'
toggle.equi'Equipment'
Exit
list.list'Drawlist'atx0ymax+0.3width18height5
button.ok'OK'atx0ymaxOK
pathright
button.apply'Apply'apply
button.cancel'Cancel'Cancel
!
modifyOnIcon=!
!
pml.getpathname('modmodeon16.png')
button.pickpixmap/$!
modifyoniconatx0ymax
exit
definemethod.addvolumn()
!
this.bran.val=true
!
this.input.val='1500'
!
this.ce.callback='!
this.ce()'
!
this.apply.callback='!
this.apply()'$*不关闭对话框
endmethod
definemethod.ce()
!
this.cename.val=fullname
endmethod
definemethod.apply()
!
name=!
this.cename.val
!
dist=!
this.input.val
!
elements=array()
if(!
this.bran.val)then
var!
elementsappendcollallbranWithinVolume$!
name$!
dist
endif
if(!
this.equi.val)then
var!
elementsappendcollallequipWithinVolume$!
name$!
dist
endif
var!
namesevalnameforallfrom!
elements
do!
elementvalue!
elements
add$!
element
enddo
endmethod
列表框应用实例
setupform!
!
addvolumn
title'Addvolumn'
button.ce'CE'atx0ymaxtooltip'Selectpipe'
paragraph.cenametext'noname'width15
text.input'Entertext'atx0ymaxwidth10isstring
Frame.frame1'Include'atx0ymax
toggle.bran'Branch'
toggle.equi'Equipment'
Exit
list.list'Drawlist'atx0ymax+0.3width18height5
button.ok'OK'atx0ymaxOK
pathright
button.apply'Apply'apply
button.cancel'Cancel'Cancel
!
modifyOnIcon=!
!
pml.getpathname('modmodeon16.png')
button.pickpixmap/$!
modifyoniconatx0ymax
exit
definemethod.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
definemethod.ce()
!
this.cename.val=fullname
endmethod
definemethod.apply()
!
name=!
this.cename.val
!
dist=!
this.input.val
!
elements=array()
if(!
this.bran.val)then
var!
elementsappendcollallbranWithinVolume$!
name$!
dist
endif
if(!
this.equi.val)then
var!
elementsappendcollallequipWithinVolume$!
name$!
dist
endif
var!
namesevalnameforallfrom!
elements
!
this.list.dtext=!
names
do!
elementvalue!
elements
add$!
element
enddo
endmethod
definemethod.doselection()
!
name=!
this.list.selection()
$!
name
endmethod
AlphaViews
SetupForm!
!
alphaview
title'Input&Output'
view.InputALPHAhei10width40
channelREQUESTS
channelCOMMANDS
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PML 基础 练习