立即注册 登录
工程集散地 返回首页

zhancm的个人空间 http://bbs.g3d.org/?7910 [收藏] [复制] [分享] [RSS]

日志

PML基础练习

已有 763 次阅读2018-6-3 15:25 |个人分类:PDMS使用|系统分类:三维软件

一个简单的 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 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

QQ|关于我们|手机版|Archiver|小黑屋|工程G3D ( 鄂ICP备16022302号-2

GMT+8, 2022-6-28 20:12 , Processed in 1.171875 second(s), 20 queries .

Powered by 3d-sharp! X3.2

© 2001-2013 瞎扑 Inc.

本论坛言论纯属发布者个人意见,不代表瞎扑网立场!如有疑义,请与管理员联系:sharp3d@qq.com 未经本站许可,禁止转载本站内容。

返回顶部