|
<< Click to Display Table of Contents >> Navigation: Programming Mechworks PDM > DBWCommandShell > Examples > plotlist file example |
This example shows how to execute a command script on a remote machine.
Specifically, here you find code to print some document on a remote plotting device.
'this file must be shared with other users but make sure they won't overwrite it if it's in use by someone else.
plotListFilePath = "D:\plotlist.txt"
destinationUserName = "PlotServer"
Dim fs
sub main
DBWInit(True)
Set fs = CreateObject("Scripting.FileSystemObject")
'get selected document for plotting
DBWShell("GetSelection")
if (okDBW) then
selection = DBWResult("@SELECTION")
if selection = "" then
DBWMsgBox "Please select the documents you want to plot."
exit sub
end if
'put selected document in an array
Dim uidArray
uidArray = Split(selection,",", -1, 1)
ub = UBound(uidArray)
if ub = 0 then ' only one element
uidArray = Array(Cint(selection))
ub = 1
end if
if ub>0 then
'delete a previous version of plotfile
if fs.FileExists( plotListFilePath ) then
fs.DeleteFile( plotListFilePath )
end if
'fill the plotlist file with full path file names
for i=0 to ub
fName = DBWQueryByUid(uidArray(i),DBWLookUp("NAME_FIELD_FILE_NAME"))
fDir = DBWQueryByUid(uidArray(i),DBWLookUp("NAME_FIELD_FILE_DIRECTORY"))
fPath = fDir+fName
addFileToPlotList( fPath )
next
'ask for confirmation
res = DBWMsgBox( (ub+1) & " documents will be plotted on workstation " & destinationUserName & vbcrlf & "Confirm ?",4)
if res = 6 then
createAndSendCommandFile
end if
end if
end if
end sub
'this sub write a line in the command script
Sub addFileToPlotList( filePath )
Set a = fs.OpenTextFile( plotListFilePath, ForAppending, True )
a.WriteLine( filePath )
a.Close
End Sub
'this sub is called if you confirm the plotting
Sub createAndSendCommandFile()
'write a special file (for command execution) in the temporary folder
Set tfolder = fs.GetSpecialFolder(TemporaryFolder)
commandFileName = tfolder & "\!COMMAND.!!!"
Set a = fs.OpenTextFile( commandFileName, ForWriting, True )
a.WriteLine( "ExecScript PlotServer.vbs" )
a.Close
'run the command script on the user machine
DBWShell("SendCommandMessageToUser " & replace(commandFileName," ","|") & " " & destinationUserName )
End Sub
This the vbs script file. It simply reads the plotlist file and sends entries to the plot device.
plotListFilePath = "D:\plotlist.txt"
sub main()
'retrieve the plotlist file.
Set fso = CreateObject("Scripting.FileSystemObject")
if fs.FileExists( plotListFilePath ) then
Set a = fs.OpenTextFile( plotListFilePath, ForReading, True )
linea = a.readline
DBWShell("PlotAll " & plotListFilePath & " 1") '1 = avoid to ask confirmation for each print
a.close
set a = nothing
end if
set fso = nothing
end sub