×
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 pdf from modeling, with dim or hidden edges?
2

Export pdf from modeling, with dim or hidden edges?

Export pdf from modeling, with dim or hidden edges?

(OP)
Is it possible in NX8?
Thanks in advance

----
kukelyk

RE: Export pdf from modeling, with dim or hidden edges?

Yes it is possible, but there is a bit of prep work involved. You'll have to set the view preferences to use the older rendering methods.
  1. Preferences -> Visualization -> Visual
  2. General Display Settings, change rendering style to "Static Wireframe"
  3. Edge Display Settings, change hidden edges to invisible (or dashed, or gray thin)
  4. If you reorient your view at this point, you will notice that the hidden edges do not update automatically (use regenerate view if needed)
  5. Export your pdf
  6. Reset your view preferences
The invisible and dashed options work well, the "gray thin" option produced black lines in my test. I'm not sure if there is a way around that.

www.nxjournaling.com

RE: Export pdf from modeling, with dim or hidden edges?

What I have done in the passed was export to a jpeg, then the jpeg to a pdf.

RE: Export pdf from modeling, with dim or hidden edges?

Cowski and Jerry, - Where have you been during the last years ? smile

There was some fuzz some years ago when the dynamic mode hidden line became "a standard icon on the toolbar" ( -John will bash me for that) and the export such as pdf and cgm did not take the hidden lines into account. The fix has been there since then, (or a maintenance pack later) but the description in the menu, has been as difficult to understand since day one...

Preferences - Visualization - Visual - Edge display settings - Session settings - Infer edge output = on.
- Will export hidden edges in pdf's etc as expected.

Regards,
Tomas

RE: Export pdf from modeling, with dim or hidden edges?

Toost,
Thanks for the heads up, I missed that one.
Fortunately, I don't do a lot of exporting from the model view so it hasn't really been an issue for me.

www.nxjournaling.com

RE: Export pdf from modeling, with dim or hidden edges?

(OP)
Thanks for your attention, guys!
Now, if You came here, I tell what I want:
export a jpg, from a dual-view layout, with Csys, for the workshop.
My postprocessor list data to a html-file, but it need some drawing, picture, or something like that.
The exported jpg could be better, because it can be easily link into the html. But, when I print the html, it would be better, if the picture contained no empty areas around the views. I found some code, what can crop the picture, but still not works.
I have a journal, what exports the pdf, labelled with the filename, but there were this hidden-line problem.
Unfortunately my programming skills are not so strong, but I do not give it up, somebody hopefully will help me.

http://tek-tips.com/viewthread.cfm?qid=1694947

----
kukelyk

RE: Export pdf from modeling, with dim or hidden edges?

You want your journal to export a jpg and link it into an existing html file that was created by your post processor?

What code do you have so far (is the code posted in the tek-tips thread all of it)?

www.nxjournaling.com

RE: Export pdf from modeling, with dim or hidden edges?

(OP)
no, that's not what I want..
my post creates a html, where the filename same as the prt's, the jpg also.
the html code will contain this default image name..(if there is no picture, there will be a hole in the html page)

----
kukelyk

RE: Export pdf from modeling, with dim or hidden edges?

So all you need is to output a jpg of the part with the same file name as the part and you are trying to minimize the "blank" space around the model? Do you need the jpg output to a specific folder or is it OK to output it to the same folder as the part?

www.nxjournaling.com

RE: Export pdf from modeling, with dim or hidden edges?

(OP)
Yes, the same folder, the same as the prt filename.

----
kukelyk

RE: Export pdf from modeling, with dim or hidden edges?

Here's a code snippet to try:

CODE

Option Strict Off
Imports System
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 fitPercent As Integer = theSession.Preferences.ScreenVisualization.FitPercentage
        theSession.Preferences.ScreenVisualization.FitPercentage = 100

        workPart.ModelingViews.WorkView.Orient(View.Canned.Trimetric)
        workPart.ModelingViews.WorkView.Fit()

        Dim prtJpg As String = Left(workPart.FullPath, Len(workPart.FullPath) - 3) & "jpg"

        ufs.Disp.CreateImage(prtJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)
        theSession.Preferences.ScreenVisualization.FitPercentage = fitPercent

    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 

The above code changes the view fit percentage to 100%, changes the model orientation to trimetric, performs a view fit, exports a jpg with the same name as the file to the same directory as the file, and finally resets the view fit % to the previous value.

www.nxjournaling.com

RE: Export pdf from modeling, with dim or hidden edges?

(OP)
It seems good, but:

Line 17: Value of 'NXOpen.View.Canned'cannot be converted to NXOpen.Matrix3x3'.

What is the problem?
My code is in this stage:

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports Microsoft.VisualBasic
Imports System.Drawing
Imports System.Drawing.Graphics
Imports NXOpen.BasePart
Imports NXOpen.UF  
Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
'  Open 'L2' Layout,  Replace View->TOP&FRONT
' ----------------------------------------------
Dim currentLayout as String = workPart.Layouts.Current.Name
Dim layout1 As Layout = CType(workPart.Layouts.FindObject("L2"), Layout)

If currentLayout <> "L2" Then
 		layout1.Open()
End If

Dim leftSideTop As ModelingView = CType(workPart.ModelingViews.FindObject("TOP"), ModelingView)
layout1.ReplaceView(workPart.ModelingViews.WorkView, leftSideTop, True)

Dim rightSideDefault As ModelingView = CType(workPart.ModelingViews.FindObject("RIGHT"), ModelingView)
Dim rightSideFront As ModelingView = CType(workPart.ModelingViews.FindObject("FRONT"), ModelingView)
layout1.ReplaceView(rightSideDefault, rightSideFront, True)

' ----------------------------------------------
'   Static Wireframe
' ----------------------------------------------
leftSideTop.RenderingStyle = View.RenderingStyleType.StaticWireframe
rightSideFront.RenderingStyle = View.RenderingStyleType.StaticWireframe
' ----------------------------------------------
'   Update Display
' ----------------------------------------------
rightSideFront.UpdateDisplay()
leftSideTop.UpdateDisplay()

' ----------------------------------------------
'   View triad OFF
' ----------------------------------------------

      Dim  sesPrefs = theSession.Preferences
      sesPrefs.ScreenVisualization.TriadVisibility = 0

' ----------------------------------------------
' JPG_output
' ----------------------------------------------
'Dim WorkDir As String 
Dim Work_part As String 
Dim SetupJpg as string
Dim Line as string
Dim ufs As UFSession = UFSession.GetUFSession()  
Dim LineLength As Integer

SetupJpg =  theSession.Parts.Work.FullPath 'read NX internal variable
SetupJpg = Replace (SetupJpg, "prt", "jpg")

            ufs.Disp.CreateImage(SetupJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)  
LineLength = Len( SetupJpg )
While LineLength > 0
      LineLength = LineLength-1
Line &= "-" 
End While
		
theSession.ListingWindow.Open
theSession.ListingWindow.WriteLine( Line )
theSession.ListingWindow.WriteLine( SetupJpg )
theSession.ListingWindow.WriteLine( Line )

' ----------------------------------------------
'   Restore L1 layout
' ----------------------------------------------
Dim SingleView As Layout = CType(workPart.Layouts.FindObject("L1"), Layout)
SingleView.Open()
workPart.ModelingViews.WorkView.Fit()

' ----------------------------------------------
'   View triad ON
' ----------------------------------------------
  sesPrefs.ScreenVisualization.TriadVisibility = 1

' ----------------------------------------------
' Reread exported JPG file, and crop
' ----------------------------------------------

    Dim origJPG As New Bitmap( SetupJpg )

        Dim JPGminX As Integer = origJPG.Width
        Dim JPGminY As Integer = origJPG.Height
        Dim JPGmaxX As Integer = 0
        Dim JPGmaxY As Integer = 0

	Dim bckgrndColor As Color = Color.White

            For y As Integer = 0 To origJPG.Height - 1
                For x As Integer = 0 To origJPG.Width - 1
                    If origJPG.GetPixel(x, y).ToArgb <> bckgrndColor.ToArgb Then
                        If x < JPGminX Then
                            JPGminX = x
                        ElseIf x > JPGmaxX Then
                            JPGmaxX = x
                        End If
                        If y < JPGminY Then
                            JPGminY = y
                        ElseIf y > JPGmaxY Then
                            JPGmaxY = y
                        End If
                    End If
                Next
            Next
        Dim rect As New Rectangle(JPGminX, JPGminY, JPGmaxX - JPGminX  + 1, JPGmaxY - JPGminY + 1)

      Dim cropped As Bitmap = origJPG.Clone(rect, origJPG.PixelFormat)

    ' Close the image files.
   origJPG.Dispose()
 cropped.Save(SetupJpg, System.Drawing.Imaging.ImageFormat.Jpeg)

End Sub

End Module

it exports a JPG, and crop it correctly, the first time.
If I run it once again, the model disappears before the export, and the jpg contains only the WCS...

does anyone know why? 

----
kukelyk

RE: Export pdf from modeling, with dim or hidden edges?

To get my code to work, try replacing these 2 lines:

CODE

workPart.ModelingViews.WorkView.Orient(View.Canned.Trimetric)
workPart.ModelingViews.WorkView.Fit() 

with this line

CODE

workPart.ModelingViews.WorkView.Orient(NXOpen.View.Canned.Trimetric, NXOpen.View.ScaleAdjustment.Fit) 

Looks like you wouldn't need that line in your code at all since you aren't reorienting views but rather using existing layouts.

www.nxjournaling.com

RE: Export pdf from modeling, with dim or hidden edges?

I ran your code and saw the same issue on the second and subsequent runs. I added a message box before the jpg output to "pause" the journal and see what was going on with the views. This had the effect of allowing everything to update and run correctly. My guess is, for some reason the code runs faster on the 2nd run and it jumps to the jpg output before the views have finished updating. I commented out the messagebox and put a DoEvents in there instead and it seemed to have the same effect.


CODE

Option Strict Off  
Imports System  
Imports System.Windows.Forms  
Imports NXOpen  
Imports Microsoft.VisualBasic  
Imports System.Drawing  
Imports System.Drawing.Graphics  
Imports NXOpen.BasePart  
Imports NXOpen.UF    
Module NXJournal  
Sub Main  

Dim theSession As Session = Session.GetSession()  
Dim theUI As UI = UI.GetUI()  
Dim workPart As Part = theSession.Parts.Work  
Dim displayPart As Part = theSession.Parts.Display  
Dim lw as ListingWindow = theSession.ListingWindow  
lw.Open  

' ----------------------------------------------
'  Open 'L2' Layout,  Replace View->TOP&FRONT
' ----------------------------------------------
Dim currentLayout as String = workPart.Layouts.Current.Name  
Dim layout1 As Layout = CType(workPart.Layouts.FindObject("L2"), Layout)  

If currentLayout <> "L2" Then  
 		layout1.Open()  
End If  

Dim leftSideTop As ModelingView = CType(workPart.ModelingViews.FindObject("TOP"), ModelingView)  
layout1.ReplaceView(workPart.ModelingViews.WorkView, leftSideTop, True)  

Dim rightSideDefault As ModelingView = CType(workPart.ModelingViews.FindObject("RIGHT"), ModelingView)  
Dim rightSideFront As ModelingView = CType(workPart.ModelingViews.FindObject("FRONT"), ModelingView)  
layout1.ReplaceView(rightSideDefault, rightSideFront, True)  

' ----------------------------------------------
'   Static Wireframe
' ----------------------------------------------
leftSideTop.RenderingStyle = NXOpen.View.RenderingStyleType.StaticWireframe  
rightSideFront.RenderingStyle = NXOpen.View.RenderingStyleType.StaticWireframe  
' ----------------------------------------------
'   Update Display
' ----------------------------------------------
rightSideFront.UpdateDisplay()  
leftSideTop.UpdateDisplay()  

' ----------------------------------------------
'   View triad OFF
' ----------------------------------------------

Dim  sesPrefs = theSession.Preferences  
sesPrefs.ScreenVisualization.TriadVisibility = 0  

'msgbox("check view")
for i as integer = 1 to 10  
	Application.DoEvents  
next  

' ----------------------------------------------
' JPG_output
' ----------------------------------------------
'Dim WorkDir As String 
Dim Work_part As String   
Dim SetupJpg as string  
Dim Line as string  
Dim ufs As UFSession = UFSession.GetUFSession()    
Dim LineLength As Integer  

SetupJpg =  theSession.Parts.Work.FullPath  'read NX internal variable
SetupJpg = Replace (SetupJpg, "prt", "jpg")  

ufs.Disp.CreateImage(SetupJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)  
			  
'LineLength = Len( SetupJpg )
'While LineLength > 0
'      LineLength = LineLength-1
'Line &= "-" 
'End While

'the above loop can be condensed to:
Line = New String("-"c, Len( SetupJpg ))  
		  
theSession.ListingWindow.Open  
theSession.ListingWindow.WriteLine( Line )  
theSession.ListingWindow.WriteLine( SetupJpg )  
theSession.ListingWindow.WriteLine( Line )  

' ----------------------------------------------
'   Restore L1 layout
' ----------------------------------------------
Dim SingleView As Layout = CType(workPart.Layouts.FindObject("L1"), Layout)  
SingleView.Open()  
workPart.ModelingViews.WorkView.Fit()  

' ----------------------------------------------
'   View triad ON
' ----------------------------------------------
  sesPrefs.ScreenVisualization.TriadVisibility = 1  

' ----------------------------------------------
' Reread exported JPG file, and crop
' ----------------------------------------------

    Dim origJPG As New Bitmap( SetupJpg )  

        Dim JPGminX As Integer = origJPG.Width  
        Dim JPGminY As Integer = origJPG.Height  
        Dim JPGmaxX As Integer = 0  
        Dim JPGmaxY As Integer = 0  

	Dim bckgrndColor As Color = Color.White  

            For y As Integer = 0 To origJPG.Height - 1  
                For x As Integer = 0 To origJPG.Width - 1  
                    If origJPG.GetPixel(x, y).ToArgb <> bckgrndColor.ToArgb Then  
                        If x < JPGminX Then  
                            JPGminX = x  
                        ElseIf x > JPGmaxX Then  
                            JPGmaxX = x  
                        End If  
                        If y < JPGminY Then  
                            JPGminY = y  
                        ElseIf y > JPGmaxY Then  
                            JPGmaxY = y  
                        End If  
                    End If  
                Next  
            Next  
        Dim rect As New Rectangle(JPGminX, JPGminY, JPGmaxX - JPGminX  + 1, JPGmaxY - JPGminY + 1)  

      Dim cropped As Bitmap = origJPG.Clone(rect, origJPG.PixelFormat)  

 ' Close the image files.
   origJPG.Dispose()  
 cropped.Save(SetupJpg, System.Drawing.Imaging.ImageFormat.Jpeg)  

End Sub  

End Module 

www.nxjournaling.com

RE: Export pdf from modeling, with dim or hidden edges?

(OP)
Great, many thanks

----
kukelyk

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