trying to run through all files and update drawings

I have added this code to some code to recurse through folder and open each part and update views

' ----------------------------------------------
' Menu: Application->Drafting...
' ----------------------------------------------
Dim drawingSheet1 As Drawings.DrawingSheet = CType(workPart.DrawingSheets.FindObject("DWG"), Drawings.DrawingSheet)

drawingSheet1.Open()

' ----------------------------------------------
' Menu: Application->PMI
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Enter Drafting")

workPart.Views.WorkView.UpdateCustomSymbols()

workPart.Drafting.SetTemplateInstantiationIsComplete(True)

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Update Views")

Dim views1(2) As Drawings.DraftingView
Dim baseView1 As Drawings.BaseView = CType(workPart.DraftingViews.FindObject("TOP@1"), Drawings.BaseView)

views1(0) = baseView
Dim projectedView1 As Drawings.ProjectedView = CType(workPart.DraftingViews.FindObject("ORTHO@3"), Drawings.ProjectedView)

views1(1) = projectedView1
Dim projectedView2 As Drawings.ProjectedView = CType(workPart.DraftingViews.FindObject("ORTHO@2"), Drawings.ProjectedView)

views1(2) = projectedView2
workPart.DraftingViews.UpdateViews(views1)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

But the view names are not always the same---is there a way to use wildcards or some way to ignore the viewname and update any view

Thanks

Brian

Perhaps something like this:

For Each tempSheet As Drawings.DrawingSheet In workPart.DrawingSheets
For Each tempView As Drawings.DraftingView In tempSheet.GetDraftingViews
If tempView.IsOutOfDate Then
tempView.Update()
End If
Next
Next

Awesome----Thanks

and what is the final code ?

Thanks
Heinz

UG since 1978 .... NXjournaling since March 2016

'NXJournaling
'October 26, 2012
'tested on NX 8

'Journal to Cycle All Part Files in a specified folder (with option to include subfolders)
'based on 'cyclePartFiles' code example from GTAC
'
'This journal will prompt for a folder (selection dialog)
'then open each file and perform some action on the file then close the file

Option Strict Off
Imports System
Imports System.IO
Imports System.Collections
Imports System.Windows.Forms

Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF

Module Cycle_Files_and_Folders_b
Dim theSession As Session = Session.GetSession
Dim LW As ListingWindow = theSession.ListingWindow

Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim initialPart As Part = theSession.Parts.Display

Dim nTotalPartFiles As Integer = 0

Sub Main()

Dim strOutputFolder As String
LW.Open()
Try

Dim FolderBrowserDialog1 As New FolderBrowserDialog
' Change the .SelectedPath property to the default location
With FolderBrowserDialog1
' Desktop is the root folder in the dialog.
.RootFolder = Environment.SpecialFolder.Desktop
' Change the following line to default to a given path
.SelectedPath = "C:\"
' Prompt the user with a custom message.
.Description = "Select the directory to scan"
If .ShowDialog = DialogResult.OK Then
' Display the selected folder if the user clicked on the OK button.
'msgbox(.SelectedPath)
strOutputFolder = .SelectedPath
Else
'user pressed "cancel", exit the journal
Exit Sub
End If
End With

LW.WriteLine("Cycle All Parts in a Folder Tree")
LW.WriteLine("Start Time: " & CType(TimeOfDay(), String))
LW.WriteLine("")

processParts(strOutputFolder, False)

LW.WriteLine("")
LW.WriteLine("Total Part Files Scanned: " & nTotalPartFiles)
LW.WriteLine("Stop Time: " & CType(TimeOfDay(), String))

Catch ex As NXException
LW.WriteLine("Cycle Files and Folders Error: " & ex.Message)
Exit Sub
End Try
End Sub

'***************************************************************************
'Process All Parts in a Directory

Sub processParts(ByVal directoryPath As String, ByVal includeSubDirs As Boolean)

Try
Dim nPartFiles As Integer = 0
Dim part1 As Part
Dim files() As String

If includeSubDirs Then
files = Directory.GetFiles(directoryPath, "*.prt", SearchOption.AllDirectories)
Else
files = Directory.GetFiles(directoryPath, "*.prt", SearchOption.TopDirectoryOnly)
End If
For Each fileName As String In files
nPartFiles += 1
nTotalPartFiles += 1
LW.WriteLine(" " & nPartFiles & " " & Path.GetFileName(fileName))

If (IsNothing(initialPart)) OrElse (initialPart.FullPath <> fileName) Then
part1 = theSession.Parts.OpenDisplay(fileName, Nothing)
Else
'LW.WriteLine("initial part equals display part: " & initialPart.Equals(displayPart).ToString)
part1 = displayPart
End If

displayPart = theSession.Parts.Display
workPart = theSession.Parts.Display

'do something
'write your own subroutines and/or functions to process the part and call them from here

For Each tempSheet As Drawings.DrawingSheet In workPart.DrawingSheets
For Each tempView As Drawings.DraftingView In tempSheet.GetDraftingViews
If tempView.IsOutOfDate Then
tempView.Update()
End If
Next
Next

'close file unless this file was initially open
If (IsNothing(initialPart)) OrElse (initialPart.FullPath <> fileName) Then
part1.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.True)
'part1.Close(BasePart.CloseWholeTree.False, BasePart.CloseModified.UseResponses, Nothing)
part1 = Nothing
workPart = Nothing
displayPart = Nothing
End If

If Not IsNothing(initialPart) Then
Dim partLoadStatus1 As PartLoadStatus
Dim status1 As PartCollection.SdpsStatus
status1 = theSession.Parts.SetDisplay(initialPart, False, False, partLoadStatus1)

displayPart = theSession.Parts.Display
partLoadStatus1.Dispose()
theSession.Parts.SetWork(displayPart)
workPart = theSession.Parts.Work
End If

Next fileName
Catch ex As Exception
LW.WriteLine("Part Scan Error: " & ex.Message)
End Try

End Sub

'***************************************************************************
Function CountBodies() As Integer

Dim total As Integer
total = workPart.Bodies.ToArray.Length
Return total

End Function

'***********************************************************************

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

Hello
I am new with journaling ..... so my questions start with simple things
I start the vb program in NX9 without any part open.

I would expect a dialog to select a Directory
but I receive a error message
Line 160: End of statement expected.

Thanks for your Help
Greeting from Germany
Heinz

UG since 1978 .... NXjournaling since March 2016

The last line in the code above has a copy & paste error. It should just read:

End Module

I fixed the original code posting for anyone else who copies it from the site.
and not:

End Module/

It works !
I did not see the option to include subfolders .... may be because I dont have subfolders.

I would like to have a option "Output each Drawing to PDF".

But its Eastern ..... and not Christmas ;-)

Thank you very much !!!!
Heinz

UG since 1978 .... NXjournaling since March 2016

Christmas may have come early for you, Heinz.
The following link will download a zip file of journal files; one of which will process the parts in a given folder and export a pdf file of each.

http://www.nxjournaling.com/downloads/NXJ_PdfExporter.zip

The one you are looking for is called: export_pdf_test_all_parts_in_folder.vb