×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

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

Students Click Here

Jobs

Selecting all objects on a layer as part of a journal

Selecting all objects on a layer as part of a journal

Selecting all objects on a layer as part of a journal

(OP)
I am looking to automate the process of changing the color of a point cloud (imported from an iges file) located on a specific layer. When I step through a journal of this processes, each point is individually selected with its coordinates displayed, which is a problem because every file will have different point cloud data.

I'm sure there is some function that I can include in a journal file to select all objects on a layer, but I have not been able to find this. Any help would be appreciated.

RE: Selecting all objects on a layer as part of a journal

Here's a quick journal that collects all the objects on layer 1 (can be changed in the journal).

CODE

Option Strict Off
Imports System
Imports NXOpen

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 lw As ListingWindow = theSession.ListingWindow
Dim allObjects as NXObject()

allObjects = workPart.Layers.GetAllObjectsOnLayer(1)
lw.Open
for each someObject as NXObject in allObjects
    lw.WriteLine(someObject.GetType.ToString)
next
lw.Close

End Sub
End Module

RE: Selecting all objects on a layer as part of a journal

(OP)
Thanks for the reply. I'm not sure I was very clear in the op. I would like to be able to call a function or something that would allow for manipulation of all objects on a certain layer. In one example, I might want to make all the points in a point cloud imported from an iges file be black instead of the default green on layer 2, while on layer 3 they should all be turned red.

When I create a journal file to do this, there is a seperate line for each individual point, like this:

CODE

Dim point1 As Point = CType(workPart.Points.FindObject("HANDLE R-203321"), Point)

objects1(0) = point1
Dim point2 As Point = CType(workPart.Points.FindObject("HANDLE R-203300"), Point)

objects1(1) = point2
Dim point3 As Point = CType(workPart.Points.FindObject("HANDLE R-203136"), Point)

objects1(2) = point3
Dim point4 As Point = CType(workPart.Points.FindObject("HANDLE R-203439"), Point)

objects1(3) = point4
Dim point5 As Point = CType(workPart.Points.FindObject("HANDLE R-203296"), Point)

objects1(4) = point5

This code won't be very repeatable when I have a new file with a new point cloud that will have a different number of point coordinates. It seems like there would be some function that would allow the selection of everything on a layer so that you could modify it all at once (changing the color, moving the objects to a different layer, etc.)

We are currently using NX5, but will be transitioning to NX8 within a few weeks, so all the automation tasks I am working on have been in NX8.
 

RE: Selecting all objects on a layer as part of a journal

Building on the previous example, here is one way to do it (not necessarily the best method).

CODE

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 pointObject as Point

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

End Sub
End Module

RE: Selecting all objects on a layer as part of a journal

(OP)
Thanks for the help cowski.

I can also see how I can use this to change the colors of bodies as well by changing the lines:

CODE

Dim pointObject as Point

allObjects = workPart.Layers.GetAllObjectsOnLayer(layerNumber)
lw.Open
for each someObject as NXObject in allObjects
'    lw.WriteLine(someObject.GetType.ToString)
    if someObject.GetType.ToString = "NXOpen.Point" then

to

CODE

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

I had two more questions:

1. How would I use this method to also make a body translucent? I hoped that "pointObject.Translucency = 60" would work, but no such luck. How do you know these commands anyway? Just experience? Is there a reference somewhere?

2. How would I move or copy objects from one layer to another once selected?

I really appreciate the help.  

RE: Selecting all objects on a layer as part of a journal

The following code shows how to move/copy object to another layer and another way (probably more efficient) to change the display properties of objects.

CODE

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 pointObject as Point
Dim myPoints as DisplayableObject()

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

allObjects = workPart.Layers.GetAllObjectsOnLayer(layerNumber)
lw.Open
for each someObject as NXObject in allObjects
'    lw.WriteLine(someObject.GetType.ToString)
    if someObject.GetType.ToString = "NXOpen.Point" then
        redim preserve myPoints(i)
        myPoints(i) = someObject
        i += 1
    end if
next

'move or copy object to another layer using the layer manager
'workPart.Layers.MoveDisplayableObjects(4, myPoints)

workPart.Layers.CopyObjects(5, myPoints)

With displayModification1
    .NewColor = 216
    'move layers with a display modification
    .NewLayer = 3
    '.NewTranslucency = 60        'only applies to faces; you can set this for points, but it will have no effect
    .Apply(myPoints)
    .Dispose
End With
lw.WriteLine(myPoints.Length & " points processed on layer: " & layerNumber)
lw.WriteLine("points copied to layer 5 (original color)")
lw.WriteLine("points moved to layer 3 and color changed to black")

lw.Close

End Sub
End Module

How do I know about this stuff? I have some past experience with Visual basic (VB 5&6, VBA in MSOffice - mostly Excel) which helps with the programming/debugging aspect. For the NX specific stuff, I mostly record journals and look at the output code; or look at code that other people have written (some sample .NET code is installed along with NX in <NX install directory path>\UGOPEN\SampleNXOpenApplications\.NET). When I see something new that looks interesting, I'll look it up in the .NET reference guide (NX Help -> Automation -> NX Open -> Open for .NET -> NX Open for .NET reference guide). Also in Automation -> NX Open is the NX Open Programmer's Guide which gives some background and theory.

RE: Selecting all objects on a layer as part of a journal

(OP)
This has been extremely instructive cowski. Thank you very much for taking the time.

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.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources