Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Using journal to select all

Status
Not open for further replies.

DHuskic

Computer
Dec 18, 2012
114
thread561-272370
I am trying to use the NX 7.5 to do a select all after applying a type filter
can anyone help explain how i would begin to proceed selecting everything on the screen thru code?
 
Replies continue below

Recommended for you

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:
[COLOR=green]'Date:  09/30/2010[/color]
[COLOR=green]'Subject:  Sample NX Open .NET Visual Basic routine : demo select all objects of given types[/color]
[COLOR=green]'[/color]
[COLOR=green]'Note:  GTAC provides programming examples for illustration only, and[/color]
[COLOR=green]'assumes that you are familiar with the programming language being[/color]
[COLOR=green]'demonstrated and the tools used to create and debug procedures.  GTAC[/color]
[COLOR=green]'support professionals can help explain the functionality of a particular[/color]
[COLOR=green]'procedure, but we will not modify these examples to provide added[/color]
[COLOR=green]'functionality or construct procedures to meet your specific needs.[/color]

    [COLOR=blue]Function[/color] getAllObjectsByTypes(ByVal whatTypes() [COLOR=blue]As Integer[/color]) [COLOR=blue]As[/color] DisplayableObject()  
        [COLOR=blue]Dim[/color] objList [COLOR=blue]As[/color] ArrayList [COLOR=blue]= New[/color] ArrayList  
        [COLOR=blue]Dim[/color] thisType [COLOR=blue]As Integer =[/color] 0  
        [COLOR=blue]Dim[/color] thisSubType [COLOR=blue]As Integer =[/color] 0  

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


www.nxjournaling.com
 
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.
 
Here's some code that may get you started:

Code:
[COLOR=green]'eng-tips thread561-335918[/color]
[COLOR=green]'select displayed arcs, do something based on arc radius[/color]

[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  

[COLOR=blue]Module[/color] Module1  

    [COLOR=blue]Sub[/color] Main()  

        [COLOR=blue]Dim[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
        [COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work  

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

                End [COLOR=blue]If[/color]  
            End [COLOR=blue]If[/color]  
        [COLOR=blue]Next[/color]  

    End [COLOR=blue]Sub[/color]  

End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
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:
'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.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
 
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
 
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?
 
Try this:

Code:
[COLOR=green]'eng-tips thread561-335918[/color]
[COLOR=green]'select displayed arcs, do something based on arc radius[/color]

[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.UF  
[COLOR=blue]Imports[/color] NXOpen.Utilities  
[COLOR=blue]Imports[/color] NXOpen.Assemblies  
[COLOR=blue]Imports[/color] System.Windows.Forms  
[COLOR=blue]Imports[/color] System.IO  
[COLOR=blue]Imports[/color] System.Collections  
[highlight #EDD400][COLOR=blue]Imports[/color] System.Collections.Generic[/highlight]  
[COLOR=blue]Imports[/color] System.Environment  
[COLOR=blue]Imports[/color] NXOpenUI  

[COLOR=blue]Module[/color] Module1  

    [COLOR=blue]Sub[/color] Main()  

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

        [highlight #EDD400][COLOR=blue]Dim[/color] arcList [COLOR=blue]As New[/color] List(Of Arc)[/highlight]  

 [COLOR=green]'Get visible objects in work view[/color]
        [COLOR=blue]Dim[/color] visibleObjects() [COLOR=blue]As[/color] DisplayableObject  
        visibleObjects [COLOR=blue]=[/color] workPart.Views.WorkView.AskVisibleObjects  
        [COLOR=blue]Dim[/color] tempArc [COLOR=blue]As[/color] Arc  

        [COLOR=blue]Dim[/color] displayModification1 [COLOR=blue]As[/color] DisplayModification  
        displayModification1 [COLOR=blue]=[/color] S.DisplayManager.NewDisplayModification()  
 [COLOR=green]'displayModification1.NewColor = layerColorID(1)[/color]
 [COLOR=green]'displayModification1.NewFont = DisplayableObject.ObjectFont.LongDashed[/color]
        displayModification1.NewWidth [COLOR=blue]=[/color] DisplayableObject.ObjectWidth.Thick  
        displayModification1.ApplyToAllFaces [COLOR=blue]= True[/color]  
        displayModification1.ApplyToOwningParts [COLOR=blue]= False[/color]  

        [COLOR=blue]For Each[/color] tempObj [COLOR=blue]As[/color] DisplayableObject [COLOR=blue]In[/color] visibleObjects  
 [COLOR=green]'test if object is an arc[/color]
            [COLOR=blue]If TypeOf[/color] tempObj [COLOR=blue]Is[/color] Arc [COLOR=blue]Then[/color]  
                tempArc [COLOR=blue]=[/color] tempObj  
                [COLOR=blue]If[/color] tempArc.Radius < 1 [COLOR=blue]Then[/color]  
 [COLOR=green]'do something with small arc[/color]
                    [highlight #EDD400]arcList.Add(tempArc)[/highlight]  
                End [COLOR=blue]If[/color]  
            End [COLOR=blue]If[/color]  
        [COLOR=blue]Next[/color]  

        [highlight #EDD400][COLOR=blue]If[/color] arcList.Count > 0 [COLOR=blue]Then[/color][/highlight]  
        [highlight #EDD400]    displayModification1.Apply(arcList.ToArray)[/highlight]  
        [highlight #EDD400]End [COLOR=blue]If[/color][/highlight]  
        [highlight #EDD400]displayModification1.Dispose()[/highlight]  

    End [COLOR=blue]Sub[/color]  
End [COLOR=blue]Module[/color]


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

Part and Inventory Search

Sponsor