当前位置:文档之家› PDMS 12.0 编程基础ABC

PDMS 12.0 编程基础ABC

下面是PDMS编程介绍一个简单的MacroNEW EQUIP /FREDNEW BOXXLEN 300 YLEN 400 ZLEN 600NEW CYL DIA 400 HEI 600CONN P1 TO P2 OF PREV参数化宏Parameterized MacroNEW EQUIP /$1NEW BOXXLEN $2 YLEN $3 ZLEN $4NEW CYL DIA $3 HEI $4CONN P1 TO P2 OF PREV变量给属性赋值New PipeDesc 'My Description'Temp 100Pspec /A3BPurp PIPI!desc = desc!temp = temp!pspec = pspec!purp = purpNew PipeDesc '$!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 * !Widthreturn !Area $*函数!!Area有两个参数一个返回值Endfunction练习-新建函数计算园的面积,测试函数define function !!circleArea( !radius is REAL) is REAL!Area = PI * pow(!radius,2)return !AreaEndfunction条件判断语句(If Construct)!Type = Type!OwnType = Type of OwnerIF (!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 = typeif(!type eq 'BRAN') then!href = href!tref = trefif(!href.set()) then!n = !n + 1add hrefendifif(!tref.set()) then!n = !n + 1add trefendifendifif(!type eq 'NOZZ') then!cref = crefif(!cref.set()) then!n = !n + 1add crefendifendif$p Total $!n reference循环赋值!Total = 0Do !x From 1 To 100 By 1!Total = !Total + !xEnddo中断循环Break!Total = 0Do !x From 1 To 100!Total = !Total + !xIf(!Total gt 500) thenBreak $*或者Break if(!Total gt 500) EndifEnddo用skip 跳过奇数Do !x From 1 To 100If(Int(!x / 2) NE (!x / 2)) thenSkip $*或者Skip If(Int(!x / 2) NE (!x / 2)) Endif!Total = !Total + !xEnddo练习-跳转!n = 0label /start!type = typeif(!type eq 'BRAN') then!href = href!tref = trefif(!href.set()) then!n = !n + 1add hrefendifif(!tref.set()) then!n = !n + 1add trefendifendifif(!type eq 'NOZZ') then!cref = crefif(!cref.set()) then!n = !n + 1add crefgoto crefgolabel /startendifendif$p Total $!n reference错误提示Next$p OK错误处理(Error Handling)NextHandle (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 valuedo !Name values !BestCar$p Array element is $!NameEnddo索引循环Do indicesdo !n indices !BestCar!Car = !BestCar[!n]$p Array element $!n is $!CarEnddo管道排序Var !Pipes Coll all Pipe for ceVar !Names Eval name for all from !Pipes!Name.sort().invert()Do !n indices !Namesreorder $!names[$!n] before $!nEndDo练习-选择一个设备,将所有Nozzle连接的管道添加进来Var !nozzles Coll all nozzle for ceDo !nozzle value !nozzlesAdd cref of $!nozzleEndDo文件处理(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 $!lineEnddo显示输出窗口var !isshown form _CADCBTH displayif(!isshown eq 'Off') thenshow _CADCREQendifvar !date clock datevar !time clock time$p Begin report at $!date $!time一个简单的对话框(Form)setup form !!helloTitle 'Hello'paragraph .Message text 'Hello world'button .bye 'Goodbye' OKexit缺省构造方法(Constructor method)setup form !!helloTitle 'Hello'paragraph .Message text 'Hello world'text .input 'Enter text' width 10 is string $*字符串类型的编辑框button .bye 'Goodbye' OKexitDefine method .hello() $*缺省构造方法,与Form同名,不带参数!this.input.callback = ‘!this.doinput()’ $*Callback指明响应操作endmethodDefine method .doinput() $*响应操作!this.message.val = !this.input.val $*!this = !!hello, val 表示value endmethod控件定位setup form !!helloTitle 'Hello'paragraph .Message text 'Hello world'text .input 'Enter text' at x0 ymax width 10 is stringbutton .bye 'Goodbye' at x0 ymax OKexit控件定义setup form !!addvolumntitle 'Add volumn'button .ce 'CE' at x0 ymax tooltip 'Select pipe'paragraph .cename text 'no name' width 15text .input 'Enter text' at x0 ymax width 10 is stringFrame .frame1 'Include' at x0 ymaxtoggle .bran 'Branch'toggle .equi 'Equipment'Exitlist .list 'Drawlist' at x0 ymax+0.3 width 18 height 5button .ok 'OK' at x0 ymax OKpath rightbutton .apply 'Apply' applybutton .cancel 'Cancel' Cancel!modifyOnIcon = !!pml.getpathname('modmodeon16.png')button .pick pixmap /$!modifyonicon at x0 ymaxexit设置控件初始值setup form !!addvolumntitle 'Add volumn'button .ce 'CE' at x0 ymax tooltip 'Select pipe'paragraph .cename text 'no name' width 15text .input 'Enter text' at x0 ymax width 10 is stringFrame .frame1 'Include' at x0 ymaxtoggle .bran 'Branch'toggle .equi 'Equipment'Exitlist .list 'Drawlist' at x0 ymax+0.3 width 18 height 5button .ok 'OK' at x0 ymax OKpath rightbutton .apply 'Apply' applybutton .cancel 'Cancel' Cancel!modifyOnIcon = !!pml.getpathname('modmodeon16.png') button .pick pixmap /$!modifyonicon at x0 ymaxexitdefine method .addvolumn()!this.bran.val = true!this.input.val = '1500'endmethod按钮的应用实例setup form !!addvolumntitle 'Add volumn'button .ce 'CE' at x0 ymax tooltip 'Select pipe'paragraph .cename text 'no name' width 15text .input 'Enter text' at x0 ymax width 10 is stringFrame .frame1 'Include' at x0 ymaxtoggle .bran 'Branch'toggle .equi 'Equipment'Exitlist .list 'Drawlist' at x0 ymax+0.3 width 18 height 5button .ok 'OK' at x0 ymax OKpath rightbutton .apply 'Apply' applybutton .cancel 'Cancel' Cancel!modifyOnIcon = !!pml.getpathname('modmodeon16.png') button .pick pixmap /$!modifyonicon at x0 ymaxexitdefine method .addvolumn()!this.bran.val = true!this.input.val = '1500'!this.ce.callback = '!this.ce()'endmethoddefine method .ce()!this.cename.val = fullnameendmethod对话框控制属性-Applysetup form !!addvolumntitle 'Add volumn'button .ce 'CE' at x0 ymax tooltip 'Select pipe'paragraph .cename text 'no name' width 15text .input 'Enter text' at x0 ymax width 10 is stringFrame .frame1 'Include' at x0 ymaxtoggle .bran 'Branch'toggle .equi 'Equipment'Exitlist .list 'Drawlist' at x0 ymax+0.3 width 18 height 5button .ok 'OK' at x0 ymax OKpath rightbutton .apply 'Apply' applybutton .cancel 'Cancel' Cancel!modifyOnIcon = !!pml.getpathname('modmodeon16.png') button .pick pixmap /$!modifyonicon at x0 ymaxexitdefine method .addvolumn()!this.bran.val = true!this.input.val = '1500'!this.ce.callback = '!this.ce()'!this.apply.callback = '!this.apply()' $*不关闭对话框endmethoddefine method .ce()!this.cename.val = fullnameendmethoddefine method .apply()!dist = !this.input.val!name = !this.cename.val$p CE is $!name ,Dist = $!distendmethod多选框的应用实例setup form !!addvolumntitle 'Add volumn'button .ce 'CE' at x0 ymax tooltip 'Select pipe'paragraph .cename text 'no name' width 15text .input 'Enter text' at x0 ymax width 10 is stringFrame .frame1 'Include' at x0 ymaxtoggle .bran 'Branch'toggle .equi 'Equipment'Exitlist .list 'Drawlist' at x0 ymax+0.3 width 18 height 5button .ok 'OK' at x0 ymax OKpath rightbutton .apply 'Apply' applybutton .cancel 'Cancel' Cancel!modifyOnIcon = !!pml.getpathname('modmodeon16.png')button .pick pixmap /$!modifyonicon at x0 ymaxexitdefine method .addvolumn()!this.bran.val = true!this.input.val = '1500'!this.ce.callback = '!this.ce()'!this.apply.callback = '!this.apply()' $*不关闭对话框endmethoddefine method .ce()!this.cename.val = fullnameendmethoddefine method .apply()!name = !this.cename.val!dist = !this.input.val!elements = array()if(!this.bran.val) thenvar !elements append coll all bran Within Volume $!name $!dist endifif(!this.equi.val) thenvar !elements append coll all equip Within Volume $!name $!dist endifvar !names eval name for all from !elementsdo !element value !elementsadd $!elementenddoendmethod列表框应用实例setup form !!addvolumntitle 'Add volumn'button .ce 'CE' at x0 ymax tooltip 'Select pipe'paragraph .cename text 'no name' width 15text .input 'Enter text' at x0 ymax width 10 is stringFrame .frame1 'Include' at x0 ymaxtoggle .bran 'Branch'toggle .equi 'Equipment'Exitlist .list 'Drawlist' at x0 ymax+0.3 width 18 height 5button .ok 'OK' at x0 ymax OKpath rightbutton .apply 'Apply' applybutton .cancel 'Cancel' Cancel!modifyOnIcon = !!pml.getpathname('modmodeon16.png')button .pick pixmap /$!modifyonicon at x0 ymaxexitdefine 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()'endmethoddefine method .ce()!this.cename.val = fullnameendmethoddefine method .apply()!name = !this.cename.val!dist = !this.input.val!elements = array()if(!this.bran.val) thenvar !elements append coll all bran Within Volume $!name $!dist endifif(!this.equi.val) thenvar !elements append coll all equip Within Volume $!name $!dist endifvar !names eval name for all from !elements!this.list.dtext = !namesdo !element value !elementsadd $!elementenddoendmethoddefine method .doselection()!name = !this.list.selection()$!nameendmethodAlpha ViewsSetup Form !!alphaviewtitle ' Input & Output'view .Input ALPHA hei 10 width 40channel REQUESTSchannel COMMANDSExitbutton .apply 'Apply' at x0 ymax Applybutton .Dismiss 'Cancel' at Xmax form-size Cancel ExitVolumn Viewsetup form !!poptestview .vol volume width 50 hei 9exitpath downbutton .press 'swap popup' call '!this.popswap()'menu .popmenuadd 'hello' ' 'add 'world' ' 'exitexitdefine method .popswap()!this.vol.popup = !this.popmenuendmethod。

相关主题