nathangaldamez
New member
- Jul 13, 2011
- 15
I'm using the code below to select and change the color of a face that I created using the "Ruled" feature. I was wondering if it's possible to obtain the "RULED(545)" name from using a function such as object.tag, but 'tag' only returns the tag number not the RULED number.
This is the coded that I'm using, which I just copied and pasted from another forum:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module changeColorOfPreSelectedFaces_v2
Dim theSession As Session = Session.GetSession()
Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager
Sub Main()
'' Integer variable to store color code in.
Dim newColorCode As Integer = 114
'' While loop to ensure that color code is Integer value
While 1
newColorCode = Convert.ToInt32(NXInputBox.GetInputNumber("Color code:", "Enter New Face Color Code", 1))
If newColorCode > 0 And newColorCode < 217 Then
Exit While
End If
MsgBox("Code must be Integer between 1 and 216")
End While
'' The selectFaces method takes an NXobject array by reference
Dim selectedObjectsArray() As NXObject
SelectFaces(selectedObjectsArray)
'' Need to recast the face NXObjects to Displayable objects
Dim faceArray(selectedObjectsArray.Length - 1) As DisplayableObject
For i As Integer = 0 To selectedObjectsArray.Length - 1
faceArray(i) = CType(selectedObjectsArray(i), DisplayableObject)
Next
'' A display modification object is used to change to color of the faces.
Dim changeFaceColor As DisplayModification = theSession.DisplayManager.NewDisplayModification()
With changeFaceColor
.ApplyToAllFaces = False
.NewColor = newColorCode
.Apply(faceArray)
.Dispose()
End With
End Sub
'' The following routine is from GTAC
' ----------------------------------------------
' sub to select faces
' ----------------------------------------------
Sub SelectFaces(ByRef selectedObjects As NXObject())
Dim ui As UI = NXOpen.UI.GetUI
Dim message As String = "Select Faces"
Dim title As String = "Selection"
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = False
Dim response As Selection.Response
Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With
response = ui.SelectionManager.SelectObjects(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObjects)
If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
Return
End If
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
This is the coded that I'm using, which I just copied and pasted from another forum:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module changeColorOfPreSelectedFaces_v2
Dim theSession As Session = Session.GetSession()
Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager
Sub Main()
'' Integer variable to store color code in.
Dim newColorCode As Integer = 114
'' While loop to ensure that color code is Integer value
While 1
newColorCode = Convert.ToInt32(NXInputBox.GetInputNumber("Color code:", "Enter New Face Color Code", 1))
If newColorCode > 0 And newColorCode < 217 Then
Exit While
End If
MsgBox("Code must be Integer between 1 and 216")
End While
'' The selectFaces method takes an NXobject array by reference
Dim selectedObjectsArray() As NXObject
SelectFaces(selectedObjectsArray)
'' Need to recast the face NXObjects to Displayable objects
Dim faceArray(selectedObjectsArray.Length - 1) As DisplayableObject
For i As Integer = 0 To selectedObjectsArray.Length - 1
faceArray(i) = CType(selectedObjectsArray(i), DisplayableObject)
Next
'' A display modification object is used to change to color of the faces.
Dim changeFaceColor As DisplayModification = theSession.DisplayManager.NewDisplayModification()
With changeFaceColor
.ApplyToAllFaces = False
.NewColor = newColorCode
.Apply(faceArray)
.Dispose()
End With
End Sub
'' The following routine is from GTAC
' ----------------------------------------------
' sub to select faces
' ----------------------------------------------
Sub SelectFaces(ByRef selectedObjects As NXObject())
Dim ui As UI = NXOpen.UI.GetUI
Dim message As String = "Select Faces"
Dim title As String = "Selection"
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = False
Dim response As Selection.Response
Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim selectionMask_array(1) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.Subtype = 0
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
End With
response = ui.SelectionManager.SelectObjects(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObjects)
If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
Return
End If
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module