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!

Journal - add object to array

Status
Not open for further replies.

MANox

Mechanical
Joined
Apr 2, 2007
Messages
130
Location
PL
Hello,

I have problem with journal:
I use SelectsObject for create first group/array of Lines p.ex. FirstGroup As NXObject.
After for each element in FirstGroup I create new line (p.ex perpendicular in intersectionpoint with face).
And I want add every line to second group/array (SecondGroup As NX Object).

If I must add this element by select on screen - it's no problem.
But when I must add new element to existing array - I don't know what I must doing.

I think it's easy, but I don't know...
Mayby somebody can help me?

Best regards

Michał Nowak
 
I suggest using list objects instead of arrays. The list objects have methods for adding/removing objects from the list and the list will take care of resizing and other tedious 'bookkeeping' tasks. The following thread may be of interest to you:
thread561-366364


Here's some example code that works with point objects; create a new file and add a few points. Run the journal and select at least 1 point object.

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

Module Module13
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUi As UI = UI.GetUI
        Dim workPart As Part = theSession.Parts.Work
        Dim rnd1 As New Random()
        Dim max As Integer
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim myPoints As New List(Of Point)

        If SelectPoints("Select points", myPoints) = Selection.Response.Cancel Then
            Return
        End If

        MsgBox("number of points selected: " & myPoints.Count.ToString & ControlChars.NewLine & _
               "That's not enough, let's add 100 more")


        If workPart.PartUnits = Part.Units.Inches Then
            max = 10
        Else    'metric file
            max = 250
        End If

        'create Point3d using the constructor
        Dim myPt1 As New Point3d(0, 0, 0)

        For i As Integer = 0 To 99
            'change values of myPt1 using random numbers
            myPt1.X = rnd1.Next(-max, max) + rnd1.NextDouble
            myPt1.Y = rnd1.Next(-max, max) + rnd1.NextDouble
            myPt1.Z = rnd1.Next(-max, max) + rnd1.NextDouble
            Dim newPt As Point
            newPt = workPart.Points.CreatePoint(myPt1)
            newPt.SetVisibility(SmartObject.VisibilityOption.Visible)
            myPoints.Add(newPt)
        Next

        For Each tempPt As Point In myPoints
            tempPt.Highlight()
        Next

        workPart.Views.WorkView.UpdateDisplay()
        MsgBox("The list, 'myPoints', now contains: " & myPoints.Count.ToString & " points")

        For Each tempPt As Point In myPoints
            tempPt.Unhighlight()
        Next

        'if you need the point objects in an array (some NXOpen API functions only accept an array),
        'use myPoints.ToArray - this will return an array of the objects that are in the list

    End Sub

    Function SelectPoints(ByVal prompt As String, ByRef thePoints As List(Of Point)) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select points"
        Dim includeFeatures As Boolean = False
        Dim keepHighlighted As Boolean = False
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim selectionMask_array(0) As Selection.MaskTriple
        Dim selObj() As TaggedObject

        With selectionMask_array(0)
            .Type = NXOpen.UF.UFConstants.UF_point_type
            .Subtype = NXOpen.UF.UFConstants.UF_all_subtype
        End With

        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selObj)
        If resp = Selection.Response.Ok Then
            For Each tempObj As Point In selObj
                thePoints.Add(tempObj)
            Next
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function


End Module

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

Part and Inventory Search

Sponsor

Back
Top