Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

automatic image creation

Status
Not open for further replies.

DPRK

Automotive
Oct 3, 2013
8
US
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
 
Replies continue below

Recommended for you

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
 
You may be interested in the code posted in the last few posts of:
thread561-331483

Short description: change your view fit percent to 100 before exporting the screenshot and there is code that will crop out some white space.

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

Part and Inventory Search

Sponsor

Top