Batch appending files to nwf and save to nwd by VBScript

By Xiaodong Liang

Issue
Is there a way through VBScript to publish a directory of dwg's to an single .nwd file?

Solution
Navisworks can append the same file more than once without warning. You need to use code to check if the file has been existed. roamer.state.CurrentPartition (InwOaPartition) returns the top level access to the current model. if any files are appended, InwOaPartition.Children will tell each file. So you can use InwOaPartition.FileName to check if the file existed or not. The attached VBS checks if C:\temp\1.dwg1 has been appended to the main nwf.

Please note: the string in VBS is case sensitive.

' ########test.vbs##########

''Usage:
'AppendFiles.vbs <main_filename>  <file_Name1>  <file_Name2> 
'example:
'AppendFiles.vbs "c:\temp\main.nwf" "c:\temp\1.dwg"  "c:\temp\2.dwg"

' navisworks application
dim roamer'
' input argument
dim arg_in
dim file_Name1
dim file_Name2
dim count

' top api object
dim oState

' root partition
dim oPartition
' each partition if more than one files within the document
dim oEachPartition

' the file has been appended?
dim hasDWG1

 
' get inputs 
count=WScript.Arguments.Count
' document
arg_in=WScript.Arguments(0)
' file 1
file_Name1 =WScript.Arguments(1)
' file2
file_Name2 =WScript.Arguments(2)
 
'create roamer via automation
set roamer=createobject("navisWorks.document")   

'open input file
roamer.openfile arg_in
 
hasDWG1 = false
for each   oEachPartition in roamer.state.CurrentPartition.Children
  msgbox "each file in the main nwf: " & oEachPartition.Filename
  if oEachPartition.Filename = "C:\temp\1.dwg" then
     hasDWG1 = true
     msgbox "DWG1 has been appended!"
  end if
next

' if the file has Not been appended
if hasDWG1 = false then
  roamer.appendfile file_Name1
  msgbox "append DWG1"
end if
 
' append file 2 without checking
roamer.appendfile file_Name2

' save to the nwd
roamer.saveas  "c:\temp\test.nwd"
 
msgbox "end"


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading