×
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 Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

(OP)
Hi

I have a journal that grab assembly parts by the following statement

CODE -->

Dim sparts As Part() = s.Parts.ToArray() 

and do somthing with the parts. but I found that the parts array
contains parts from other assembly part in the session.

and I want only parts from the assembly part that the journal itself open
and manipulate.

How I can do that.

I'm using nx 8.5
and run this journal on NX Manger platform.

Thanks in advanced.




RE: Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

I assume that your "s" variable is a reference to the NX Session; if so, the session.parts array holds all the parts currently open in the session regardless of what assembly they belong to (if any). One way to get the parts in a particular assembly is to get the root component of the assembly and use its .GetChildren method to find the first level components of the assembly. If you need to get all the components in the assembly (components of sub-assemblies), you can use recursion to process all the components in the assembly. An example of this can be found here.

www.nxjournaling.com

RE: Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

(OP)
Thank you Cowski

That's a brief and good explained example.

RE: Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

(OP)
I browsed the code and I don't see
why it will not work on nx manager.

When I'll be on accessible nx manager I'll try it.

Thank you.

RE: Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

I just tested on teamcenter (TC 10, NX 9) using a small assembly and it worked without error.

www.nxjournaling.com

RE: Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

(OP)
Thank you a lot.

RE: Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

If you have SNAP, then you don't need the recursive code to find children of children of children, ....

You just get the root component, and use its Descendents property. This property has internal logic that does all the recursion for you.

There are lots of examples of this sort of thing in the Assemblies chapter of the "Getting Started with SNAP" document.

RE: Journal Quastion on this statement ==> Dim sparts As Part() = s.Parts.ToArray()

(OP)

BubbaK Thank you your notice. (I have not a SNAP)

I found this GTAC journal with non-recursive sub for getting all components.
and I wonder witch one is more fastest the recursive one or the non-recursive one

CODE -->

'Date:  5-JUN-2008
'Subject:  Sample NX Open .NET Visual Basic program : rename components to part number

'Note:  GTAC provides programming examples for illustration only, and
'assumes that you are familiar with the programming language being
'demonstrated and the tools used to create and debug procedures.  GTAC
'support professionals can help explain the functionality of a particular
'procedure, but we will not modify these examples to provide added
'functionality or construct procedures to meet your specific needs.

'
' this should rename components in the current displayed part
' to the NXManager Part Number.
'
' Note that they will ONLY be renamed in the displayed part.
'
' So if part C is a component of part B and B is a component
' in part A, and A is the displayed part, component C will be 
' renamed in A.  If you make B the displayed part, then
' component C will not appear to be renamed in that context.
'

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module rename_components_to_part_number

   Public s As Session = Session.GetSession()
   Public ufs As UFSession = UFSession.GetUFSession()
   Public lw As ListingWindow = s.ListingWindow

   Sub Main()

      Dim is_active As Boolean = False
      ufs.UF.IsUgmanagerActive(is_active)
      If is_active = False Then
         MsgBox("This program should be used in an NXManager environment.", _
                                                      MsgBoxStyle.Exclamation)
         Return
      End If

      Dim dp As Integer = 0
      dp = check_for_missing_display_part()

      If dp = 1 Then
         Return
      End If

      Dim dispPart As Part = s.Parts.Display
      Dim thisComp As NXOpen.Tag = NXOpen.Tag.Null

      Do
         thisComp = ask_next_component(dispPart.Tag, thisComp)
         If thisComp <> NXOpen.Tag.Null Then
            Dim partName As String = ""
            Dim refsetName As String = ""
            Dim instanceName As String = ""
            Dim origin(2) As Double
            Dim csysMatrix(8) As Double
            Dim transform(3, 3) As Double
            ufs.Assem.AskComponentData(thisComp, partName, refsetName, _
                             instanceName, origin, csysMatrix, transform)

            Dim partNumber As String = ""
            partNumber = ask_component_part_number(partName, thisComp)
            Dim thisInstance As NXOpen.Tag = _
                                ufs.Assem.AskInstOfPartOcc(thisComp)

            ' this changes what shows up in Component Properties->General->Name
            ufs.Obj.SetName(thisComp, partNumber)

            ' uncomment the following line to change the instance name
            'ufs.Assem.RenameInstance(thisInstance, partNumber)


         End If

      Loop Until thisComp = NXOpen.Tag.Null


   End Sub

   Public Function ask_component_part_number(ByVal partName As String, _
                                    ByVal comp As NXOpen.Tag) As String
      Dim partNumber As String = ""
      Dim partRev As String = ""
      Dim partFileType As String = ""
      Dim partFileName As String = ""
      ufs.Ugmgr.DecodePartFileName(partName, partNumber, _
                                   partRev, partFileType, partFileName)
      Return partNumber

   End Function

   Public Function ask_next_component(ByVal dispPartTag As NXOpen.Tag, _
                              ByVal comp As NXOpen.Tag) As NXOpen.Tag
      Dim type As Integer = 0
      Dim subtype As Integer = 0

      Do
         ufs.Obj.CycleObjsInPart(dispPartTag, _
                                 UFConstants.UF_component_type, comp)
         If NXOpen.Tag.Null = comp Then
            Return comp
         End If

         ufs.Obj.AskTypeAndSubtype(comp, type, subtype)

         If subtype = UFConstants.UF_part_occurrence_subtype Then
            Return comp
         End If

      Loop Until comp = NXOpen.Tag.Null

      Return comp

   End Function

   Public Function check_for_missing_display_part() As Integer

      Dim dispPart As Part = Nothing

      Try
         dispPart = s.Parts.Display
      Catch ex As Exception
         lw.Open()
         lw.WriteLine("+++Error: " & ex.ToString())
      End Try

      If dispPart Is Nothing Then
         lw.Open()
         lw.WriteLine("There is no current Displayed Part")
         ufs.UF.PrintSyslog("+++ERROR: There is no current Displayed Part", _
                                                                       False)
         Return 1
      End If
      Return 0

   End Function

   Public Function GetUnloadOption(ByVal dummy As String) As Integer

      Return Session.LibraryUnloadOption.Immediately

   End Function

End Module 

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