×
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

automatic image creation

automatic image creation

automatic image creation

(OP)
hello,

I have seen a journal to take a jpg image of each part and assembly that exists in the model but was wondering if we can take the image to be more precise. Only the bounding area of each displayed part to be in the created image? basically to reduce the whitespace around and to reduce the file size and to get a crisper image.

thanks for the help
DPRK

RE: automatic image creation

(OP)
here is the one I modified to suit my needs after getting the original from one of this forums.

thanks for the help.

Option Strict Off

Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module NXJournal

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow

Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display
theSession.Preferences.ScreenVisualization.TriadVisibility = 0
'*******************************************************
' TO get the folder name for jpgs
'******************************************************
Dim folderName As String = "C:"
Dim folderBrowserDialog1 As New FolderBrowserDialog
With folderBrowserDialog1
.Description = "Specify folder for screenshot output"
.ShowNewFolderButton = False
.RootFolder = Environment.SpecialFolder.Desktop
'use folderName as default directory
.SelectedPath = folderName
End With

Dim result As DialogResult = folderBrowserDialog1.ShowDialog()

If (result = DialogResult.OK) Then
folderName = folderBrowserDialog1.SelectedPath
Else
'user pressed cancel, exit the journal
Exit Sub
End If
'**********************************************
'**********************************************

'lw.Open
Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
if not IsNothing(c.RootComponent) then
'*** insert code to process 'root component' (assembly file)
'lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
'lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
'lw.WriteLine(folderName & "\" & c.RootComponent.DisplayName)
'*** end of code to process root component
Dim nullAssemblies_Component As Assemblies.Component = Nothing

Dim partLoadStatus3 As PartLoadStatus
theSession.Parts.SetWorkComponent(nullAssemblies_Component, partLoadStatus3)

workPart = theSession.Parts.Work
partLoadStatus3.Dispose()

dispPart.ModelingViews.WorkView.Fit()
dispPart.ModelingViews.WorkView.Orient(NXOpen.View.Canned.Isometric, NXOpen.View.ScaleAdjustment.Fit)
dispPart.ModelingViews.WorkView.RenderingStyle = NXOpen.View.RenderingStyleType.ShadedWithEdges
dispPart.Preferences.NamesBorderVisualization.ShowModelViewNames = False
theSession.Preferences.ScreenVisualization.TriadVisibility = 0
For i As Integer = 2 To 256
Dim stateArray1(0) As Layer.StateInfo
stateArray1(0) = New Layer.StateInfo(i, Layer.State.Hidden)
dispPart.Layers.ChangeStates(stateArray1, False)
Next

Dim strPartJpg As String = ""
strPartJpg = Path.GetFileNameWithoutExtension(dispPart.FullPath) & ".jpg"
strPartJpg = Path.Combine(folderName, strPartJpg)
ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)

ReportComponentChildren(c.RootComponent, 0, folderName, theSession)
else
'*** insert code to process piece part
'lw.WriteLine("Part has no components")
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
End Try
'lw.Close

End Sub

'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer, ByVal fName As String, ByVal theSes As Session)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
'lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'lw.WriteLine(New String(" ", indent * 2) & fName & "\" & child.DisplayName())

'****************************************************
Dim Part1 As Part = CType(theSes.Parts.FindObject(child.DisplayName()), Part)

Dim partLoadStatus1 As PartLoadStatus
Dim status1 As PartCollection.SdpsStatus
status1 = theSes.Parts.SetDisplay(Part1, True, True, partLoadStatus1)

Dim workPart As Part = theSes.Parts.Work
Dim displayPart As Part = theSes.Parts.Display
workPart = theSes.Parts.Work
displayPart = theSes.Parts.Display
partLoadStatus1.Dispose()

displayPart.ModelingViews.WorkView.Fit()
displayPart.ModelingViews.WorkView.Orient(NXOpen.View.Canned.Isometric, NXOpen.View.ScaleAdjustment.Fit)
displayPart.ModelingViews.WorkView.RenderingStyle = NXOpen.View.RenderingStyleType.ShadedWithEdges
displayPart.Preferences.NamesBorderVisualization.ShowModelViewNames = False
theSes.Preferences.ScreenVisualization.TriadVisibility = 0
For i As Integer = 2 To 256
Dim stateArray1(0) As Layer.StateInfo
stateArray1(0) = New Layer.StateInfo(i, Layer.State.Hidden)
displayPart.Layers.ChangeStates(stateArray1, False)
Next

Dim strPartJpg As String = ""
strPartJpg = Path.GetFileNameWithoutExtension(displayPart.FullPath) & ".jpg"
strPartJpg = Path.Combine(fName, strPartJpg)
ufs.Disp.CreateImage(strPartJpg, UFDisp.ImageFormat.Jpeg, UFDisp.BackgroundColor.White)


'Dim markId As Session.UndoMarkId
'markId = theSes.SetUndoMark(Session.MarkVisibility.Visible, "Display Parent")
'************************************

'*** end of code to process component or subassembly
if child.GetChildren.Length <> 0 then
'*** this is a subassembly, add code specific to subassemblies
'lw.WriteLine(New String(" ", indent * 2) & _
'"* subassembly with " & _
' child.GetChildren.Length & " components")
'lw.WriteLine(New String(" ", indent * 2) & _
'" + Active Arrangement: " & _
'child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
'lw.WriteLine(New String(" ", indent * 2) & fName & "\" & child.DisplayName())
else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components
'lw.WriteLine(New String(" ", indent * 2) & fName & "\" & child.DisplayName())
end if
reportComponentChildren(child, indent + 1, fName, theSes)
Next
End Sub
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************

End Module

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