×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Export Image Macro

Export Image Macro

Export Image Macro

(OP)
I would like a macro that exports an image(jpeg or bitmap), and saves it as the file name on a folder on my desktop in the C: drive.
I am clueless on where I would start to do this and an im need of assistance.

RE: Export Image Macro

(OP)
that is perfect! some minor modifications and I will have myself the macro I have been looking for. Thanks cowski!

RE: Export Image Macro

(OP)
can anyone help me debug this?
I attepted to make a version of the jpeg macro with an output directory that could be chosen every time. If you click cancel it uses the last directory.

Or better yet, is there a way to go up a level in the folder path from where the root part it, and then back down a level to a named folder?
Here is what I have so far, the line below is giving me the issue.
ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.original)

CODE --> vb

' NX 7.5.5.4
'http://www.eng-tips.com/viewthread.cfm?qid=327914&tmac=fav&val=1,327914

Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.Utilities
Imports NXOpen.Layer  

Module Module1  

Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim ufs As UFSession = UFSession.GetUFSession()  
        Dim workPart As Part = theSession.Parts.Work  
        Dim partName As String = Path.GetFileNameWithoutExtension(workPart.FullPath)    
      'turn triad off
        theSession.Preferences.ScreenVisualization.TriadVisibility = 0 
      'directory to output jpegs, change as needed
      'Change the directory to where you would like the picture for now
      'the next update will feature automatic storing into Vantage folders for that job
        Dim folderName As String = "C:"        
        Dim outputDirectory As String = folderName   
        Dim strPartJpg As String = ""  
        Dim wpModelingView As ModelingView
        Dim strCurrentDate as String
        Dim s As Session = Session.GetSession()
        Dim ui As UI = UI.GetUI()
        Dim lw As ListingWindow = s.ListingWindow
        Dim root As Component = s.Parts.Work.ComponentAssembly.RootComponent
        Dim folderBrowserDialog1 As New FolderBrowserDialog
        folderBrowserDialog1.ShowNewFolderButton = False
        Dim result As DialogResult = folderBrowserDialog1.ShowDialog()
        
        If (result = DialogResult.OK) Then
            folderName = folderBrowserDialog1.SelectedPath
        End If
        
        If Not Directory.Exists(outputDirectory) Then  
            MsgBox("The specified directory does not exist, journal will now exit", MsgBoxStyle.Exclamation, outputDirectory & " not found")  
        Exit Sub
        End If   
            strCurrentDate = format(Today, "dd.MM.y")
            strPartJpg = Path.GetFileNameWithoutExtension(workPart.FullPath) & "_" & strCurrentDate & ".jpg"  
            strPartJpg = Path.Combine(outputDirectory, strPartJpg)  
            ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.original) 
      'turn triad on
        theSession.Preferences.ScreenVisualization.TriadVisibility = 1
End Sub  
       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 

RE: Export Image Macro

You save the user's selection as folderName, but then output the jpg to outputDirectory.

The following code fixes that and uses the work part's parent folder as the default directory choice in the folder browser.

CODE

' NX 7.5.5.4
'http://www.eng-tips.com/viewthread.cfm?qid=327914&tmac=fav&val=1,327914

Option Strict Off  
Imports System  
Imports System.IO  
Imports System.Windows.Forms  
Imports NXOpen  
Imports NXOpen.UF  
Imports NXOpen.Assemblies  
Imports NXOpen.Utilities  
Imports NXOpen.Layer  

Module Module1  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim ufs As UFSession = UFSession.GetUFSession()  
        Dim workPart As Part = theSession.Parts.Work  
        Dim partName As String = Path.GetFileNameWithoutExtension(workPart.FullPath)  
 'turn triad off
        theSession.Preferences.ScreenVisualization.TriadVisibility = 0  
 'directory to output jpegs, change as needed
 'Change the directory to where you would like the picture for now
 'the next update will feature automatic storing into Vantage folders for that job
        Dim folderName As String = "C:"  
 'assign output folder to workpart folder
        folderName = Path.GetDirectoryName(workPart.FullPath)  
 'get parent folder (up a level)
        Dim directoryInfo As DirectoryInfo  
        directoryInfo = Directory.GetParent(folderName)  
 'assign the parent folder to folderName
        folderName = directoryInfo.FullName  

        Dim strPartJpg As String = ""  
        Dim strCurrentDate As String = Format(Today, "dd.MM.y")  
        Dim s As Session = Session.GetSession()  
        Dim ui As UI = UI.GetUI()  
        Dim lw As ListingWindow = s.ListingWindow  
        Dim root As Component = s.Parts.Work.ComponentAssembly.RootComponent  
        Dim folderBrowserDialog1 As New FolderBrowserDialog  
        With folderBrowserDialog1  
            .Description = "Specify folder for screenshot output"  
            .ShowNewFolderButton = False  
            .RootFolder = Environment.SpecialFolder.Desktop  
 'use folderName as default directory
            .SelectedPath = folderName  
        End With  

        Dim result As DialogResult = folderBrowserDialog1.ShowDialog()  

        If (result = DialogResult.OK) Then  
            folderName = folderBrowserDialog1.SelectedPath  
        Else  
 'user pressed cancel, exit the journal
            Exit Sub  
        End If  

        If Not Directory.Exists(folderName) Then  
            MsgBox("The specified directory does not exist, journal will now exit", MsgBoxStyle.Exclamation, folderName & " not found")  
            Exit Sub  
        End If  
        strPartJpg = Path.GetFileNameWithoutExtension(workPart.FullPath) & "_" & strCurrentDate & ".jpg"  
        strPartJpg = Path.Combine(folderName, strPartJpg)  
        ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.Original)  
 'turn triad on
        theSession.Preferences.ScreenVisualization.TriadVisibility = 1  
    End Sub  
    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 

www.nxjournaling.com

RE: Export Image Macro

And a photo (JPEG) on NX like Snagit? Custom view and use the mouse for capture the image?

Take out as PDF and JPEG images, to a specific folder.

RE: Export Image Macro

(OP)
There is a folder called "Job_Pictures" under ever every parent. How would I make the pictures automatically go to this folder?

RE: Export Image Macro

Implement the following code (or equivalent) into the journal:

CODE

Dim folderName As String = "C:"  
'assign output folder to workpart folder
folderName = Path.GetDirectoryName(workPart.FullPath)  
'get parent folder (up a level)
Dim directoryInfo As DirectoryInfo  
directoryInfo = Directory.GetParent(folderName)  
'assign the parent folder to folderName
folderName = directoryInfo.FullName  
If IO.Directory.Exists(IO.Path.Combine(directoryInfo.FullName, "Job_Pictures")) Then  
    folderName = IO.Path.Combine(directoryInfo.FullName, "Job_Pictures")  
End If 

www.nxjournaling.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources