×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# NX11 - Journal Help Please

## NX11 - Journal Help Please

(OP)

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?

### RE: NX11 - Journal Help Please

(OP)
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 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

### RE: NX11 - Journal Help Please

(OP)
I mean to use the String Attribute in place of the layer filter.

### RE: NX11 - Journal Help Please

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
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

End Function

End Module 

### RE: NX11 - Journal Help Please

(OP)
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

### RE: NX11 - Journal Help Please

#### Quote (Kenja824)

...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.

### RE: NX11 - Journal Help Please

> 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.

### RE: NX11 - Journal Help Please

(OP)
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

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!