Build hierarchical structure of documents sample

<< Click to Display Table of Contents >>

Navigation:  Programming Mechworks PDM > DBWCommandShell > Examples >

Build hierarchical structure of documents sample

This example shows how to build a hierarchical structure of generic documents (in this case .doc documents, but can be generalized to any kind). The code of the InsertGenericDocument function shows how to create a precise number of instances of the same document (useful for an exact BOM output)

Sub main()

 DBWInit(TRUE)
 noinputonsaveold = DBWGetOption( "NO_INPUT_SAVE_MODE" )
 DBWSetOption  "NO_INPUT_SAVE_MODE", "1"
 waitTimeOld = DBWGetOption( "WAIT_TIME" )
 DBWSetOption  "WAIT_TIME", "10"
 projectName = "testProject"
 projectType = "0"
 DBWShell("CreateNewProject " & projectName )
 projectUid = DBWQuery( projectName & " " & projectType , DBWLookUp("NAME_FIELD_UNIQUE_ID") )
 rootUid = InsertGenericDocument( "f:\dbworks\Root.doc" , projectUid, 1 )
  tempUid = InsertGenericDocument( "c:\mydocs\FirstLevel01.doc", rootUid, 1 )
  tempUid = InsertGenericDocument( "c:\mydocs\FirstLevel02.doc", rootUid, 3 )
  tempUid = InsertGenericDocument( "c:\mydocs\FirstLevel03.doc", rootUid, 5 )
  firstLevel04Uid = InsertGenericDocument( "c:\mydocs\FirstLevel04.doc", rootUid, 1 )
   tempUid = InsertGenericDocument( "c:\mydocs\SecondLevel01.doc", firstLevel04Uid, 3 )
   tempUid = InsertGenericDocument( "c:\mydocs\SecondLevel02.doc", firstLevel04Uid, 2 )
   tempUid = InsertGenericDocument( "c:\mydocs\SecondLevel03.doc", firstLevel04Uid, 10 )
   tempUid = InsertGenericDocument( "c:\mydocs\SecondLevel04.doc", firstLevel04Uid, 5 )
   tempUid = InsertGenericDocument( "c:\mydocs\SecondLevel05.doc", firstLevel04Uid, 2 )
  tempUid = InsertGenericDocument( "c:\mydocs\FirstLevel05.doc", rootUid, 1 )
  tempUid = InsertGenericDocument( "c:\mydocs\FirstLevel06.doc", rootUid, 4 )
  tempUid = InsertGenericDocument( "c:\mydocs\FirstLevel07.doc", rootUid, 2 )
 DBWSetOption  "NO_INPUT_SAVE_MODE", noinputonsaveold
 DBWSetOption  "WAIT_TIME", waitTimeOld
 DBWShell("Wait 1000")
End Sub
Function InsertGenericDocument( FullPathName , ParentUniqueId , numberOfInstances )
 dirName = DBWDirNameFromFullName( FullPathName )
 fileName = DBWFileNameFromFullName( FullPathName )
 docId = DBWGetIdFromFullFileName( dirName, fileName, docUid )
 if docUid>0 then
  DBWShell("DeleteParentChild " & docUid )
 end if
 DBWShell("AddDocument " & FullPathName & " " & ParentUniqueId )
 InsertGenericDocument = DBWResult("@DOCUMENT_UNIQUE_ID")
 if numberOfInstances >= 2 then
  for i=2 to numberOfInstances
   DBWShell("AddDocument " & FullPathName & " " & ParentUniqueId )
  next
 end if
End function