Showing results for 
Search instead for 
Do you mean 
Reply

Sequence of screenshots of machining process

I'm currently working on creating a journal which will batch screenshots into folder for each movement of the tool, for all operations .
I am very new to both journaling and visual basic programming, and following code is as far as I could get: (it does limited amount of screenshots for first several movements, I grabbed some code from NXjournaling forums). 

Anyone knows what to add/fix etc. this code so it could work on any part and do the screenshot for all tool movements? I am guessing I will have to loop somehow, but I don't have enough knowledge of this. Thanks.

 

Option Strict Off
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
 
Module NXJournal
Sub Main (ByVal args() As String) 
 
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
 
Dim displayPart As NXOpen.Part = theSession.Parts.Display
 
' ----------------------------------------------
'   Menu: Tools->Operation Navigator->Tool Path->Simulate...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")
 
Dim kinematicConfigurator1 As NXOpen.SIM.KinematicConfigurator
kinematicConfigurator1 = workPart.KinematicConfigurator
 
Dim objects1(0) As NXOpen.CAM.CAMObject
Dim nCGroup1 As NXOpen.CAM.NCGroup = CType(workPart.CAMSetup.CAMGroupCollection.FindObject("NC_PROGRAM"), NXOpen.CAM.NCGroup)
 
objects1(0) = nCGroup1
Dim isvControlPanelBuilder1 As NXOpen.SIM.IsvControlPanelBuilder
isvControlPanelBuilder1 = kinematicConfigurator1.CreateIsvControlPanelBuilder(NXOpen.SIM.IsvControlPanelBuilder.VisualizationType.ToolPathSimulation, objects1)
 
isvControlPanelBuilder1.SetSingleStep(NXOpen.SIM.IsvControlPanelBuilder.SingleStepType.Block)
 
isvControlPanelBuilder1.SetSpeed(10)
 
theSession.SetUndoMarkName(markId1, "Simulation Control Panel Dialog")
 
theSession.SetUndoMarkVisibility(markId1, Nothing, NXOpen.Session.MarkVisibility.Invisible)
 
Dim simulationOptionsBuilder1 As NXOpen.CAM.SimulationOptionsBuilder
simulationOptionsBuilder1 = isvControlPanelBuilder1.SimulationOptionsBuilder
 
Dim response1 As Integer
response1 = isvControlPanelBuilder1.SetShow3dMaterialRemoval(True)
 
isvControlPanelBuilder1.SingleStepForward()
 ExportScreenshot("''''destination folder''''\Nx_screenshot0001.png")
isvControlPanelBuilder1.SingleStepForward()
 ExportScreenshot("''''destination folder''''\NX_screenshot0002.png")
isvControlPanelBuilder1.SingleStepForward()
 ExportScreenshot("''''destination folder''''\NX_screenshot0003.png")
isvControlPanelBuilder1.SingleStepForward()
 ExportScreenshot("''''destination folder''''\NX_screenshot0004.png")
isvControlPanelBuilder1.SingleStepForward()
 ExportScreenshot("''''destination folder''''\NX_screenshot0005.png")
isvControlPanelBuilder1.SingleStepForward()
 ExportScreenshot("''''destination folder''''\NX_screenshot0006.png")
isvControlPanelBuilder1.SingleStepForward()
 
isvControlPanelBuilder1.SingleStepForward()
 
isvControlPanelBuilder1.SingleStepForward()
 
isvControlPanelBuilder1.SingleStepForward()
 
isvControlPanelBuilder1.SingleStepForward()
 
isvControlPanelBuilder1.SingleStepForward()
 
 
' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
 
End Sub
 
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
 
Sub submain()
 
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If
 
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()
 
        'change export location as needed
        'ExportScreenshot("\\myhome.itap.purdue.edu\myhome\kbernadi\ecn.data\Desktop\testfolder\NX_screenshot.png")
 
        'optional, delete the image file
        'DeleteFile("\\myhome.itap.purdue.edu\myhome\kbernadi\ecn.data\Desktop\testfolder\NX_screenshot.png")
 
        lw.Close()
 
    End Sub
 
Sub ExportScreenshot(ByVal filename As String)
 
        Dim wcsVisible As Boolean = theSession.Parts.Display.WCS.Visibility
        Dim triadVisible As Integer = theSession.Preferences.ScreenVisualization.TriadVisibility
 
 
        Try
            DeleteFile(filename)
 
            theSession.Parts.Display.WCS.Visibility = False
            theSession.Preferences.ScreenVisualization.TriadVisibility = 0
 
            theUfSession.Disp.CreateImage(filename, UFDisp.ImageFormat.Png, UFDisp.BackgroundColor.White)
        Catch ex As Exception
            MsgBox(ex.Message & ControlChars.NewLine & _
                   "'" & filename & "' could not be created")
            'Return
 
        Finally
            theSession.Parts.Display.WCS.Visibility = wcsVisible
            theSession.Preferences.ScreenVisualization.TriadVisibility = triadVisible
 
        End Try
 
        'copy image to clipboard
        Dim theImage As Bitmap = CType(Image.FromFile(filename), Bitmap)
        Clipboard.SetImage(theImage)
 
    End Sub
 
Sub DeleteFile(ByVal filePath As String)
 
        'does file exist? if so, try to delete it (overwrite)
        If IO.File.Exists(filePath) Then
            IO.File.Delete(filePath)
        End If
 
    End Sub
 
Public Function GetUnloadOption(ByVal dummy As String) As Integer
 
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
 
    End Function
 
End Module
2 REPLIES

Re: Sequence of screenshots of machining process

[ Edited ]

For cycling all operations, look in the UGOPEN\SampleNXOpenApplications\.NET\CAM  folder for samples with "CycleAll" in the name.  Another option is to have the user select the program or operation, and then run your program.

The looping is straight vb - I am sure there are several ways to do it. I always look at other programs or search online. If you don't get help here, search the UGOPEN samples or online in the Knowledge base. 

I would be very concerned with the volume of tool motions. Can you save 100,000 images? 

I am curious why you are doing this. We usually see users that want a picture at a collision, or tool change, or some significant event - not every motion.

Mark Rief
Retired Siemens

Re: Sequence of screenshots of machining process

Thanks for the reply! I'll check "cycleAll" section you mentioned ASAP!

 

I'm having trouble with user selecting program, since I used journaling to record and add some vb code after to achieve the result, and I'm encountering selection stickiness. 

 

Reason I'm grabbing all screenshots is because I simply couldn't find efficient way of automating creating pictures of specifically on collision+tool change+etc (I started looking into NX journaling/programming not long ago, still very new), but if there is a way to do it this would be awesome.