Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IFRs on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export pdf from modeling, with dim or hidden edges? 2

Status
Not open for further replies.

kukelyk

Industrial
Mar 21, 2005
315
Is it possible in NX8?
Thanks in advance

----
kukelyk
 
Replies continue below

Recommended for you

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.
[ol 1]
[li]Preferences -> Visualization -> Visual[/li]
[li]General Display Settings, change rendering style to "Static Wireframe"[/li]
[li]Edge Display Settings, change hidden edges to invisible (or dashed, or gray thin)[/li]
[li]If you reorient your view at this point, you will notice that the hidden edges do not update automatically (use regenerate view if needed)[/li]
[li]Export your pdf[/li]
[li]Reset your view preferences[/li]
[/ol]

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
 
What I have done in the passed was export to a jpeg, then the jpeg to a pdf.
 
Cowski and Jerry, - Where have you been during the last years ? :)

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
 
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
 
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.

[URL unfurl="true"]http://tek-tips.com/viewthread.cfm?qid=1694947[/url]

----
kukelyk
 
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
 
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
 
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
 
Yes, the same folder, the same as the prt filename.

----
kukelyk
 
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
 
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
 
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
 
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:
[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] System.Windows.Forms  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] Microsoft.VisualBasic  
[COLOR=blue]Imports[/color] System.Drawing  
[COLOR=blue]Imports[/color] System.Drawing.Graphics  
[COLOR=blue]Imports[/color] NXOpen.BasePart  
[COLOR=blue]Imports[/color] NXOpen.UF    
[COLOR=blue]Module[/color] NXJournal  
[COLOR=blue]Sub[/color] Main  

[COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
[COLOR=blue]Dim[/color] theUI [COLOR=blue]As[/color] UI [COLOR=blue]=[/color] UI.GetUI()  
[COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  
[COLOR=blue]Dim[/color] displayPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Display  
[COLOR=blue]Dim[/color] lw [COLOR=blue]as[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow  
lw.Open  

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

[COLOR=blue]If[/color] currentLayout <> "L2" [COLOR=blue]Then[/color]  
 		layout1.Open()  
End [COLOR=blue]If[/color]  

[COLOR=blue]Dim[/color] leftSideTop [COLOR=blue]As[/color] ModelingView [COLOR=blue]=[/color] CType(workPart.ModelingViews.FindObject("TOP"), ModelingView)  
layout1.ReplaceView(workPart.ModelingViews.WorkView, leftSideTop, [COLOR=blue]True[/color])  

[COLOR=blue]Dim[/color] rightSideDefault [COLOR=blue]As[/color] ModelingView [COLOR=blue]=[/color] CType(workPart.ModelingViews.FindObject("RIGHT"), ModelingView)  
[COLOR=blue]Dim[/color] rightSideFront [COLOR=blue]As[/color] ModelingView [COLOR=blue]=[/color] CType(workPart.ModelingViews.FindObject("FRONT"), ModelingView)  
layout1.ReplaceView(rightSideDefault, rightSideFront, [COLOR=blue]True[/color])  

[COLOR=green]' ----------------------------------------------[/color]
[COLOR=green]'   Static Wireframe[/color]
[COLOR=green]' ----------------------------------------------[/color]
leftSideTop.RenderingStyle [COLOR=blue]=[/color] NXOpen.View.RenderingStyleType.StaticWireframe  
rightSideFront.RenderingStyle [COLOR=blue]=[/color] NXOpen.View.RenderingStyleType.StaticWireframe  
[COLOR=green]' ----------------------------------------------[/color]
[COLOR=green]'   Update Display[/color]
[COLOR=green]' ----------------------------------------------[/color]
rightSideFront.UpdateDisplay()  
leftSideTop.UpdateDisplay()  

[COLOR=green]' ----------------------------------------------[/color]
[COLOR=green]'   View triad OFF[/color]
[COLOR=green]' ----------------------------------------------[/color]

[COLOR=blue]Dim[/color]  sesPrefs [COLOR=blue]=[/color] theSession.Preferences  
sesPrefs.ScreenVisualization.TriadVisibility [COLOR=blue]=[/color] 0  

[COLOR=green]'msgbox("check view")[/color]
[COLOR=blue]for[/color] i [COLOR=blue]as[/color] [COLOR=blue]integer[/color] [COLOR=blue]=[/color] 1 [COLOR=blue]to[/color] 10  
	Application.DoEvents  
[COLOR=blue]next[/color]  

[COLOR=green]' ----------------------------------------------[/color]
[COLOR=green]' JPG_output[/color]
[COLOR=green]' ----------------------------------------------[/color]
[COLOR=green]'Dim WorkDir As String [/color]
[COLOR=blue]Dim[/color] Work_part [COLOR=blue]As[/color] [COLOR=blue]String[/color]   
[COLOR=blue]Dim[/color] SetupJpg [COLOR=blue]as[/color] [COLOR=blue]string[/color]  
[COLOR=blue]Dim[/color] Line [COLOR=blue]as[/color] [COLOR=blue]string[/color]  
[COLOR=blue]Dim[/color] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession()    
[COLOR=blue]Dim[/color] LineLength [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  

SetupJpg [COLOR=blue]=[/color]  theSession.Parts.Work.FullPath  [COLOR=green]'read NX internal variable[/color]
SetupJpg [COLOR=blue]=[/color] Replace (SetupJpg, "prt", "jpg")  

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

[COLOR=green]'the above loop can be condensed to:[/color]
Line [COLOR=blue]=[/color] [COLOR=blue]New[/color] String("-"c, Len( SetupJpg ))  
		  
theSession.ListingWindow.Open  
theSession.ListingWindow.WriteLine( Line )  
theSession.ListingWindow.WriteLine( SetupJpg )  
theSession.ListingWindow.WriteLine( Line )  

[COLOR=green]' ----------------------------------------------[/color]
[COLOR=green]'   Restore L1 layout[/color]
[COLOR=green]' ----------------------------------------------[/color]
[COLOR=blue]Dim[/color] SingleView [COLOR=blue]As[/color] Layout [COLOR=blue]=[/color] CType(workPart.Layouts.FindObject("L1"), Layout)  
SingleView.Open()  
workPart.ModelingViews.WorkView.Fit()  

[COLOR=green]' ----------------------------------------------[/color]
[COLOR=green]'   View triad ON[/color]
[COLOR=green]' ----------------------------------------------[/color]
  sesPrefs.ScreenVisualization.TriadVisibility [COLOR=blue]=[/color] 1  

[COLOR=green]' ----------------------------------------------[/color]
[COLOR=green]' Reread exported JPG file, and crop[/color]
[COLOR=green]' ----------------------------------------------[/color]

    [COLOR=blue]Dim[/color] origJPG [COLOR=blue]As[/color] [COLOR=blue]New[/color] Bitmap( SetupJpg )  

        [COLOR=blue]Dim[/color] JPGminX [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] origJPG.Width  
        [COLOR=blue]Dim[/color] JPGminY [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] origJPG.Height  
        [COLOR=blue]Dim[/color] JPGmaxX [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] 0  
        [COLOR=blue]Dim[/color] JPGmaxY [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] 0  

	Dim bckgrndColor [COLOR=blue]As[/color] Color [COLOR=blue]=[/color] Color.White  

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

      [COLOR=blue]Dim[/color] cropped [COLOR=blue]As[/color] Bitmap [COLOR=blue]=[/color] origJPG.Clone(rect, origJPG.PixelFormat)  

 [COLOR=green]' Close the image files.[/color]
   origJPG.Dispose()  
 cropped.Save(SetupJpg, System.Drawing.Imaging.ImageFormat.Jpeg)  

End [COLOR=blue]Sub[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor