10
AVEVA PDMS/MARINE Step-By-Step Tutorial AUTOMATIC NIGHT PROCEDURES OF ADMINISTRATION PREAMBLE ............................................................................................................................................................. 2 PART 1. INITIAL SETUP – PREPARING FOLDERS TO STORE LOG-FILES AND USERS EXPUNGE .................................. 2 PART 2. DATABASES CHECK ................................................................................................................................... 3 PART 3. RUN INTER-DB MACROSES ........................................................................................................................ 3 PART 4. SPATIAL MAP UPDATE .............................................................................................................................. 4 PART 5. PIPING CHECK ........................................................................................................................................... 4 PART 6. REVIEW FILE CREATION ............................................................................................................................. 4 PART 7. SESSION MERGING.................................................................................................................................... 5 PART 8. CLASHES CHECK ........................................................................................................................................ 5 PART 9. SENDING EMAIL WITH ALL LOGS ATTACHED ............................................................................................. 6 APPENDIX A. COMPLETE CODE CONSISTS OF ALL ABOVE PARTS ............................................................................ 7

Final

Embed Size (px)

Citation preview

Page 1: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

AUTOMATIC NIGHT PROCEDURES OF ADMINISTRATION

PREAMBLE ............................................................................................................................................................. 2

PART 1. INITIAL SETUP – PREPARING FOLDERS TO STORE LOG-FILES AND USERS EXPUNGE .................................. 2

PART 2. DATABASES CHECK ................................................................................................................................... 3

PART 3. RUN INTER-DB MACROSES ........................................................................................................................ 3

PART 4. SPATIAL MAP UPDATE .............................................................................................................................. 4

PART 5. PIPING CHECK ........................................................................................................................................... 4

PART 6. REVIEW FILE CREATION ............................................................................................................................. 4

PART 7. SESSION MERGING .................................................................................................................................... 5

PART 8. CLASHES CHECK ........................................................................................................................................ 5

PART 9. SENDING EMAIL WITH ALL LOGS ATTACHED ............................................................................................. 6

APPENDIX A. COMPLETE CODE CONSISTS OF ALL ABOVE PARTS ............................................................................ 7

Page 2: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

PREAMBLE

Administrator of AVEVA PDMS/Marine systems should maintain project performing some tasks which usually done on periodical basis. Some of them are databases integrity check, sessions merging, creation of Review file (RVM), Inter-DB macro run, piping consistency check, clashes check etc. Many of these procedures could be done in auto mode running with the scheduler for example at nights. In next several examples, we will review some of the procedures The result of some following actions is a log-file where administrator can check if there are any problems found. It is also possible automatically send any logs to email – some PML code should be added (not done here). Although it is possible to try to fix the problems in automode, we highly recommend to do it manually under control of Administrator after reading the log visually. All the following procedures written on PML and checked on SAM project supplied with AVEVA PDMS. For any other projects it should modified by Administrator of this project therefore prerequisites for those who wants to use it and modify are PML and Admin knowledge. To run it you need to do following: 1.Copy all needed PML from following blocks into one file and call it for example night-process-run.pmlmac 2.Create a copy of your project’s run bat-file shortcut and add folling to shortcut properties: …..\pdms.bat TTY SAM SYSTEM/XXXXXX /SAMPLE $M/\\yourserverpath\night-process-run.pmlmac where TTY - terminal mode of PDMS run (non-graphics) SAM – project name SYSTEM/XXXXXX – username and password (must be a system user) /SAMPLE – MDB And as a last parameter call for night macro You don’t need to point any module here as far as PML macro will manage them automatically

3.Create a schedule with using for example Windows scheduler and point ot this shortcut

BEFORE DO ANY ACTION YOU MUST BE SURE THAT YOUR PROJECT IS BACKUPED

PART 1. Initial setup – preparing folders to store log-files and users expunge

--first file – database check log-file folder --second file – piping consistency check log-file folder --third file - AVEVA Review file folder --if folders do not exist then create it with CMD MKDIR command !folders[1] = 'C:\temp\NIGHT-WORK\DatabaseCheck\' !folders[2] = 'C:\temp\NIGHT-WORK\PipingCheck\' !folders[3] = 'C:\temp\NIGHT-WORK\Review\' !folders[4] = 'C:\temp\NIGHT-WORK\Clashes\' do !x from 1 to !folders.Size() !fo = object file('$!folders[$!x]') if (!fo.Exists().Not()) then !comm = |SYSCOM 'MKDIR $!folders[$!x]'| $!comm endif Enddo

--Block 1. EXPUNGE ALL CLAMILISTS/USERS BEFORE --Goto Admin module ADMIN --doing users expunge

EXPUNGE --run thru all databases and expunge from claimlists

VAR !DBS COLLECT ALL DB do!x from 1 to !DBS.Size() !DBNA = !DBS[!X].Dbref().Name.After('/*') EXPUNGE DB $!DBNA HANDLE (1,271)(1,273) --if database is UPDATE or is FOREIGN

ENDHANDLE

Page 3: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

ENDDO --end of Block 1

PART 2. Databases check

--Block 2. CHECK DATABASES --collect databases, check and form the log-file with name !TotalLOG-DB.log VAR !DBS COLL ALL DB !outputLOG = object array() !outputLOGFILE = object file('$!folders[1]' + '!TotalLOG-DB.log') VAR !mdbn MDB --check options CHECKOPTION EXT CHECK PREF $!mdbn

do !x from 1 to !DBS.Size() --skip if Foreign skip if (!DBS[!x].DbRef().Fore EQ 'FOREIGN') !dbName = !DBS[!x].DbRef().Name --replacing not allowable symbols in file name !nfile = '$!folders[1]' & !DBS[!x].DbRef().Name.After('/*').Replace('/','!') & '.txt' ALPHA LOG/$!nfile OVER HANDLE ANY ALPHA LOG END SKIP ENDHANDLE !dbN = !DBS[!x].DbRef().Name.After('/*') --run check for each db in collection CHECK DB $!dbN HANDLE ANY ALPHA LOG END SKIP ENDHANDLE ALPHA LOG END --check log file for any errors or inconsistencies !logfile = object file(!nfile) !logfileRead = !logfile.ReadFile() if (!logfileRead[!logfileRead.Size() - 1].Matchwild('*Database has no structural errors*').Not()) then !outputLOG.Append('DBS $!dbName : inconsistencies found.. Manual check needed...') endif do !y from 1 to !logfileRead.Size() if (!logfileRead[!y].Matchwild('*invalid*') OR !logfileRead[!y].Matchwild('*unknown*')) then !outputLOG.Append('DBS $!dbName : inconsistencies found.. Manual check needed...') SKIP endif enddo enddo --output results of checking into final log-file !outputLOGFILE.WriteFile('OVERWRITE',!outputLOG) --end of Block 2

PART 3. Run Inter-DB macroses

--Block 3. Run any inter-db Macroses if found --read folder proj_idMAC VAR !PROJCODE PROJ CODE !TOEVAL = |VAR !MACFOLDER EVAR '$!PROJCODE| & |MAC'| $!TOEVAL !MacroFolder = object file(!MACFOLDER) --enter to Design DESIGN !files = !MacroFolder.Files() if (!files.Size() NEQ 0) then --run each macro do !x from 1 to !files.Size() !path = !files[!x].String() $M/$!path enddo

Page 4: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

--back to Monitor MONITOR do !x from 1 to !files.Size() --delete processed macroses DELETE MAC $!x enddo endif --End of Block 3

PART 4. Spatial map update

--Block 4. Spatial map update DESIGN MAP BUILD MDB HANDLE (69,97) --if Read-Only DB ENDHANDLE --End of Block 4

PART 5. Piping check

--Block 5. Check pipe (using SAM project as example) --goto Zone with Piping ZONE /PIPES --collect pipes !pipes = !!CollectAllFor('PIPE',||,CE) --creating log-file with name !TotalLOG-PIPES.log !outputLOG = object array() !outputLOGFILE = object file('$!folders[2]' + '!TotalLOG-PIPES.log') --run do..loop, forming data output to temp log-file do !x from 1 to !pipes.Size() !nfile = '$!folders[2]' & !pipes[!x].Name.Replace('/','!') & '.txt' ALPHA LOG/$!nfile OVER $!pipes[$!x] VAR !userm USERM VAR !lastm LASTM !user = 'Modified by user: $!userm , $!lastm' $P $!user CHECK CE ALPHA LOG END --check temp log-file and if inconsistencies found output then to final log !logfile = object file(!nfile) !logfileRead = !logfile.ReadFile() if (!logfileRead[!logfileRead.Size()].Matchwild('*NO DATA INCONSISTENCIES*').Not()) then !outputLOG.Append('PIPE $!!CE.Name : inconsistencies found... Manual check needed…') endif enddo !outputLOGFILE.WriteFile('OVERWRITE',!outputLOG) --End of Block 5

PART 6. Review file creation

--Block 6. Create RVM file (using SAM project as example) --goto SITE SITE /STABILIZER !CEName = !!CE.Name --create RVM file VAR !projcode PROJ CODE !revFile = object file('$!folders[3]' + '$!projcode' + '_model.rvm') --run export command EXPORT FILE/$!revFile OVER EXPORT ENCODING UTFE

Page 5: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

EXPORT ALL PIPE FOR CE COLOUR 10 EXPORT ALL PIPE WITH (NAME OF ZONE EQ '/CABLETRAY') FOR CE COLOUR 11 EXPORT ALL PIPE WITH (MATCHWILD(NAME,'*A*') AND NAME OF ZONE EQ '/PIPES') FOR CE COLOUR 2 EXPORT ALL PIPE WITH (MATCHWILD(NAME,'*B*') AND NAME OF ZONE EQ '/PIPES') FOR CE COLOUR 3 EXPORT ALL PIPE WITH (MATCHWILD(NAME,'*C*') AND NAME OF ZONE EQ '/PIPES') FOR CE COLOUR 6 EXPORT ALL PIPE WITH (NAME OF ZONE EQ '/HEATING-VENTS') FOR CE COLOUR 12 EXPORT ALL EQUI FOR CE COLOUR 4 EXPORT ALL STRU FOR CE COLOUR 8 EXPORT ALL STRU WITH (NAME OF ZONE EQ '/STEEL' OR NAME OF ZONE EQ '/RACKPIPES') FOR CE COLOUR 7 EXPORT FINISH --End of Block 6

PART 7. Session merging

This part should not be used on global projects or if you use any tools for history checking --Block 7. Session merging (optional) --goto Admin ADMIN VAR !DBS COLL ALL DB do !x from 1 to !DBS.Size() --skip on Foreign DBs skip if (!DBS[!x].DbRef().Fore EQ 'FOREIGN') !mergewhere = !DBS[!x].DbRef().Name.After('/*') --run merge MERGE CHAN $!mergewhere HANDLE (1,18)(1,293) --handle if Foreign DB ENDHANDLE enddo --End of Block 7

PART 8. Clashes check

--Block 8.Clashes check --goto Design DESIGN --first create template !clashTemplateFile = !folders[4] + 'clashtemplate.tmp' !templData[1] = '$$CLANUM$$ # $$CLATYPE$$' !templData[2] = '$$CLA1$$' !templData[3] = 'with' !templData[4] = '$$CLA2$$' !templData[5] = 'at $$CLAPOS$$' !templData[6] = '--------------' !clashTemplateFileObject = object file(!clashTemplateFile) !clashTemplateFileObject.Writefile('OVERWRITE',!templData) !clashOutputFile = !folders[4] + '!TotalLOG-CLASHES.log' --run desclash DESCLASH REPORT MACRO /$!clashTemplateFile ALPHA FILE /$!clashOutputFile OVER OVERRIDE ON REMOVE OBST All OBST ALL --some setting NOCHECK WITHIN BRAN NOCHECK WITHIN EQUI INCLUDE CONNECTIONS INCLUDE TOUCHES

Page 6: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

--check site /STABILIZER from SAM project CHECK /STABILIZER ALPHA FILE END REPORT MACRO OFF EXIT --End of Block 8

PART 9. Sending email with all logs attached

--Block 9.Send email --goto MONITOR MONITOR !emailAddresses = '[email protected];[email protected]' VAR !getPU EVAR PDMSUSER !pdmsuser1 = !getPU.Split()[1] !scriptFile = !pdmsuser1 + |\send-night-report.vbs| --get attachments from prev !attachment1File = !folders[1] + '!TotalLOG-DB.log' !attachment2File = !folders[2] + '!TotalLOG-PIPES.log' !attachment3File = !folders[4] + '!TotalLOG-CLASHES.log' !scriptFileOF = object FILE(!scriptFile) if (!scriptFileOF.Exists()) then !scriptFileOF.Deletefile() HANDLE ANY ENDHANDLE endif VAR !getU EVAR USERNAME !session = current session var !projCode PROJ CODE !nightDate = object datetime() !nightDateString = !nightDate.String() -- Build the lines for the VBS file !lines = OBJECT ARRAY() !lines.append(|Set olApp = CreateObject("Outlook.Application")|) !lines.append(|Set objMail = olApp.CreateItem(olMailItem)|) !lines.append(|objMail.Display|) !lines.append(|Set colAttach = objMail.Attachments|) !lines.append(|Set oAttach = colAttach.Add("| & !attachment1File & |")|) !lines.append(|colAttach.Add("| & !attachment2File & |")|) !lines.append(|colAttach.Add("| & !attachment3File & |")|) !lines.append(|objMail.To = "$!emailAddresses"|) !lines.append(|objMail.Subject = "Night Check Results ( $!nightDateString )"|) !lines.append(|objMail.HTMLBody = "<BODY><p style='font-face:Tahoma; color=#000000 size=12pt;'>" & _ |) !lines.append(|"<b style='font-face:Verdana; color:#ff0000; font-size:12pt;'>Project: </b>| & !projCode & |<br/>" & _ |) !lines.append(|"<b style='font-face:Verdana; color:#ff0000; font-size:12pt;'>MDB: </b>| & !session.mdb().string() & |</p></BODY>"|) !lines.append(|Set olApp = Nothing|) !lines.append(|objMail.Send()|) !scriptFileOF.writeFile(|OVER|, !lines) -- Convert the file to get rid of any unicode characters !!pmlTranscFile('$!scriptFile', '', '', '', '') -- Execute the script to create the email and send automatically SYSCOM |CSCRIPT "$!<scriptFile>" /x|

And many more…

Page 7: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

Appendix A. Complete code consists of all above parts

--PART1 !folders[1] = 'C:\temp\NIGHT-WORK\DatabaseCheck\' !folders[2] = 'C:\temp\NIGHT-WORK\PipingCheck\' !folders[3] = 'C:\temp\NIGHT-WORK\Review\' !folders[4] = 'C:\temp\NIGHT-WORK\Clashes\' do !x from 1 to !folders.Size() !fo = object file('$!folders[$!x]') if (!fo.Exists().Not()) then !comm = |SYSCOM 'MKDIR $!folders[$!x]'| $!comm endif Enddo

ADMIN EXPUNGE VAR !DBS COLLECT ALL DB do!x from 1 to !DBS.Size() !DBNA = !DBS[!X].Dbref().Name.After('/*') EXPUNGE DB $!DBNA HANDLE (1,271)(1,273) ENDHANDLE ENDDO --PART 2 VAR !DBS COLL ALL DB !outputLOG = object array() !outputLOGFILE = object file('$!folders[1]' + '!TotalLOG-DB.log') VAR !mdbn MDB CHECKOPTION EXT CHECK PREF $!mdbn

do !x from 1 to !DBS.Size() skip if (!DBS[!x].DbRef().Fore EQ 'FOREIGN') !dbName = !DBS[!x].DbRef().Name !nfile = '$!folders[1]' & !DBS[!x].DbRef().Name.After('/*').Replace('/','!') & '.txt' ALPHA LOG/$!nfile OVER HANDLE ANY ALPHA LOG END SKIP ENDHANDLE !dbN = !DBS[!x].DbRef().Name.After('/*') CHECK DB $!dbN HANDLE ANY ALPHA LOG END SKIP ENDHANDLE ALPHA LOG END !logfile = object file(!nfile) !logfileRead = !logfile.ReadFile() if (!logfileRead[!logfileRead.Size() - 1].Matchwild('*Database has no structural errors*').Not()) then !outputLOG.Append('DBS $!dbName : inconsistencies found.. Manual check needed...') endif do !y from 1 to !logfileRead.Size() if (!logfileRead[!y].Matchwild('*invalid*') OR !logfileRead[!y].Matchwild('*unknown*')) then !outputLOG.Append('DBS $!dbName : inconsistencies found.. Manual check needed...') SKIP endif enddo Enddo !outputLOGFILE.WriteFile('OVERWRITE',!outputLOG)

--PART 3 VAR !PROJCODE PROJ CODE !TOEVAL = |VAR !MACFOLDER EVAR '$!PROJCODE| & |MAC'| $!TOEVAL

Page 8: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

!MacroFolder = object file(!MACFOLDER) DESIGN !files = !MacroFolder.Files() if (!files.Size() NEQ 0) then do !x from 1 to !files.Size() !path = !files[!x].String() $M/$!path enddo MONITOR do !x from 1 to !files.Size() DELETE MAC $!x enddo endif --PART 4 DESIGN MAP BUILD MDB HANDLE (69,97) ENDHANDLE --PART 5 ZONE /PIPES !pipes = !!CollectAllFor('PIPE',||,CE) !outputLOG = object array() !outputLOGFILE = object file('$!folders[2]' + '!TotalLOG-PIPES.log') do !x from 1 to !pipes.Size() !nfile = '$!folders[2]' & !pipes[!x].Name.Replace('/','!') & '.txt' ALPHA LOG/$!nfile OVER $!pipes[$!x] VAR !userm USERM VAR !lastm LASTM !user = 'Modified by user: $!userm , $!lastm' $P $!user CHECK CE ALPHA LOG END !logfile = object file(!nfile) !logfileRead = !logfile.ReadFile() if (!logfileRead[!logfileRead.Size()].Matchwild('*NO DATA INCONSISTENCIES*').Not()) then !outputLOG.Append('PIPE $!!CE.Name : inconsistencies found... Manual check needed…') endif enddo !outputLOGFILE.WriteFile('OVERWRITE',!outputLOG) --PART 6 SITE /STABILIZER !CEName = !!CE.Name VAR !projcode PROJ CODE !revFile = object file('$!folders[3]' + '$!projcode' + '_model.rvm') EXPORT FILE/$!revFile OVER EXPORT ENCODING UTFE EXPORT ALL PIPE FOR CE COLOUR 10 EXPORT ALL PIPE WITH (NAME OF ZONE EQ '/CABLETRAY') FOR CE COLOUR 11 EXPORT ALL PIPE WITH (MATCHWILD(NAME,'*A*') AND NAME OF ZONE EQ '/PIPES') FOR CE COLOUR 2 EXPORT ALL PIPE WITH (MATCHWILD(NAME,'*B*') AND NAME OF ZONE EQ '/PIPES') FOR CE COLOUR 3 EXPORT ALL PIPE WITH (MATCHWILD(NAME,'*C*') AND NAME OF ZONE EQ '/PIPES') FOR CE COLOUR 6 EXPORT ALL PIPE WITH (NAME OF ZONE EQ '/HEATING-VENTS') FOR CE COLOUR 12 EXPORT ALL EQUI FOR CE COLOUR 4 EXPORT ALL STRU FOR CE COLOUR 8 EXPORT ALL STRU WITH (NAME OF ZONE EQ '/STEEL' OR NAME OF ZONE EQ '/RACKPIPES') FOR CE COLOUR 7 EXPORT FINISH --PART 7 ADMIN VAR !DBS COLL ALL DB do !x from 1 to !DBS.Size()

Page 9: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

skip if (!DBS[!x].DbRef().Fore EQ 'FOREIGN') !mergewhere = !DBS[!x].DbRef().Name.After('/*') MERGE CHAN $!mergewhere HANDLE (1,18)(1,293) ENDHANDLE enddo PART 8 DESIGN !clashTemplateFile = !folders[4] + 'clashtemplate.tmp' !templData[1] = '$$CLANUM$$ # $$CLATYPE$$' !templData[2] = '$$CLA1$$' !templData[3] = 'with' !templData[4] = '$$CLA2$$' !templData[5] = 'at $$CLAPOS$$' !templData[6] = '--------------' !clashTemplateFileObject = object file(!clashTemplateFile) !clashTemplateFileObject.Writefile('OVERWRITE',!templData) !clashOutputFile = !folders[4] + '!TotalLOG-CLASHES.log' DESCLASH REPORT MACRO /$!clashTemplateFile ALPHA FILE /$!clashOutputFile OVER OVERRIDE ON REMOVE OBST All OBST ALL NOCHECK WITHIN BRAN NOCHECK WITHIN EQUI INCLUDE CONNECTIONS INCLUDE TOUCHES CHECK /STABILIZER ALPHA FILE END REPORT MACRO OFF EXIT --PART 9 MONITOR !emailAddresses = '[email protected];[email protected]' VAR !getPU EVAR PDMSUSER !pdmsuser1 = !getPU.Split()[1] !scriptFile = !pdmsuser1 + |\send-night-report.vbs| !attachment1File = !folders[1] + '!TotalLOG-DB.log' !attachment2File = !folders[2] + '!TotalLOG-PIPES.log' !attachment3File = !folders[4] + '!TotalLOG-CLASHES.log' !scriptFileOF = object FILE(!scriptFile) if (!scriptFileOF.Exists()) then !scriptFileOF.Deletefile() HANDLE ANY ENDHANDLE endif VAR !getU EVAR USERNAME !session = current session var !projCode PROJ CODE !nightDate = object datetime() !nightDateString = !nightDate.String() !lines = OBJECT ARRAY() !lines.append(|Set olApp = CreateObject("Outlook.Application")|) !lines.append(|Set objMail = olApp.CreateItem(olMailItem)|) !lines.append(|objMail.Display|) !lines.append(|Set colAttach = objMail.Attachments|) !lines.append(|Set oAttach = colAttach.Add("| & !attachment1File & |")|) !lines.append(|colAttach.Add("| & !attachment2File & |")|)

Page 10: Final

AVEVA PDMS/MARINE Step-By-Step Tutorial

!lines.append(|colAttach.Add("| & !attachment3File & |")|) !lines.append(|objMail.To = "$!emailAddresses"|) !lines.append(|objMail.Subject = "Night Check Results ( $!nightDateString )"|) !lines.append(|objMail.HTMLBody = "<BODY><p style='font-face:Tahoma; color=#000000 size=12pt;'>" & _ |) !lines.append(|"<b style='font-face:Verdana; color:#ff0000; font-size:12pt;'>Project: </b>| & !projCode & |<br/>" & _ |) !lines.append(|"<b style='font-face:Verdana; color:#ff0000; font-size:12pt;'>MDB: </b>| & !session.mdb().string() & |</p></BODY>"|) !lines.append(|Set olApp = Nothing|) !lines.append(|objMail.Send()|) !scriptFileOF.writeFile(|OVER|, !lines) !!pmlTranscFile('$!scriptFile', '', '', '', '') SYSCOM |CSCRIPT "$!<scriptFile>" /x|

FINISH