Forums:
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 OffImports System Imports NXOpen Imports NXOpen.UF Module Module1 Sub Main(params()AsString) 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() EndSub PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination EndFunction Function SelectBody(ByVal prompt AsString, ByRef selObj As TaggedObject)As Selection.Response Dim theUI As UI = UI.GetUIDim title AsString="Select a solid body"Dim includeFeatures AsBoolean=FalseDim keepHighlighted AsBoolean=FalseDim selAction As Selection.SelectionAction= Selection.SelectionAction.ClearAndEnableSpecificDim cursor As Point3d Dim scope As Selection.SelectionScope= Selection.SelectionScope.AnyInAssemblyDim selectionMask_array(0)As Selection.MaskTriple With selectionMask_array(0) .Type= UFConstants.UF_solid_type .SolidBodySubtype= UFConstants.UF_UI_SEL_FEATURE_SOLID_BODYEndWith 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.ObjectSelectedByNameThenReturn Selection.Response.OkElseReturn Selection.Response.CancelEndIf EndFunction 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