×
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

Using journal to select all

Using journal to select all

RE: Using journal to select all

What exactly are you trying to select? There are methods that allow you to select all the bodies in a part file or all objects on a given layer. If your "filter" is more complex, you'll probably have to sort through all the objects in code to find what you are after.

Here is a function taken from the GTAC solution center that might get you started:

CODE

'Date:  09/30/2010
'Subject:  Sample NX Open .NET Visual Basic routine : demo select all objects of given types
'
'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.

    Function getAllObjectsByTypes(ByVal whatTypes() As Integer) As DisplayableObject()  
        Dim objList As ArrayList = New ArrayList  
        Dim thisType As Integer = 0  
        Dim thisSubType As Integer = 0  

        For Each obj As DisplayableObject In s.Parts.Work.Views.WorkView.AskVisibleObjects  
            ufs.Obj.AskTypeAndSubtype(obj.Tag, thisType, thisSubType)  
            For Each aType As Integer In whatTypes  
                If aType = thisType Then  
                    objList.Add(obj)  
                End If  
            Next  
        Next  
        Return objList.ToArray(GetType(DisplayableObject))  
    End Function 

www.nxjournaling.com

RE: Using journal to select all

(OP)
In this instance I am trying to select circles. have the code check the information on the circle and input its radius as a variable in an expression.
For example
If D<2", then blank circle,
Elseif change color of circle to blue.
The problem is I usually have objects on different layers, around 1-100. This select all command is quite tedious for NX. Even when I do it through journal to see what code it refers to NX Open for samples of such code but I cannot find any.

RE: Using journal to select all

Here's some code that may get you started:

CODE

'eng-tips thread561-335918: Using journal to select all: Using journal to select all
'select displayed arcs, do something based on arc radius

Option Strict Off  
Imports System  
Imports NXOpen  

Module Module1  

    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim workPart As Part = theSession.Parts.Work  

 'Get visible objects in work view
        Dim visibleObjects() As DisplayableObject  
        visibleObjects = workPart.Views.WorkView.AskVisibleObjects  
        Dim tempArc As Arc  
        For Each tempObj As DisplayableObject In visibleObjects  
 'test if object is an arc
            If TypeOf tempObj Is Arc Then  
                tempArc = tempObj  
                If tempArc.Radius < 5 Then  
 'do something with small arc
                    tempArc.Blank()  
                Else  
 'do something else with large arc

                End If  
            End If  
        Next  

    End Sub  

End Module 

www.nxjournaling.com

RE: Using journal to select all

(OP)
Cowski, I have put this journal on the backburner for a while now, but I keep running into an error while trying to run the Displaymodification1.apply command.
I do not know what the arguments are and I am doing something run in the process of executing it. Please look at this when you get a chance and let me know if you see anything. Thanks in advanced.


CODE --> vb

'eng-tips thread561-335918: Using journal to select all: Using journal to select all: Using journal to select all: Using journal to select all
'select displayed arcs, do something based on arc radius

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.uf
Imports NXOpen.utilities
Imports NXOpen.Assemblies
Imports System.Windows.Forms
Imports System.IO
Imports System.Collections
Imports System.Environment
Imports NXOpenUI

Module Module1  

    Sub Main()  

        Dim S As Session = Session.GetSession()  
        Dim workPart As Part = S.Parts.Work 
        Dim ufs As UFSession = UFSession.GetUFSession() 
        Dim selobj As NXObject
        Dim arc1 as ibasecurve
        dim cpoint as point = nothing
        dim kk as integer=0
        Dim type As Integer
        Dim subtype As Integer
        Dim lw As ListingWindow = s.ListingWindow
        Dim layerObjects() As NXObject
        Dim layerObjectsDisplayable() As DisplayableObject
        Dim layerColorID(256) As Integer
        layerColorID(1) = 6

 'Get visible objects in work view
        Dim visibleObjects() As DisplayableObject  
        visibleObjects = workPart.Views.WorkView.AskVisibleObjects  
        Dim tempArc As Arc  

                Dim displayModification1 As DisplayModification
                displayModification1 = S.DisplayManager.NewDisplayModification()
                'displayModification1.NewColor = layerColorID(1)
                'displayModification1.NewFont = DisplayableObject.ObjectFont.LongDashed
                displayModification1.NewWidth = DisplayableObject.ObjectWidth.Thick
                displayModification1.ApplyToAllFaces = True
                displayModification1.ApplyToOwningParts = False

        For Each tempObj As DisplayableObject In visibleObjects  
'test if object is an arc
            If TypeOf tempObj Is Arc Then  
                tempArc = tempObj 
                If tempArc.Radius < 1 Then  
'do something with small arc
Dim objects1(0) As DisplayableObject
objects1(0) = temparc
displayModification1.Apply(objects1)
displayModification1.Dispose()
                End If  
            End If  
        Next  
    End Sub  
End Module 

RE: Using journal to select all

Try moving the Dispose command outside of the for loop. As it stands now, the displaymodification object is being destroyed when the first arc with radius < 1 is encountered.

CODE

For Each tempObj As DisplayableObject In visibleObjects  
            'test if object is an arc
            If TypeOf tempObj Is Arc Then  
                tempArc = tempObj 
                If tempArc.Radius < 1 Then  
                  'do something with small arc
                   Dim objects1(0) As DisplayableObject
                   objects1(0) = temparc
                   displayModification1.Apply(objects1)

                End If  
            End If  
        Next  
displayModification1.Dispose()
    End Sub 

Alternately, you may get slightly better performance by creating a list of objects, adding the desired objects to the list in the for loop then applying the display modification to the entire list at once after the for loop.

www.nxjournaling.com

RE: Using journal to select all

(OP)
I tried moving the dispose command down and it removed one of the errors I was recieving and gave me another one with the apply command.
I will try that, you wouldn't happen to have any sort of general list code that I could use to this would you?

RE: Using journal to select all

Try this:

CODE

'eng-tips thread561-335918: Using journal to select all: Using journal to select all
'select displayed arcs, do something based on arc radius

Option Strict Off  
Imports System  
Imports NXOpen  
Imports NXOpen.UF  
Imports NXOpen.Utilities  
Imports NXOpen.Assemblies  
Imports System.Windows.Forms  
Imports System.IO  
Imports System.Collections  
Imports System.Collections.Generic  
Imports System.Environment  
Imports NXOpenUI  

Module Module1  

    Sub Main()  

        Dim S As Session = Session.GetSession()  
        Dim workPart As Part = S.Parts.Work  
        Dim ufs As UFSession = UFSession.GetUFSession()  
        Dim selobj As NXObject  
        Dim arc1 As ibasecurve  
        Dim cpoint As point = Nothing  
        Dim kk As Integer = 0  
        Dim type As Integer  
        Dim subtype As Integer  
        Dim lw As ListingWindow = s.ListingWindow  
        Dim layerObjects() As NXObject  
        Dim layerObjectsDisplayable() As DisplayableObject  
        Dim layerColorID(256) As Integer  
        layerColorID(1) = 6  

        Dim arcList As New List(Of Arc)  

 'Get visible objects in work view
        Dim visibleObjects() As DisplayableObject  
        visibleObjects = workPart.Views.WorkView.AskVisibleObjects  
        Dim tempArc As Arc  

        Dim displayModification1 As DisplayModification  
        displayModification1 = S.DisplayManager.NewDisplayModification()  
 'displayModification1.NewColor = layerColorID(1)
 'displayModification1.NewFont = DisplayableObject.ObjectFont.LongDashed
        displayModification1.NewWidth = DisplayableObject.ObjectWidth.Thick  
        displayModification1.ApplyToAllFaces = True  
        displayModification1.ApplyToOwningParts = False  

        For Each tempObj As DisplayableObject In visibleObjects  
 'test if object is an arc
            If TypeOf tempObj Is Arc Then  
                tempArc = tempObj  
                If tempArc.Radius < 1 Then  
 'do something with small arc
                    arcList.Add(tempArc)  
                End If  
            End If  
        Next  

        If arcList.Count > 0 Then  
            displayModification1.Apply(arcList.ToArray)  
        End If  
        displayModification1.Dispose()  

    End Sub  
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