|
<< Click to Display Table of Contents >> Navigation: Programming Mechworks PDM > DBWCommandShell > Library Reference > Tree > DBWWalkTreeBottomTop |
It walks the child tree or the parent tree of the document with the assigned unique id.
Function DBWWalkTreeBottomTop(DocUID, Parent, OptionalQueryFilter)
DocUID |
It is the unique id of the root document. |
|---|---|
Parent |
<0/1> |
OptionalQueryFilter |
It's a further specification for the tree walking. This it's a part of a query, so you've to set it in this way: " AND <condition> " For example you can specify that you want to search only in certain documents (projects, parts, ...). " AND T='0' " |
![]()
The routine calls the callback user-defined UserProcessDocument routine, passing it the unique id of the current tree node.
The user-defined routine is called first for the deeper tree nodes and then for top-level item nodes, in a bottom-to-top order.
Related commands and functions
A typical example is a script for approving any child document of a currently opened checked-out assembly:
' approveTree.vbs
'
' Author: Ciro Ettorre - MechWorks s.r.l.
'
' This program shows how to approve a whole opened assembly with a one step operation
' The program traverses down the assembly tree, looks for any not-released document
' and approves it in a bottom-to-top way
' It may be extended with a preventive check at the beginning for controlling
' if any not-null field has to be filled before the approval
'
'
totalCount = 0
counter = 0
actionCanceled = false
pass = 0
Sub Main
DBWInit(TRUE)
ok = InputBox("Enter 'ok' to proceed with the approval of this document." & vbcrlf & _
"ATTENTION: the process can be take a long time to complete" )
if ok<>"ok" and ok<>"OK" then
exit sub
end if
docUid = DBWGetActiveDocUid
if docUid = 0 then
MsgBox "Document not found in the database"
end if
wt = DBWGetOption("WAIT_TIME")
nioc = DBWGetOption("NO_INPUT_ON_CHECKIN")
nism = DBWGetOption("NO_INPUT_SAVE_MODE")
DBWSetOption "NO_INPUT_ON_CHECKIN",1
DBWSetOption "NO_INPUT_SAVE_MODE",1
DBWSetOption "WAIT_TIME",100
' first pass to calculate the number of items
totalCount = 0
pass = 1
DBWWalkTreeBottomTop docUid, 0, " AND STATE IN ('NEW','CHECKED_IN','BEING_MODIFIED')"
' second pass to approve
counter = 0
DBWShell("WaitDialogOpen " & replace("Tree Approval"," ","|") & " " & replace("Approval in progress ..."," ","|") )
pass = 2
DBWWalkTreeBottomTop docUid, 0, " AND STATE IN ('NEW','CHECKED_IN','BEING_MODIFIED')"
DBWShell("WaitDialogClose")
DBWSetOption "NO_INPUT_ON_CHECKIN",nioc
DBWSetOption "NO_INPUT_SAVE_MODE",nism
DBWSetOption "WAIT_TIME",wt
end sub
Sub UserProcessDocument(docUid)
state = DBWQueryByUid( docUid, "STATE" )
ok = false
if state = "BEING_MODIFIED" then
if pass = 2 then
DBWShell("OpenDocument " & docUid )
DBWShell("Checkin " & docUid )
ok = okDBW
else
ok = true
end if
elseif state = "NEW" then
if pass = 2 then
DBWShell("OpenDocument " & docUid )
DBWShell("SWSave" )
DBWShell("SWClose" )
DBWShell("IncrementRevisionState " & docUid )
ok = okDBW
else
ok = true
end if
elseif state = "CHECKED_IN" then
ok = true
end if
if ok = true then
if pass = 2 then
DBWShell("WaitDialogPoll " & Clng((counter*100)/totalCount) )
actionCanceled = DBWResult("@CANCELED")
counter = counter+1
DBWShell("IncrementRevisionState " & docUid )
else
totalCount = totalCount+1
end if
end if
end sub