erpj
Aerospace
- Jul 15, 2011
- 24
Hi everyone,
I'm trying to generate multiple screenshots of an assembly by rotating it around the Y axis and invoking the CreateImage method. The script works, however, I cannot figure out how to update the display to redraw the model edges after each rotation. After each rotation, the image is saved, but it is as if NX doen't have enough time to redraw completly model and what gets exported is a simplified version of the geometry.
You can see below that I try multiple function to uodate the display, but nothing seems to work.
I would also like to know how define the base 3D point (origin2) dynamically instead of statically. (something like Pick the geometric center of the view)
Etienne
NX8.5.3.3 + TC9.1.2.2
I'm trying to generate multiple screenshots of an assembly by rotating it around the Y axis and invoking the CreateImage method. The script works, however, I cannot figure out how to update the display to redraw the model edges after each rotation. After each rotation, the image is saved, but it is as if NX doen't have enough time to redraw completly model and what gets exported is a simplified version of the geometry.
You can see below that I try multiple function to uodate the display, but nothing seems to work.
I would also like to know how define the base 3D point (origin2) dynamically instead of statically. (something like Pick the geometric center of the view)
Code:
' NX 8.5.3.3
'
Option Strict Off
Imports System
Imports System.Threading
Imports NXOpen
Imports NXOpen.UF
Module NXJournal
Sub Main
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theSession As Session = Session.GetSession()
Dim displayPart As Part = theSession.Parts.Display
Dim workPart As Part = theSession.Parts.Work
' ---------------------------------------------------
' Choose the folder where to export the images
' ---------------------------------------------------
Dim theFolder as String
Dim defAns as String = "C:\"
theFolder = InputBox("Where to export images? (Paste directory path)", "", defAns)
if theFolder = "" then
Return
Else
theFolder = theFolder.Replace("""", "")
End If
' ---------------------------------------------------
' Choose the base name for the images
' ---------------------------------------------------
Dim ImageName As String
defAns = "IMG"
ImageName = InputBox("Enter a base name for all created images", "", defAns)
if ImageName = "" then
Return
Else
ImageName = ImageName.Replace("""", "")
End If
' ---------------------------------------------------
' Choose the angle increment for the images
' ---------------------------------------------------
Dim strAngle As String
Dim Angle As Integer
defAns = "45"
strAngle = InputBox("Enter an angle between each generated images", "", defAns)
if strAngle = "" then
Return
Else
Try
Angle = CInt(strAngle)
Catch ex As NXException
MsgBox("You did not enter a proper integer value for the angle")
Return
End Try
End If
' ---------------------------------------------------
' Create the images
' ---------------------------------------------------
'Parameters for the view rotation
Dim origin2 As Point3d = New Point3d(0.0, -46.1544676136208, 79.5)
Dim vector2 As Vector3d = New Vector3d(0.0, 1.0, 0.0)
'Parameters for the exported image name
Dim exportFileName As String = Nothing
Dim ImageNameInt As String = Nothing
'parameters for the loop
Dim StartInt As Integer = 1
Dim EndInt As Integer = Math.Floor(360/Angle)
For index As Integer = StartInt To EndInt
ImageNameInt = ImageName & "_" & cstr(index)
exportFileName = IO.Path.Combine(theFolder, ImageNameInt & ".png")
'if this file already exists, delete it
If My.Computer.FileSystem.FileExists(exportFileName) Then
My.Computer.FileSystem.DeleteFile(exportFileName)
End If
workPart.ModelingViews.WorkView.Rotate(origin2, vector2, Angle)
'Refresh the view after the rotation
ufs.Disp.MakeDisplayUpToDate()
ufs.Disp.Refresh()
workPart.ModelingViews.WorkView.UpdateDisplay()
'This discard all the display and redraw, but still not entirely. (and it is really slow)
'ufs.Disp.RegenerateDisplay()
Dim background_color As UFDisp.BackgroundColor = UFDisp.BackgroundColor.white
displayPart.WCS.Visibility = False
'ufs.Disp.CreateImage(exportFileName, UFDisp.ImageFormat.Png, background_color)
Next
End Sub
End Module
Etienne
NX8.5.3.3 + TC9.1.2.2