Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journal code - What am I dong wrong? 1

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949
I like having simple buttons to turn certain options that i use a lot, on and off. Edges Hidden by Edges, View Hidden Lines in a drafting view, etc...

All of these that I have working are all done in Drafting. I am trying to make one work the same way in Modeling for Silhouettes. This code will turn them on, but never turns them off.


Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
' Menu: Preferences->Visualization...
' ----------------------------------------------
Dim currentMode1 As NXOpen.Preferences.SessionVisualizationHighEndRendering.MaterialEditorEditingMode = Nothing
currentMode1 = theSession.Preferences.HighEndRenderingVisualization.StudioMaterialEditorEditingMode

Dim displayAppearanceOptions1 As NXOpen.Preferences.ViewVisualizationVisual.DisplayAppearanceOptions = Nothing

displayAppearanceOptions1.RenderingStyle = NXOpen.Preferences.ViewVisualizationVisual.RenderingStyle.StaticWireframe
displayAppearanceOptions1.HiddenEdges = NXOpen.Preferences.ViewVisualizationVisual.HiddenEdges.Visible

[highlight #FCE94F]
if displayAppearanceOptions1.Silhouettes = True then
displayAppearanceOptions1.Silhouettes = False
elseif displayAppearanceOptions1.Silhouettes = False then
displayAppearanceOptions1.Silhouettes = True
End if [/highlight]

displayAppearanceOptions1.SmoothEdges = True
displayAppearanceOptions1.SmoothEdgeColor = 0
displayAppearanceOptions1.SmoothEdgeFont = NXOpen.Preferences.ViewVisualizationVisual.SmoothEdgeFont.Original
displayAppearanceOptions1.SmoothEdgeWidth = NXOpen.Preferences.ViewVisualizationVisual.SmoothEdgeWidth.Original
displayAppearanceOptions1.SmoothEdgeAngleTolerance = 0.19999999999999996
workPart.ModelingViews.WorkView.VisualizationVisualPreferences.DisplayAppearance = displayAppearanceOptions1

End Sub
End Module
 
Replies continue below

Recommended for you

Your "displayAppearanceOptions1" variable is originally declared to be "nothing"; this means that all the member variables are not set yet. Later bits of code (your highlighted parts) attempt to make use of a member variable that still isn't set yet. To populate the member variables with the current settings, get the display options from the current work view. After that, you can make use of the values for the current setting and change them as desired. The code below gets the view settings from the current work view, sets the display style to static wireframe and toggles the silhouette curve setting (run it a few times to see the effect).

Code:
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Preferences->Visualization...
' ----------------------------------------------
Dim displayAppearanceOptions1 As NXOpen.Preferences.ViewVisualizationVisual.DisplayAppearanceOptions = workPart.ModelingViews.WorkView.VisualizationVisualPreferences.DisplayAppearance
displayAppearanceOptions1.RenderingStyle = NXOpen.Preferences.ViewVisualizationVisual.RenderingStyle.StaticWireframe
displayAppearanceOptions1.HiddenEdges = NXOpen.Preferences.ViewVisualizationVisual.HiddenEdges.Visible
displayAppearanceOptions1.Silhouettes = Not displayAppearanceOptions1.Silhouettes
workPart.ModelingViews.WorkView.VisualizationVisualPreferences.DisplayAppearance = displayAppearanceOptions1

' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

www.nxjournaling.com
 
SO in dumbed down English, let me see if I get this right. lol

Because I had the DisplayAppearanceOptions set to "Nothing", it is basically saying nothing is set. So it didnt know what to do. You changed that to look at the display settings of the work view.

Then instead of using an IF statement, you did the following....

For the rendering style and the hidden edges, it is looking at the display settings, then the code is giving them a specific setting to use.

The Silhouettes code sees the display settings being used, then basically just tells it to use whatever setting is not already being used?


As you see, I understand code very little. I get what I can find and try to hack my way through it to make it do what I need. Doesnt always work out so well. lol

I did try it and it works great. Thanks cowski
 
The setting for the silhouettes property is a boolean value (either true or false). The code above uses the Not operator to flip the value of the silhouettes setting (Not True = False and Not False = True). It is a shortcut notation that does the same thing as the If block in your original code. My use of the Not .Silhouettes isn't what made the code work, but rather getting the view settings from the current work view before attempting to make changes.

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

Part and Inventory Search

Sponsor