Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

(NX1980) Objects Not Properly Highlighting When Selected in Journal 1

Status
Not open for further replies.

LHolm

Industrial
Feb 17, 2020
6
I'm writing a small program to allow a user to add specified text to selected dimensions. Depending on the orientation of the selected dimensions, the placement of the text will vary ("after" for horizontal dimensions, "below" for vertical). Some dimensions are a subtype that is neither 1(horizontal) nor 2(vertical), and therefore require further user input to decide where to place the appended text (after or below).

What I want to do is have the user select all the dimensions to which they want to append text. Then, if any of those are not subtype 1 or 2, cycle through the dimensions in question, highlighting each in turn and asking where the appended text should go.

The problem is that the .Highlight() Method doesn't appear to be working as I had hoped. The .Highlight() Method doesn't seem to be updating the dimensions' highlighted status mid-journal, as I would need it to in order for the user to know what dimension needs a decision to be made. From what I can tell, highlighting only works how I'd like it to while the user has just selected an object with the SelectionManager. You can see what I'm talking about if you run the code below. After selecting a dimension, it is added to a list which is then cycled through and each item highlighted in turn. As long as you keep selecting new dimensions, this works as intended. Once you respond with anything other than selecting an object (Back, Cancel, or Ok), the highlighting loop stops working.

If this is just a how NXOpen works, I can find a way to live with it. But I'm hoping there's a way to make highlighting work the way I'd prefer, rather than working around it.

Code:
' LOUIS HOLM
' 03-07-22
' RED BUD INDUSTRIES

Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
	Dim objUI As UI = UI.GetUI
	Dim objUFS As UFSession = UFSession.GetUFSession()
	Dim objSession As Session = Session.GetSession()
	
	Sub Main (ByVal args() As String)
		Dim intResponse As Integer
		Dim objSelected As TaggedObject
		Dim pntSelect As Point3D
		Dim lstSelected As New Collections.Generic.List(Of TaggedObject)
		Dim intType As Integer
		Dim intSubtype As Integer
		Dim objDisplayable As DisplayableObject

		While intResponse <> 2
			intResponse = objUI.SelectionManager.SelectTaggedObject("prompt", "title", Selection.SelectionScope.AnyInAssembly, False, Selection.SelectionType.All, objSelected, pntSelect)
			If Not lstSelected.Contains(objSelected) And objSelected IsNot Nothing Then
				lstSelected.Add(objSelected)
			End If
			
			For Each fSelected As TaggedObject In lstSelected
				objUFS.Obj.AskTypeAndSubtype(fSelected.Tag, intType, intSubtype)
				If intType = 26 Then ' Is Dimension
					objDisplayable = CType(fSelected, DisplayableObject)
					objDisplayable.Highlight()
					MsgBox("Highlighted selection has subtype: " & intSubtype)
					objDisplayable.Unhighlight()
				End If
			Next
		End While
		
	End Sub
End Module
 
 https://files.engineering.com/getfile.aspx?folder=7c9cd7cd-f6d6-44ac-86d4-c4b8d92dc5b6&file=HighlightTest.vb
Replies continue below

Recommended for you

Updating the work view seems to help.

Code:
' LOUIS HOLM
' 03-07-22
' RED BUD INDUSTRIES

Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
	Dim objUI As UI = UI.GetUI
	Dim objUFS As UFSession = UFSession.GetUFSession()
	Dim objSession As Session = Session.GetSession()
	
	Sub Main (ByVal args() As String)
		Dim intResponse As Integer
		Dim objSelected As TaggedObject
		Dim pntSelect As Point3D
		Dim lstSelected As New Collections.Generic.List(Of TaggedObject)
		Dim intType As Integer
		Dim intSubtype As Integer
		Dim objDisplayable As DisplayableObject

		While intResponse <> 2
			intResponse = objUI.SelectionManager.SelectTaggedObject("prompt", "title", Selection.SelectionScope.AnyInAssembly, False, Selection.SelectionType.All, objSelected, pntSelect)
			If Not lstSelected.Contains(objSelected) And objSelected IsNot Nothing Then
				lstSelected.Add(objSelected)
			End If
			
			For Each fSelected As TaggedObject In lstSelected
				objUFS.Obj.AskTypeAndSubtype(fSelected.Tag, intType, intSubtype)
				If intType = 26 Then ' Is Dimension
					objDisplayable = CType(fSelected, DisplayableObject)
					objDisplayable.Highlight()
					[highlight #FCE94F]objSession.parts.work.views.workview.updatedisplay[/highlight]
					MsgBox("Highlighted selection has subtype: " & intSubtype)
					objDisplayable.Unhighlight()
				End If
			Next
		End While
		
	End Sub
End Module

www.nxjournaling.com
 
I can't believe I hadn't tried that. Thanks cowski!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor