×
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

NX6 jpeg default directory

NX6 jpeg default directory

NX6 jpeg default directory

(OP)
The default location for a jpeg image is the ugii directory.
Is there way to change that location to something else?
I have looked as many places as I could think of, including the customer defaults, and cannot find where to change it.

RE: NX6 jpeg default directory

For what purpose? Import? Export? UI?

Mark Rief
Product Manager
Siemens PLM

RE: NX6 jpeg default directory

(OP)
To export.
I want to make a macro that saves pictures at differnt angles of several versions of designs that we have.
There will be well over 300 pictures total. The macro I have now only saves them to ugii.
The difficulty in creating the macro is being able to specify what directory the macro puts them in - but when I need to change the directory I may put the path name in a text file and have the macro read it from there.

RE: NX6 jpeg default directory

Here is a quick journal to get you started. It outputs each of the saved views to a jpeg in the specified directory.

CODE

Option Strict Off  
Imports System  
Imports System.IO  
Imports NXOpen  
Imports NXOpen.UF  

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)  

 'directory to output jpegs, change as needed
        Dim outputDirectory As String = "C:\temp"  
        Dim strPartJpg As String = ""  

        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  

        Dim wpModelingView As ModelingView  
        For Each wpModelingView In workPart.ModelingViews  
            workPart.Views.WorkView.Orient(wpModelingView.Name, View.ScaleAdjustment.Fit)  
            strPartJpg = partName & "_" & wpModelingView.Name & ".jpg"  
            strPartJpg = Path.Combine(outputDirectory, strPartJpg)  
            ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)  
        Next  


    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 

Change the highlighted line to point to the directory of your choice.
If this is along the lines of what you are looking for, we can improve it with the features you need.

www.nxjournaling.com

RE: NX6 jpeg default directory

There is an old feature / function to set up a html template to document models and assemblies. In that template one can define how a number of screenshots should be taken. It will ootb then create a html page, and create the needed screenshots.
I think the product was called UG / Webexpress some 10-15 years ago. I think it's available under file - export - author HTML.
What one need to do is edit a ".htt" ( The html template) to set the image preferences.

Regards,
Tomas

RE: NX6 jpeg default directory

Hi Cowski,

Is there any way to add these JPEG shots to an HTML or a PDF file directly?

If you have 50 views, is a nightmare to organize them properly...

Thanks.

RE: NX6 jpeg default directory

Quote (berri2)

Is there any way to add these JPEG shots to an HTML or a PDF file directly?

Yes.
Do you have an example of the format you are looking for?

www.nxjournaling.com

RE: NX6 jpeg default directory

Something along the lines of this?

CODE

'NXJournaling.com
'March 21, 2012
'Journal purpose: export shaded model views to a pdf file
'  the journal creates an "A" or "A4" size sheet for each model view, places
'  the view on the sheet and scales it to fit. The journal then exports all
'  the sheets to the specified pdf file

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

Module Export_Shaded_pdf  

    Dim theSession As Session = Session.GetSession()  
    Dim workPart As Part = theSession.Parts.Work  
    Dim ufs As UF.UFSession = UF.UFSession.GetUFSession()  

    Dim pdfSheets As New ArrayList  

    Sub Main()  

        Dim markId1 As Session.UndoMarkId  
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")  
        theSession.SetUndoMarkName(markId1, "pdf_sheets")  

        Dim pdfSheet As Drawings.DrawingSheet  
        Dim outputFileName(1) As String  
        Dim pdfFile As String  

        Dim wpModelingView As ModelingView  
        For Each wpModelingView In workPart.ModelingViews  
 'create new sheet for view
            pdfSheet = CreateSheet()  
            pdfSheet.SetName(wpModelingView.Name)  
 'add view to new sheet
            AddView(wpModelingView, pdfSheet)  
            pdfSheets.Add(pdfSheet)  
        Next  

        outputFileName(0) = OutputPath()  
        outputFileName(1) = Path.GetFileNameWithoutExtension(workPart.FullPath) & ".pdf"  
        pdfFile = Path.Combine(outputFileName(0), outputFileName(1))  

        If My.Computer.FileSystem.FileExists(pdfFile) Then  
            My.Computer.FileSystem.DeleteFile(pdfFile)  
        End If  

 'output new sheets to pdf
        Try  
            Call CreatePDF(pdfFile)  
        Catch ex As UnauthorizedAccessException  
            MessageBox.Show("You do not have permission to write to this directory", "PDF file creation error", MessageBoxButtons.OK, MessageBoxIcon.Error)  
        Catch ex As ApplicationException  
            MessageBox.Show(ex.Message, "PDF file creation error", MessageBoxButtons.OK, MessageBoxIcon.Error)  
        End Try  

 'optional: delete pdf sheets
        Dim markId2 As Session.UndoMarkId  
        markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete")  

        Dim objects1(pdfSheets.Count - 1) As NXObject  
        For i As Integer = 0 To pdfSheets.Count - 1  
            objects1(i) = pdfSheets.Item(i)  
        Next  
        pdfSheets.Clear()  

        Dim nErrs1 As Integer  
        nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1)  

        Dim notifyOnDelete2 As Boolean  
        notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete  

        Dim nErrs2 As Integer  
        nErrs2 = theSession.UpdateManager.DoUpdate(markId2)  


    End Sub  

    Public Function CreateSheet() As Drawings.DrawingSheet  
 ' ----------------------------------------------
 '   Menu: Insert->Sheet...
 ' ----------------------------------------------

 'Dim markId1 As Session.UndoMarkId
 'markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

        Dim nullDrawings_DrawingSheet As Drawings.DrawingSheet = Nothing  

        Dim drawingSheetBuilder1 As Drawings.DrawingSheetBuilder  
        drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(nullDrawings_DrawingSheet)  

        drawingSheetBuilder1.Option = Drawings.DrawingSheetBuilder.SheetOption.StandardSize  
 'start with 1:1 scale sheet, view will be scaled to fit later
        drawingSheetBuilder1.ScaleNumerator = 1.0  
        drawingSheetBuilder1.ScaleDenominator = 1.0  

        If workPart.PartUnits = Part.Units.Inches Then  
            drawingSheetBuilder1.Units = Drawings.DrawingSheetBuilder.SheetUnits.English  
 'insert standard letter size sheet
            drawingSheetBuilder1.Height = 8.5  
            drawingSheetBuilder1.Length = 11.0  
Else  'metric unit file
            drawingSheetBuilder1.Units = Drawings.DrawingSheetBuilder.SheetUnits.Metric  
 'insert standard A4 size sheet
            drawingSheetBuilder1.Height = 210  
            drawingSheetBuilder1.Length = 297  
        End If  

 'sheetLength = drawingSheetBuilder1.Length
 'sheetHeight = drawingSheetBuilder1.Height

        drawingSheetBuilder1.ProjectionAngle = Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third  

        Dim pdfSheet As Drawings.DrawingSheet  
        pdfSheet = drawingSheetBuilder1.Commit()  

 'theSession.SetUndoMarkName(markId1, "##01Sheet")

        drawingSheetBuilder1.Destroy()  

        Return pdfSheet  

    End Function  

    Public Sub AddView(ByVal view As ModelingView, ByVal sheet As Drawings.DrawingSheet)  
 ' ----------------------------------------------
 '   Menu: Insert->View->Base...
 ' ----------------------------------------------
 'Dim markId3 As Session.UndoMarkId
 'markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

        sheet.Open()  

        Dim nullDrawings_BaseView As Drawings.BaseView = Nothing  

        Dim baseViewBuilder1 As Drawings.BaseViewBuilder  
        baseViewBuilder1 = workPart.DraftingViews.CreateBaseViewBuilder(nullDrawings_BaseView)  

        baseViewBuilder1.SelectModelView.SelectedView = view  

 'theSession.SetUndoMarkName(markId3, "Base View Dialog")

        baseViewBuilder1.Style.ViewStyleBase.Part = workPart  

        baseViewBuilder1.Style.ViewStyleBase.PartName = workPart.FullPath  

        Dim arrangement1 As Assemblies.Arrangement = workPart.ComponentAssembly.ActiveArrangement  

        baseViewBuilder1.Style.ViewStyleBase.Arrangement.SelectedArrangement = arrangement1  

        baseViewBuilder1.Style.ViewStyleShading.RenderingStyle = Preferences.ShadingRenderingStyleOption.FullyShaded  

 'place the view in the center of the sheet
        Dim point1 As Point3d = New Point3d(sheet.Length / 2, sheet.Height / 2, 0.0)  
        baseViewBuilder1.Placement.Placement.SetValue(Nothing, workPart.Views.WorkView, point1)  

        Dim baseView1 As Drawings.BaseView  
        baseView1 = baseViewBuilder1.Commit()  

 'theSession.SetUndoMarkName(markId3, "Base View")

        Dim viewSize(3) As Double  
 'retrieve the size of the view
        ufs.Draw.AskViewBorders(baseView1.Tag, viewSize)  
        Dim viewLength As Double = viewSize(2) - viewSize(0)  
        Dim viewHeight As Double = viewSize(3) - viewSize(1)  

 'change scale of view so that it fits on 90% of the selected sheet size
        baseView1.Style.General.Scale = Math.Min((sheet.Length * 0.9) / viewLength, (sheet.Height * 0.9) / viewHeight)  

        baseView1.Commit()  

        baseViewBuilder1.Destroy()  

    End Sub  

    Public Sub CreatePDF(ByVal outputFile As String)  
        Dim printPDFBuilder1 As PrintPDFBuilder  

        printPDFBuilder1 = workPart.PlotManager.CreatePrintPdfbuilder()  
        printPDFBuilder1.Scale = 1.0  
        printPDFBuilder1.Action = PrintPDFBuilder.ActionOption.Native  
        printPDFBuilder1.Colors = PrintPDFBuilder.Color.BlackOnWhite  
        printPDFBuilder1.Size = PrintPDFBuilder.SizeOption.ScaleFactor  
        printPDFBuilder1.Units = workPart.PartUnits  
 'If units = 0 Then
 '    printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.English
 'Else
 '    printPDFBuilder1.Units = PrintPDFBuilder.UnitsOption.Metric
 'End If
        printPDFBuilder1.XDimension = pdfSheets.Item(1).Height  
        printPDFBuilder1.YDimension = pdfSheets.Item(1).Length  
        printPDFBuilder1.OutputText = PrintPDFBuilder.OutputTextOption.Polylines  
        printPDFBuilder1.RasterImages = True  
        printPDFBuilder1.ImageResolution = PrintPDFBuilder.ImageResolutionOption.Medium  
        printPDFBuilder1.Append = True  
        printPDFBuilder1.AddWatermark = False  

        Dim sheets1(pdfSheets.Count - 1) As NXObject  
 'Dim drawingSheet1 As Drawings.DrawingSheet = CType(dwg, Drawings.DrawingSheet)
        For i As Integer = 0 To pdfSheets.Count - 1  
            sheets1(i) = pdfSheets.Item(i)  
        Next  

 'sheets1(0) = drawingSheet1
        printPDFBuilder1.SourceBuilder.SetSheets(sheets1)  

        printPDFBuilder1.Filename = outputFile  
 'printPDFBuilder1.Filename = "C:\Temp\test.pdf"

        Dim nXObject1 As NXObject  
        nXObject1 = printPDFBuilder1.Commit()  

        printPDFBuilder1.Destroy()  

    End Sub  

    Function OutputPath()  
 'Requires:
 '    Imports System.IO
 '    Imports System.Windows.Forms
 'if the user presses OK on the dialog box, the chosen path is returned
 'if the user presses cancel on the dialog box, 0 is returned

        Dim strLastPath As String  
        Dim strOutputPath As String  

 'Key will show up in HKEY_CURRENT_USER\Software\VB and VBA Program Settings
        Try  
 'Get the last path used from the registry
            strLastPath = GetSetting("NX journal", "Export pdf", "ExportPath")  
 'msgbox("Last Path: " & strLastPath)
        Catch e As ArgumentException  
        Catch e As Exception  
            msgbox(e.GetType.ToString)  
        Finally  
        End Try  

        Dim FolderBrowserDialog1 As New FolderBrowserDialog  

 ' Then use the following code to create the Dialog window
 ' Change the .SelectedPath property to the default location
        With FolderBrowserDialog1  
 ' Desktop is the root folder in the dialog.
            .RootFolder = Environment.SpecialFolder.Desktop  
 ' Select the D:\home directory on entry.
            If Directory.Exists(strLastPath) Then  
                .SelectedPath = strLastPath  
            Else  
                .SelectedPath = Environment.SpecialFolder.MyDocuments  
            End If  
 ' Prompt the user with a custom message.
            .Description = "Select the directory to export .pdf file"  
            If .ShowDialog = DialogResult.OK Then  
 ' Display the selected folder if the user clicked on the OK button.
                OutputPath = .SelectedPath  
 ' save the output folder path in the registry for use on next run
                SaveSetting("NX journal", "Export pdf", "ExportPath", .SelectedPath)  
            Else  
 'user pressed 'cancel', exit the subroutine
                OutputPath = 0  
            End If  
        End With  

    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 

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