|
<< Click to Display Table of Contents >> Navigation: Programming Mechworks PDM > DBWCommandShell > Event Scripts > BOM > OnEditBomAssignAbsolutePositions.LST script file |
By properly customizing such script, it is possible to alter, with a custom logic, some or all of the PDM generated PARENT_CHILD_BOM_POS values for the currently edited BOM.
Please note that Mechworks PDM fully execute the functionality before invoking the script; in such way, the PARENT_CHILD_BOM_POS are already filled by PDM with their default values, and for such reason the script can alter only the BOM items that needs to be renumbered with a custom logic.
If present in LST\ directory, this script is executed as a post-event of the functionality in the EditBOM dialog.
The following example will renumber the BOM items with their ID field beginning with the string "Brake", by adding them an offset of 500
.VBSCRIPT
sub main()
DBWInit(TRUE)
parentUniqueId = 0
Dim childUniqueIdArray: childUniqueIdArray = Array()
' get the input from Mechworks PDM the parent document unique id
' and the child document unique id list
Set fs = CreateObject("Scripting.FileSystemObject")
Set tfolder = fs.GetSpecialFolder(TemporaryFolder)
Set a = fs.OpenTextFile( tfolder & "\" & "dbwscrpt.in" , ForReading, True )
Dim tokens
Do While a.AtEndOfStream <> True
line = a.ReadLine
tokens = Split( line, "=", 2, 1)
if tokens(0) = "@PARENT_UNIQUE_ID" then
parentUniqueId = tokens(1)
elseif tokens(0) = "@CHILD_UNIQUE_ID" then
ReDim Preserve childUniqueIdArray( UBound(childUniqueIdArray) + 1 )
childUniqueIdArray(UBound(childUniqueIdArray)) = tokens(1)
end if
Loop
a.Close
' if no input exit the script
If ( parentUniqueId = 0 or UBound(childUniqueIdArray) = -1 ) Then
exit sub
end if
' here update the PARENT_CHILD::PARENT_CHILD_BOM_POS field with your own logic
' in this sample we'll update, by adding an offset of 500, the child components where
' their ID begins with the string "Brake"
For i = 0 To UBound(childUniqueIdArray)
DBWShell("GetBOMFieldValue " & childUniqueIdArray(i) & " " & parentUniqueId & " " & DBWLookUp("NAME_FIELD_PARENT_CHILD_BOM_POS") )
absPosNr = DBWResult("@BOM_FIELD_VALUE")
' here apply a custom logic for filtering the child items as per your needs
id = DBWQueryByUid(childUniqueIdArray(i), DBWLookUp("NAME_FIELD_ID"))
id = ucase(id)
if left(id,5) = "BRAKE" then
' here renumber the abs pos as per your needs ( only if not already done )
if cint(absPosNr) < 500 then
newAbsPosNr = cint(absPosNr) + 500
' ... then call the DBW Api for setting the BOM POS
DBWShell("AssignBOMFieldValue " & childUniqueIdArray(i) & " " & parentUniqueId & " " & DBWLookUp("NAME_FIELD_PARENT_CHILD_BOM_POS") & " " & newAbsPosNr )
end if
end if
next
end sub