Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Color changing journal, please help? 2

Status
Not open for further replies.

IvanNX

Mechanical
Jun 9, 2005
267
SE
I have to change the colors of hundreds of parts (using 20+ different colors) and I do not know how to make this journal work.
Here is the journal that I recorded, all I need to be edited is to select all solid bodies in part and to apply color with number form NX color scheme, like color 11 for example for "Light Yellow Spring" so that I can manually copy/past journal and edit it to use it for 20+ colors that I need.

THANK YOU!

Code:
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Edit->Selection->Select All
' ----------------------------------------------
' Refer to the sample NXOpen application, Selection for "Select All" alternatives.
' ----------------------------------------------
'   Menu: Edit->Object Display...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start")

theSession.SetUndoMarkName(markId1, "Object Color Dialog")

' ----------------------------------------------
'   Dialog Begin Object Color
' ----------------------------------------------
Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Object Color")

theSession.DeleteUndoMark(markId2, Nothing)

Dim markId3 As NXOpen.Session.UndoMarkId = Nothing
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Object Color")

theSession.DeleteUndoMark(markId3, Nothing)

theSession.SetUndoMarkName(markId1, "Object Color")

theSession.DeleteUndoMark(markId1, Nothing)

Dim markId4 As NXOpen.Session.UndoMarkId = Nothing
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Edit Object Display")

Dim displayModification1 As NXOpen.DisplayModification = Nothing
displayModification1 = theSession.DisplayManager.NewDisplayModification()

displayModification1.ApplyToAllFaces = True

displayModification1.ApplyToOwningParts = False

Dim objects1(0) As NXOpen.DisplayableObject
Dim body1 As NXOpen.Body = CType(workPart.Bodies.FindObject("REVOLVED(6)"), NXOpen.Body)

objects1(0) = body1
displayModification1.Apply(objects1)

Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(markId4)

theSession.DeleteUndoMark(markId4, "Edit Object Display")

displayModification1.Dispose()
' ----------------------------------------------
'   Menu: File->Save
' ----------------------------------------------
Dim partSaveStatus1 As NXOpen.PartSaveStatus = Nothing
partSaveStatus1 = workPart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False)

partSaveStatus1.Dispose()
' ----------------------------------------------
'   Menu: Tools->Repeat Command->4 Stop Journal Recording
' ----------------------------------------------
' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

_____________________________
Enjoy your work and have fun!
 
Replies continue below

Recommended for you

Try the following:

Code:
Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module Module200

    Dim theSession As Session = Session.GetSession()

    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        If IsNothing(theSession.Parts.BaseDisplay) Then
            'need at least 1 open part
            Return
        End If

        lw.Open()

        Dim theSolids As New List(Of Body)
        'get the solid bodies from the current work part and add them to the list we created
        For Each tempBody As Body In theSession.Parts.Work.Bodies
            If tempBody.IsSolidBody Then
                theSolids.Add(tempBody)
            End If
        Next

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Object Display")

        Dim displayModification1 As DisplayModification
        displayModification1 = theSession.DisplayManager.NewDisplayModification()
        displayModification1.ApplyToAllFaces = False
        displayModification1.ApplyToOwningParts = False

        'the next line controls the new color, change it as desired before running the journal
        displayModification1.NewColor = 11

        displayModification1.Apply(theSolids.ToArray)
        displayModification1.Dispose()

        lw.Close()

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
HUGE THANK YOU COWSKI!!

_____________________________
Enjoy your work and have fun!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top