×
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

Journal - add object to array

Journal - add object to array

Journal - add object to array

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

RE: Journal - add object to array

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: "NXOpen.NXException.Invalid file name" error message


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

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