|
<< Click to Display Table of Contents >> Navigation: »No topics above this level« Intercept 'Save as...' to set field values automatically |
The file DATAENTR.LST, if previously activated, allows you to define the behavior of MechworksPDM when you save a document in the CAD. In particular this file, via scripting, allows you to fill in field values automatically and establish editing rules at save time.
If you want MechworksPDM to enable the interpretation and execution of the file DATAENTR.LST, which you can freely modify, in SolidWorks click DBWorks, Options... and in the dialog click the tab Save as. Ensure that the option Use 'DATAENTR.LST' data entry script on 'Save as...' is checked:
You need to check the option Always Start the 'Save Wizard' if Document Not Exists in Database if you like to call the SaveWizard when a document does not exist in the database.
By default the file
DATAENTR.LST defines a procedure that calls the SaveWizard and then, using the results from the choices of the user fills some fields not directly affected, like description.
.VBSCRIPT
'-------------------------------------------------------------------------------------
' field data entry routines
'
Sub Main()
read the parameters from MechworksPDM
obtain the value for the document type end put into the variable docExt
docExt = DBWInput("@DOCUMENT_TYPE")
currProj = DBWInput("@CURRENT_PROJECT") obtain the value for the current project end put into the variable currProj
Dim progetti
progetti = ArrayFromProjects() call the function to make an array out of the MechworksPDM project variable
set objDBForm = CreateObject("DBWExternalForm.IOWizard") call the wizard, but don't display it: before I need to pass over information
objDBForm.DocumentType = docExt
objDBForm.projects = progetti
objDBForm.currentProject = currProj
wait for the wizard to finish
if objDBForm.testDatabaseStructure then if the structure is ok...
objDBForm.ShowForm ...I can display the wizard on screen
VBScript cannot catch objects'events out
of a web page. Make an indefinite loop instead
while objdbform.finished = false
wend
if user canceled, then PathComplete must be = ""
PathComplete = objDBForm.CompletePath
manipulate data here
retrieve information about the users's choices
CompletePath = objDBForm.CompletePath
SimpleDir = objDBForm.SimpleDir
SimpleFileName = objDBForm.SimpleFileName
CompleteFileName = objDBForm.CompleteFileName
Code = objDBForm.SimpleCode
Serial = objDBForm.Serial
Project = objDBForm.currentProject
Choices = objDBForm.Choices
Codes = objDBForm.Codes
Titles = objDBForm.CatTitles
I customize the value of a field calculating it as a list of the user's choices
Description = CustomizeFieldDescription(Titles, Choices, Codes )
finally release the wizard object
set objDBForm = nothing
send data back to MechworksPDM after manipulation
if PathComplete <> "" then ' process not canceled
DBWOutput "ID", SimpleFileName, ForWriting
DBWOutput "DESCRIPTION", Description, ForAppending
DBWOutput "FILE_NAME", CompleteFileName , ForAppending
DBWOutput "FILE_DIRECTORY", SimpleDir , ForAppending
DBWOutput "CATEGORY", Category , ForAppending
DBWOutput "@CURRENT_PROJECT",Project, ForAppending
end if
end if
End Sub
functions called along the way
Function ArrayFromProjects()
progetti = Array(1)
i = 1
Do
progetto = DBWInput("@PROJECT" & CStr(i))
if progetto <> "" then
ReDim Preserve progetti(i)
progetti(i) = progetto
end if
i = i + 1
Loop Until progetto = ""
ArrayFromProjects = progetti
End Function
Function CustomizeFieldDescription(Titles,Choices,Codes)
if UBound(Titles) > 0 Then
Description = Titles(1) & "=" & Choices(1)
Category = Choices(1)
if UBound(Codes) > 1 then
for i = 2 to UBound(Codes) ' User's choices one by one
Description = Description & ", " & Titles(i) & "=" & Choices(i)
Category = Category & "\" & Choices(i)
next
end if
end if
CustomizeFieldDescription = Description
End Function
'End
This example is very important as it shows how to call the Save/Open Wizard and to retrieve the selected choices of the user for performing calculations. It is also a good example of 'reading' MechworksPDM fields and setting back their values.
If you need to modify some fields values or you want to perform some data validation or calculations after calling the save Wizard, we suggest that you identify the section of code in the existing DATAENTR.LST and modify it after making a backup copy of the file.
If, on the other hand, you want to recreate a file from scratch to call other applications and/or perform complex calculations where the Save Wizard is not called, please note that the lines of code marked in the earlier listing in bold need to be inserted into your new instance of the file.
Please keep in mind that the Windows Scripting Host version of VBScript redistributed by MechWorks is not limited in its features by security reasons and can therefore have full access both to the disk and to the registry as well as command any other external application which exposes itself as a COM object, including SolidWorks.
As displayed in the red lines of the sample, you can set the value of any document field for the current record. The values set here will be displayed in the data form before being written into the database after confirmation.
For further information please refer to the MechworksPDM scripting help and to the scripting section of the Microsoft web site.
If the DATAENTR.LST script outputs a @OKDATA=1 line, the standard input form that automatically appears after the script execution is automatically confirmed (as if pressing the OK button).
A simple example of content of DATAENTR.LST that confirms data automatically is the following:
.VBSCRIPT
sub main()
Set wshell = CreateObject("WScript.Shell")
wshell.Run "F:\dbworks\lst\dataentr.exe",1,True
DBWOutput "@OKDATA","1",ForAppending
Set wshell = Nothing
end sub
Please note in this example how an executable is run for all the interaction that should be made for assigning a new file name.
The DATAENTR.LST script can be used to assign the correct part number to a new configuration created in a CHECKED-OUT opened model.
The DATAENTR.LST script is responsible of assigning the correct part number; in the special case that the file name is the same as the one received as an input parameter, MechworksPDM understands that this is intentionally a request of creating a new part number for an already existing configured file.
In this case, MechworksPDM creates a new configured record, properly aligned with all the revisions needed, before displaying the standard "Save As." input form, that, in this case, with a YELLOW background color.
Pressing the CANCEL button removes the pre-inserted configured record.
The introduction of the new parameter permits to assign the initial tab of the data input form displayed after the Save Wizard category selection.
Example: suppose you have a data input form with a tab named "Classification"; suppose you want this tab to be displayed immediately after the Save Wizard category selection process.
Then, in the DataEntr.LST script, you must add the following output (normally after the assignment of the project):
..
DBWOutput "@CURRENT_PROJECT",choosed_project, ForAppending
DBWOutput "@CURRENT_INPUT_FORM_TAB","Classification", ForAppending
..