kukelyk
Industrial
- Mar 21, 2005
- 315
Is it possible in NX8?
Thanks in advance
----
kukelyk
Thanks in advance
----
kukelyk
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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
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?
workPart.ModelingViews.WorkView.Orient(View.Canned.Trimetric)
workPart.ModelingViews.WorkView.Fit()
workPart.ModelingViews.WorkView.Orient(NXOpen.View.Canned.Trimetric, NXOpen.View.ScaleAdjustment.Fit)
[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]