Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX11 - Journal Help Please

Status
Not open for further replies.

Kenja824

Automotive
Nov 5, 2014
949

Im trying to record a journal where it will fit all on the screen, then select all according to these filters....
Type = Solid Body
Attribute Filter - User Definied Attributes....
Attribute Type = String
Title = CONTROL DIRECTION
Low String Value = CROSS/CAR
High String Value = CROSS/CAR

(I am not sure if both LOW and HIGH need to be filled but it worked for me on tests that way. lol)

Once filters are set, I need it to select all bodies. (Recording a journal only lists each particular body being selected) Then it will change the color of the solid bodies to Color 78.

I actually was trying to record one that would do this over again for a total of 6 colors according to the Attribute filter.

It wouldnt record right as a journal as it doesnt record the filters or the SELECT ALL on the solid bodies. So I tried to record a macro instead. This worked good but in testing it, I learned that if the case came up where one of the filters did not find any solid bodies, it would error out and not finish.

Can anyone help with this?
 
Replies continue below

Recommended for you

I found this code and adjusted it to select bodies.... it works great for changing the color to all bodies on a specific layer. Can anyone help me with how to change the filters so it ignores the layer and works with String Attributes?


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim answer as String
dim layerNumber as Integer = 2
dim i as Integer = 0

Dim lw As ListingWindow = theSession.ListingWindow
Dim allObjects as NXObject()
Dim BodyObject as Body

allObjects = workPart.Layers.GetAllObjectsOnLayer(layerNumber)
lw.Open
for each someObject as NXObject in allObjects
' lw.WriteLine(someObject.GetType.ToString)
if someObject.GetType.ToString = "NXOpen.Body" then
BodyObject = someObject
BodyObject.Color = 216
BodyObject.RedisplayObject
i += 1
end if
next
lw.WriteLine(i & " Bodies processed on layer: " & layerNumber)
lw.Close

End Sub
End Module
 
I mean to use the String Attribute in place of the layer filter.
 
Try this:

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

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "body color by attribute")

        lw.Open()

        Const attTitle As String = "CONTROL DIRECTION"
        Const attValue As String = "CROSS/CAR"
        Const newBodyColor As Integer = 78
        Dim bodies1 As New List(Of Body)

        For Each temp As Body In theSession.Parts.Work.Bodies
            If temp.IsSheetBody Then
                'skip sheet bodies
                Continue For
            End If

            If temp.HasUserAttribute(attTitle, NXObject.AttributeType.String, -1) Then
                If temp.GetStringUserAttribute(attTitle, -1).ToUpper = attValue Then
                    bodies1.Add(temp)
                End If
            End If
        Next

        Dim displayModification1 As DisplayModification
        displayModification1 = theSession.DisplayManager.NewDisplayModification()
        displayModification1.ApplyToAllFaces = True
        displayModification1.NewColor = newBodyColor
        displayModification1.Apply(bodies1.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
 
Hey Cowski

GM sent over new macros and I moved onto a new project and never saw this reply until now. Sorry.

Since I would rather use a journal and not macros I tried this out but it didnt seem to do anything. It seemed to run through it and I thought I saw something flicker in NX11, but no colors changed or anything. I have been studying it hoping I could figure it out on my own (fat chance of that lol) then I finally decided to post a reply.

One thing I did notice however, is in reading through this, I noticed this code....

For Each temp As Body In theSession.Parts.Work.Bodies
If temp.IsSheetBody Then
'skip sheet bodies
Continue For
End If

I know I'm limited to my understanding of code, but does this say it is selecting bodied in the work part only and then take all bodies that are not Sheet Bodies?

I would need it to select only Solid-bodies and this would be in all parts available. The only way I could imagine to set a filter on the type of bodies to do the job, would be to only select solid body spheres.

Still, to be clear, only bother yourself with this if you have extra time and are interested in figuring it out. Since we do have the new macros from GM that work now, I dont actually need these per say. I would jusr prefer to use journals so they dont need to be replaced the next time we upgrade. ... and for my own understanding of course. Though its very little at a time, I learn from comparing journals and seeing what they do. lol
 
Kenja824 said:
...does this say it is selecting bodied in the work part only and then take all bodies that are not Sheet Bodies?

Yes, it only operates on solid bodies in the current work part. If an assembly is the current work part, it will only operate on bodies owned by the assembly file itself - not any component bodies.

www.nxjournaling.com
 
> GM sent over new macros ...
> I would rather use a journal and not macros

People are not always very careful in their use of the word "macro". A lot of people call VB programs "macros". I would be very surprised if GM was sending real NX macros to people, because macros have numerous well-known problems.
 
BubbaK

>> I would rather use a journal and not macros
My original quote (above) is evidence in itself that I do know the difference.

I often have to use a computer program called WESS that GM gave us to use and insists on us using, yet they no longer support it and it hasnt been updated since 2003. There are more glitches in that program now than any I work on.... except for the new Operator Timing program they recently put out to us and we have to sign onto their portal to use. That one is a new program and has more glitches than the one that hasnt been updated since 2003.

I suck at code, but when I say macro, I mean they gave us new macros and not journals. And it doesnt surprise me in the slightest. lol
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor