DBWWalkTreeAllInstances

<< Click to Display Table of Contents >>

Navigation:  Programming Mechworks PDM > DBWCommandShell > Library Reference > Tree >

DBWWalkTreeAllInstances

Description

Walks over every instance of the components of an assembly, permitting a correct BOM to be calculated

Syntax

Sub DBWWalkTreeAllInstances(DocUID, Parent, OptionalQueryFilter)

Parameters

DocUID

It is the unique id of the root document.

Parent

<0/1>
If set to 0 it traverses document child tree.
If set to 1 it traverses document parent tree.

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, ...).
You have to set the variable as

" AND T='0' "

Remarks

checkThe difference between DBWWalkTree function and DBWWalkTreeAllInstances is about the number of callback you obtain during the walkthrough.
Suppose to have an assembly A composed of two parts P1 and P2 of respectively 5 and 10 instances.
 
With DBWWalkTree function you obtain 3 callbacks:

1 for assembly A

1 for part P1

1 for part P2

With DBWWalkTreeAllInstances you obtain 16 callbacks:

1 for assembly A

5 for part P1

10 for part P2

This function is useful for example to calculate the weight of an assembly.

See also

Related commands and functions

Example

Please note the example, it's very explanatory.

You must use a sub called UserProcessDocument to execute actions while traversing the tree; it is run for each node of the tree you traverse.
As you can note, in the sub main there is only a call to DBWWalkTreeAllInstances with parameters, the whole processese are exeuted in the UserProcessDocument sub.

Please note also the DBWStopProcessing statement. It stops the tree traversing.

Sub Main
 DBWInit(True)
 DBWShell("CurrentDocument")
 uid = DBWResult("@DOCUMENT_UNIQUE_ID")
 DBWWalkTreeAllInstances uid, 0, ""
end sub
'call back for the DBWWalkTreeAllInstances
sub UserProcessDocument( uid )
 state = DBWQueryByUid( uid, DBWLookUp("NAME_FIELD_STATE") )
 if state = DBWLookUp("NAME_STATE_NEW_STRING") or state = DBWLookUp("NAME_STATE_BEING_MODIFIED") then
  id = DBWQueryByUid( uid, DBWLookUp("NAME_FIELD_ID") )
  fileName = DBWQueryByUid( uid, DBWLookUp("NAME_FIELD_FILE_NAME") )
  fileDir = DBWQueryByUid( uid, DBWLookUp("NAME_FIELD_FILE_DIRECTORY") )
  MsgBox "Document ID=" & id & " File=" & fileDir & fileName & " is still in a MODIFIABLE state"
  DBWStopProcessing = True
 end if
end sub