Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all articles
Browse latest Browse all 783

Creating a screenshot for each tool movement while machining simulation

$
0
0

I'm currently working on creating a journal which will batch screenshots into folder for each movement of the tool, for all operations (ultimately to create work instructions without using "work instructions authoring" which I don't have).
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, thanks for the guy who posted screenshot journal before).

Anyone knows how 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

Viewing all articles
Browse latest Browse all 783

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>