OnCopyReleasedFileToSecuredStorageArea.LST script file

<< Click to Display Table of Contents >>

Navigation:  Programming Mechworks PDM > DBWCommandShell > Event Scripts > Database >

OnCopyReleasedFileToSecuredStorageArea.LST script file

available from build: 20040618

Description

The purpose of this script is to take control of the action in the phase when Mechworks PDM copies the released file to the Secured Storage Area.

In that moment it is possible for this script to create a file with a different extension, with the purpose to not directly publish the original copy of the document on the Secured Storage Area. Mechworks PDM updates the FILE_NAME field of the Released Database with the new name produced by the script.

Activation

Options→Environment→Release Database Mode

Remarks

For each file the script is invoked two times:

1.with @CONTEXT=ASSIGN_FILE_NAME

2.with @CONTEXT=COPY_FILE

When in context of COPY_FILE, you can choose to copy or not to copy the file, since the CopyFile action must be performed in the script.

If you want to demand Mechworks PDM to take care of the file copy operations, the script must handle only the @CONTEXT=COPY_FILE case, so not to output the @TO_FILE_PATH for such case:
@CONTEXT=ASSIGN_FILE_NAME → output the @TO_FILE_PATH with the new name
@CONTEXT=COPY_FILE → do not output the @TO_FILE_PATH and exit the sub

LIMITATIONS: this mechanism is FILE BASED and CONFIGURATION INDEPENDENT; it is not currently possible to produce different outputs dependently from different configurations.

Input

@CONTEXT

It can have two values ( the script is called two times ):
"ASSIGN_FILE_NAME" DBWorks requests the script to declare the new file name
"COPY_FILE" DBWorks requests the script to create the new file

@FROM_FILE_PATH

the original, just released, document file path

@TO_FILE_PATH

the destination file path in the Secured Storage Area

Output

@TO_FILE_PATH

Mandatory. The destination file path in the Secured Storage Area

See also

OnPrepareSQLStatementForReleasedDatabase.LST script file

Example

This example shows how to control which additional locations are going to be used for the DBWORKS_RELEASED structure in a production environment with multiple drive letters(N:\, J:\, R:\, S:\, Z:\, and L:\)

Please note that if @CONTEXT=COPY_FILE you've to execute the FileCopy instruction explicitly in the script (but not the DBWCreateDir)

.VBSCRIPT

Sub Main()
 DBWInit(TRUE)
 context = DBWInput("@CONTEXT") 'ASSIGN_FILE_NAME or COPY_FILE
 fromFilePath = DBWInput("@FROM_FILE_PATH")
 If UCase(Left(fromFilePath, 2)) = "N:" Then
  'toFilePath = Replace(DBWInput("@TO_FILE_PATH"),"N:\","I:\")
  toFilePath = Replace(fromFilePath,"N:\","I:\")
 ElseIf UCase(Left(fromFilePath, 2)) = "J:" Then
  toFilePath = Replace(DBWInput("@TO_FILE_PATH"),"J:\","S:\")
 End If
 DBWMsgBox (context & vbcrlf & fromFilePath & vbcrlf & toFilePath)
 If context = "COPY_FILE" Then
  Exit Sub
 Else
  DBWOutput "@TO_FILE_PATH", toFilePath, ForWriting
 End If
End Sub

Example

The following example shows how to write a script that creates a PDF file to be placed in the Secured Storage Area, instead of the original one.

.VBSCRIPT

sub main()
 DBWInit(TRUE)
 context = DBWInput("@CONTEXT") ' ASSIGN_FILE_NAME or COPY_FILE
 fromFilePath = DBWInput("@FROM_FILE_PATH")
 toFilePath = replace( DBWInput("@TO_FILE_PATH"),"\\","\")
 pdfToFilePath = DBWDirNameFromFullName( toFilePath ) & _
   DBWFileNameFromFullName(toFilePath) & ".PDF"
 if context = "COPY_FILE" then
  plotFileDir = DBWDirNameFromFullName( toFilePath )
  ok = CreatePDFFile( fromFilePath, PlotFileDir )
 end if
 DBWOutput "@TO_FILE_PATH",pdfToFilePath,ForWriting
end sub
'______________________________________________________
function CreatePDFFile( fPath, PlotFileDir )
 CreatePDFFile=FALSE
 par_dir = DBWGetOption("PAR_DIR")
 tempplotparfile = par_dir & "tempplot.par"
 call DBWShell("SaveplotSetup " & replace(tempplotparfile," ","|"))
 Set fs = CreateObject("Scripting.FileSystemObject")
 Set tfolder = fs.GetSpecialFolder(TemporaryFolder)
 listplotfile = tfolder & "\plotfile.txt"
 Set a = fs.OpenTextFile( listplotfile, ForWriting, True )
 a.WriteLine( fPath )
 a.Close
 DBWSetOption "PLOT_OUTPUT_DIRECTORY",replace(PlotFileDir," ","|")
 DBWSetOption "PLOT_TO_FILE","1"
 DBWSetOption "SHOW_PRINTER_DIALOG","0"
 DBWSetOption "USE_DRAWING_SHEET_FORMAT","0"
 DBWSetOption "USE_TIF_FORMAT","2" ' PDF Format
 cmd = "plotall " & replace(listplotfile," ","|") & " 1"
 call DBWShell( cmd )
 CreatePDFFile = okDBW
 call DBWShell( "LoadplotSetup " & replace(tempplotparfile," ","|") )
End function