You need to add some code to your journal that displays a selection dialog and gives the user the opportunity to select bodies. The bodies returned from that selection dialog are the ones you want to operate upon.
Alternatively, if you have SNAP, the coding is pretty trivial: look at the chapter on object selection in the SNAP Getting Started Guide, and read the section on dealing with the "FindObject" calls that you find in recorded journals. Actually, it might help to read this material even if you're not going to use SNAP functions.
Note: you will need to change the color and layer numbers to your desired values before running the journal.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ufs As UFSession = UFSession.GetUFSession()
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change color and layer to desired values before running journal
displayModification1.NewColor = 103
displayModification1.NewLayer = 12
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Dim objects1(0) As DisplayableObject
Dim body1 As Body = SelectSolid()
objects1(0) = body1
displayModification1.Apply(objects1)
displayModification1.Dispose()
End Sub
Function SelectSolid() As Body
Dim ui As UI = ui.GetUI
Dim message As String = "Select solid body"
Dim title As String = "Selection"
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = True
Dim selectionAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With
Dim selectedObject As NXObject = Nothing
Dim cursor As Point3d
What version of NX are you using?
I ask because the .SelectObject function used in the previous journal has been deprecated and should only really be used in NX 7.5 or lower. If you are using NX 8 or above, I'd like to use the current selection function.
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module Module26
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ufs As UFSession = UFSession.GetUFSession()
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")
Dim theSolids As New List(Of Body)
If SelectSolids("Select one or more solid bodies", theSolids) = Selection.Response.Cancel Then
Return
End If
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change color and layer to desired values before running journal
displayModification1.NewColor = 103
displayModification1.NewLayer = 12
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Function SelectSolids(ByVal prompt As String, ByRef tempBodies As List(Of Body)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select one or more solid bodies"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)
If resp = Selection.Response.Ok Then
For Each temp As Body In selObj
tempBodies.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
I used above journal for multi selection of bodies to apply color and to keep bodies layer.I faced a problem for those solid bodies which is having many many faces & 3D surface part profile and solid body like LOWER SHOE ( it is having many many faces element in PRESS TOOL DESIGN ).The color is not applying for some faces of the solid body.
Are you selecting a body in a part file or are you selecting the body of a component in an assembly?
Are you sure the faces in question are part of the solid body and not duplicate sheet bodies near the body?
Are you using any feature that would override the color assigned such as: "assign feature color" or "assign feature group color"?
Does the color of the body faces change if you use the interactive NX command "edit object display"? In other words, the NX commands work but the journal does not? Or does the journal give the same results as the NX command?
Yes, I am sure that faces are the part of solid body & not duplicate sheet bodies on solid body.
No, I am not using any feature that would override the color assigned.
Yes,NX command works for the same but after using a journal some faces color remains unchange rest of the things are fine like selecting of multi solid bodies.
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module Module26
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ufs As UFSession = UFSession.GetUFSession()
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")
'Dim theSolids As New List(Of Body)
'If SelectSolids("Select one or more solid bodies", theSolids) = Selection.Response.Cancel Then
' Return
'End If
Dim theObjects As New List(Of DisplayableObject)
If SelectObjects("Select one or more objects", theObjects) = Selection.Response.Cancel Then
Return
End If
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change color and layer to desired values before running journal
displayModification1.NewColor = 103
displayModification1.NewLayer = 12
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Function SelectSolids(ByVal prompt As String, ByRef tempBodies As List(Of Body)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select one or more solid bodies"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)
If resp = Selection.Response.Ok Then
For Each temp As Body In selObj
tempBodies.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function SelectObjects(prompt As String, _
ByRef objList As List(Of DisplayableObject)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All, _
Selection.SelectionType.Faces, _
Selection.SelectionType.Edges}
Dim selObj() As TaggedObject
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects( _
prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selObj)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.Ok Then
For Each temp As DisplayableObject In selObj
objList.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
Hello
In above 2nd last journal I can select surface and curve but not able to put in layers.where has in last journal something is incorrect in 9th line when I ran the journal error message in 9th line of the journal.
Be aware of exactly what you are selecting with the journal. If you select a "face", the color will change but it cannot move to a different layer. Faces belong to a body object and you cannot move a face to a different layer than the body. After starting the journal, at the selection prompt, you can change the selection filter (in interactive NX) to further narrow the allowed selections to sheet body or solid body, in this case. Alternatively, you could remove the "faces" filter used in the journal code. This would ensure that you cannot inadvertently select face objects.
If you select a curve that belongs to a sketch, it will be moved to a different layer. However, at the next part update, NX may move it back to the same layer as the sketch. If you want to move entire sketches, we might have to adjust the selection filter to allow selection of sketches (the filter used in the journal code, not the interactive NX selection filter).
I assume you will need a SNAP license to run the SNAP code. I can't really comment on it further than that.
Selecting bodies
You need to add some code to your journal that displays a selection dialog and gives the user the opportunity to select bodies. The bodies returned from that selection dialog are the ones you want to operate upon.
There's a tutorial here: http://nxjournaling.com/content/adding-interactive-selection-routine-usi...
Alternatively, if you have SNAP, the coding is pretty trivial: look at the chapter on object selection in the SNAP Getting Started Guide, and read the section on dealing with the "FindObject" calls that you find in recorded journals. Actually, it might help to read this material even if you're not going to use SNAP functions.
1
1
re: change color and layer
The code below is a minor modification of the last code example in the article:
http://nxjournaling.com/content/beginning-journaling-using-nx-journal
Note: you will need to change the color and layer numbers to your desired values before running the journal.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module NXJournal
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ufs As UFSession = UFSession.GetUFSession()
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change color and layer to desired values before running journal
displayModification1.NewColor = 103
displayModification1.NewLayer = 12
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Dim objects1(0) As DisplayableObject
Dim body1 As Body = SelectSolid()
objects1(0) = body1
displayModification1.Apply(objects1)
displayModification1.Dispose()
End Sub
Function SelectSolid() As Body
Dim ui As UI = ui.GetUI
Dim message As String = "Select solid body"
Dim title As String = "Selection"
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = True
Dim selectionAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With
Dim selectedObject As NXObject = Nothing
Dim cursor As Point3d
ui.SelectionManager.SelectObject(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObject, cursor)
Dim solid As Body = CType(selectedObject, Body)
If solid Is Nothing Then
Return Nothing
End If
Return solid
End Function
End Module
2015-02-05 edit: displayModification1.ApplyToAllFaces = True
tx
tx
Hi,
Hi,
I
re: multiple selection
What version of NX are you using?
I ask because the .SelectObject function used in the previous journal has been deprecated and should only really be used in NX 7.5 or lower. If you are using NX 8 or above, I'd like to use the current selection function.
I
I
re: multiple selection
Try this version:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module Module26
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ufs As UFSession = UFSession.GetUFSession()
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")
Dim theSolids As New List(Of Body)
If SelectSolids("Select one or more solid bodies", theSolids) = Selection.Response.Cancel Then
Return
End If
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change color and layer to desired values before running journal
displayModification1.NewColor = 103
displayModification1.NewLayer = 12
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
displayModification1.Apply(theSolids.ToArray)
displayModification1.Dispose()
End Sub
Function SelectSolids(ByVal prompt As String, ByRef tempBodies As List(Of Body)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select one or more solid bodies"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)
If resp = Selection.Response.Ok Then
For Each temp As Body In selObj
tempBodies.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
2015-02-05 edit: displayModification1.ApplyToAllFaces = True
i
i
Thanks, I will also use this.
Thanks, I will also use this.
I used above journal for
I used above journal for multi selection of bodies to apply color and to keep bodies layer.I faced a problem for those solid bodies which is having many many faces & 3D surface part profile and solid body like LOWER SHOE ( it is having many many faces element in PRESS TOOL DESIGN ).The color is not applying for some faces of the solid body.
Please guys help me to solve this issue.
re: face color not changing
Are you selecting a body in a part file or are you selecting the body of a component in an assembly?
Are you sure the faces in question are part of the solid body and not duplicate sheet bodies near the body?
Are you using any feature that would override the color assigned such as: "assign feature color" or "assign feature group color"?
Does the color of the body faces change if you use the interactive NX command "edit object display"? In other words, the NX commands work but the journal does not? Or does the journal give the same results as the NX command?
I am selecting a body in part
I am selecting a body in part file.
Yes, I am sure that faces are the part of solid body & not duplicate sheet bodies on solid body.
No, I am not using any feature that would override the color assigned.
Yes,NX command works for the same but after using a journal some faces color remains unchange rest of the things are fine like selecting of multi solid bodies.
Is there any solution for this issue.
re: body color
I've not been able to reproduce the situation you describe. Could you email me a sample part that shows this behavior? (info@nxjournaling.com)
Also, what version of NX are you using?
OK, I WILL,GIVE ME SOME TO
OK, I WILL,GIVE ME SOME TIME TO SEND.
re: body face color
DOH!
I don't know how I missed this one, but try changing the line of code:
displayModification1.ApplyToAllFaces = False
to:
displayModification1.ApplyToAllFaces = True
I'll edit the code in the post above so if anyone copies it in the future it will be correct.
Thank you I will check
Thank you
I will check
The above journal is working
The above journal is working.It is for only solid but can not select a curve,surface,axis,points can i get journal for all.
I Knew that initially I asked for only solid but now my preferences are changed.
re: preferences changed
You can easily widen the selection filter by using the selection function found in:
http://nxjournaling.com/content/adding-interactive-selection-routine-usi...
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module Module26
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim ufs As UFSession = UFSession.GetUFSession()
Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")
'Dim theSolids As New List(Of Body)
'If SelectSolids("Select one or more solid bodies", theSolids) = Selection.Response.Cancel Then
' Return
'End If
Dim theObjects As New List(Of DisplayableObject)
If SelectObjects("Select one or more objects", theObjects) = Selection.Response.Cancel Then
Return
End If
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
'$ change color and layer to desired values before running journal
displayModification1.NewColor = 103
displayModification1.NewLayer = 12
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
displayModification1.Apply(theObjects.ToArray)
displayModification1.Dispose()
End Sub
Function SelectSolids(ByVal prompt As String, ByRef tempBodies As List(Of Body)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select one or more solid bodies"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj() As TaggedObject
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj)
If resp = Selection.Response.Ok Then
For Each temp As Body In selObj
tempBodies.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Function SelectObjects(prompt As String, _
ByRef objList As List(Of DisplayableObject)) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All, _
Selection.SelectionType.Faces, _
Selection.SelectionType.Edges}
Dim selObj() As TaggedObject
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects( _
prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selObj)
If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.Ok Then
For Each temp As DisplayableObject In selObj
objList.Add(temp)
Next
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
The same using SNAP
Just for fun and variety, here's what the code looks like if you call SNAP functions:
Option Infer On
Imports Snap.UI
Public Class MyProgram
Public Shared Sub Main()
' Create a selection dialog for selecting objects
Dim dialog = Selection.SelectObject("Please select objects")
dialog.AllowMultiple = True
' Display the dialog and get a result
Dim result = dialog.Show()
Dim response = result.Response
' If the user didn't press Cancel or Back, then ...
If response <> Response.Cancel And response <> Response.Back Then
' Loop to change the selected objects
For Each obj In result.Objects
obj.Layer = 20
obj.Color = System.Drawing.Color.Green
Next
End If
End Sub
End Class
Hello
Hello
In above 2nd last journal I can select surface and curve but not able to put in layers.where has in last journal something is incorrect in 9th line when I ran the journal error message in 9th line of the journal.
re: surface and curves to layers
Be aware of exactly what you are selecting with the journal. If you select a "face", the color will change but it cannot move to a different layer. Faces belong to a body object and you cannot move a face to a different layer than the body. After starting the journal, at the selection prompt, you can change the selection filter (in interactive NX) to further narrow the allowed selections to sheet body or solid body, in this case. Alternatively, you could remove the "faces" filter used in the journal code. This would ensure that you cannot inadvertently select face objects.
If you select a curve that belongs to a sketch, it will be moved to a different layer. However, at the next part update, NX may move it back to the same layer as the sketch. If you want to move entire sketches, we might have to adjust the selection filter to allow selection of sketches (the filter used in the journal code, not the interactive NX selection filter).
I assume you will need a SNAP license to run the SNAP code. I can't really comment on it further than that.
Thank you it's working great.
Thank you it's working great.