Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

NX8 - Journal - Filtering GetAllObjectsonLayer 1

Status
Not open for further replies.

jmarkus

Mechanical
Joined
Jul 11, 2001
Messages
377
Location
CA
I am using

Code:
allObjects = workPart.Layers.GetAllObjectsOnLayer(lay)

To get all of the objects on layer "lay" in my list. However, I actually only want to keep objects of type curve, point, solid body or sheet body in that list and no other types.

How I can filter out my list?

Thanks,
Jeff
 
I'd suggest creating a list for each type of object you are interested in then loop through your array of objects, use the TypeOf() operator to determine what type of object you have and add it to the appropriate list.

Code:
for each someObject as TaggedObject in allObjects
    if TypeOf(someObject) is NXOpen.Body then
        theBodyList.add(someObject)
    end if
    if TypeOf(someObject) is NXOpen.Point then
        thePointList.add(someObject)
    end if
    ...
    etc
    etc
next


www.nxjournaling.com
 
But if I put the objects into an ArrayList() how do I get it out again as NXObject() - which is the type I need to work with?

Thanks,
Jeff
 
Don't use an ArrayList, use a list of the type you need. Avoid ArrayLists entirely.

If you don't need to access the different object types individually (e.g. you are going to change the layer or color of all the objects simultaneously), I'd suggest creating one list of type NXObject (or, for my example, DisplayableObjects). The logic in the example above still holds, you would still loop through your existing array and look for the object types of interest. When one is found, add it to the master list instead of individual lists. If a function or method requires an array as input, you can use the list's .ToArray method.

Code:
Imports System.Collections.Generic
.
.
.
Dim masterList as New List(Of DisplayableObject)

for each someObject as NXObject in allObjects
    if TypeOf(someObject) is NXOpen.Body then
        masterList.add(someObject)
    end if
    if TypeOf(someObject) is NXOpen.Point then
        masterList.add(someObject)
    end if
    ...
    etc
    etc
next

Dim displayMod1 as DisplayModification
.
.
displayMod1.NewColor = 123
displayMod1.Apply(masterList.ToArray)
displayMod1.dispose
.
.
.

www.nxjournaling.com
 
Thanks Cowski! I think I get it now.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top