I am sharing my tool to change body color to a value which is given as a parameter of Journal.
'ColorBody by wizdar ()
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main(params() As String)
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim myBody As Body
Do Until SelectBody("select a body", myBody) = Selection.Response.Cancel
Dim displayModification1 As DisplayModification
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
displayModification1.NewColor = params(0)
Dim objects1(0) As DisplayableObject
objects1(0) = myBody
displayModification1.Apply(objects1)
displayModification1.Dispose()
Loop
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
Function SelectBody(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a solid body"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_solid_type
.SolidBodySubtype = UFConstants.UF_UI_SEL_FEATURE_SOLID_BODY
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
End Module
Additionally a thing I could not find anywhere... is how to insert the parameter in a toolbar .tbr file instead of EditAction in "Customize->New Item"
ACTION code.vb("parameter string")
TITLE MyTools
VERSION 160
BEGIN_DROPDOWN Colors
BUTTON FlameColor
LABEL FlameColor
BITMAP D:\UG_Journal\Toolbar\11.bmp
ACTION D:\UG_Journal\Toolbar\Color.vb("11")
BUTTON BlankColor
LABEL BlankColor
BITMAP D:\UG_Journal\Toolbar\15.bmp
ACTION D:\UG_Journal\Toolbar\Color.vb("15")
BUTTON NCColor
LABEL NCColor
BITMAP D:\UG_Journal\Toolbar\50.bmp
ACTION D:\UG_Journal\Toolbar\Color.vb("50")
BUTTON WeldColor
LABEL WeldColor
BITMAP D:\UG_Journal\Toolbar\91.bmp
ACTION D:\UG_Journal\Toolbar\Color.vb("91")
BUTTON AluColor
LABEL AluColor
BITMAP D:\UG_Journal\Toolbar\3.bmp
ACTION D:\UG_Journal\Toolbar\Color.vb("3")
END_DROPDOWN
re: passing parameter
Excellent!
Thanks for sharing.