Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal - Getting Objects on Multiple Layers into one collection/array 1

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
0
16
CA
Hi,

I have an NX Journal in VB which grabs all the objects on layer 1 by using:

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

If I want to ADD all the objects on a DIFFERENT layer to allObjects, I'm not sure how to do that. Essentially I want to append the objects on the different layer into the 'allobjects' collector, but I don't see a straightforward way to do this using the VB scripting.

Can someone point me in the right direction?

Thanks,
Jeff
 
Replies continue below

Recommended for you

I'd suggest using a list object for this.

Code:
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module196
    Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main(ByVal args() As String)

        lw.Open()

        Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "journal")

        Dim myObjects As New List(Of NXObject)

        myObjects.AddRange(theSession.Parts.Work.Layers.GetAllObjectsOnLayer(1))
        lw.WriteLine("number of objects on layer 1: " & myObjects.Count.ToString)

        myObjects.AddRange(theSession.Parts.Work.Layers.GetAllObjectsOnLayer(2))
        lw.WriteLine("number of objects on layer 1 and 2: " & myObjects.Count.ToString)


        lw.Close()
    End Sub

End Module

www.nxjournaling.com
 
List objects are very convenient, I use them a lot in my journals. A list is like an array in that it can hold a number of related objects but it is much more convenient to add new objects to the list. The list has an .Add method and will take care of resizing the list for you; no need to declare how many items the list will hold or using redim preserve to change the number of objects it can hold. Anywhere the NXOpen API expects an array of objects, you can use the list's .ToArray method to convert the list to an array on the fly.

www.nxjournaling.com
 
Status
Not open for further replies.
Back
Top