×
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

Brand new to Journaling
2

Brand new to Journaling

Brand new to Journaling

(OP)
Hello everyone,

I am just getting started with Journaling and am wondering if there is a file/list someplace of generic NX callouts someplace. I would like to start by creating a journal that will allow the user to select various objects (lines/arcs) and then I want to print out/use information related to those objects. Start point, end point, arc centers etc.

I started with this:
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim mySelectedObjects as NXObject()


lw.Open

If SelectObjects("Hey, select multiple somethings", _
mySelectedObjects) = Selection.Response.Ok Then
lw.WriteLine("You selected " & mySelectedObjects.Length & " object(s)")
lw.WriteLine("")
For Each mySelObj As NXObject in mySelectedObjects
lw.WriteLine("Object Tag: " & mySelObj.Tag)
lw.WriteLine("Object Type: " & mySelObj.GetType.ToString)
lw.WriteLine("")

Next
theSession.Information.DisplayObjectsDetails(mySelectedObjects)

End if

' The close method closes the text stream to the window,
' it does not close the window itself
' (use the .CloseWindow() method for that).
' Also, if you are using the listing window to write
' to a file, the close method will clean up and close the file.
lw.Close

End Sub

Function SelectObjects(prompt As String, _
ByRef selObj as NXObject()) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.All, _
Selection.SelectionType.Faces, _
Selection.SelectionType.Edges, _
Selection.SelectionType.Features}

Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
prompt, "Selection", _
Selection.SelectionScope.AnyInAssembly, _
False, typeArray, selobj)

If resp = Selection.Response.ObjectSelected Or _
resp = Selection.Response.ObjectSelectedByName Or _
resp = Selection.Response.OK Then
Return Selection.Response.Ok
Else
return Selection.Response.Cancel
End If

End Function

End Module



The problem here is that theSession.Information.DisplayObjectsDetails(mySelectedObjects) spits out everything for every object all at the same time and I want to be able to store/manipulate individual parts of that information. Am I thinking about this the wrong way or do I just need to learn what all of the callouts are?

RE: Brand new to Journaling

The following code is a modified version of what you posted, it limits selection to lines or arcs and after each selection it prints out data on the selected object to the information window. Instead of printing this information you could assign it to a variable and use it as you need within the program.

CODE

Option Strict Off  
Imports System  
Imports NXOpen  
Imports NXOpen.UF  

Module Module1  

    Sub Main()  

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

        Dim myObject As NXObject  
        Dim myArc As Arc  
        Dim myLine As Line  

        Do Until SelectLineArc("Select a line or arc", myObject) = Selection.Response.Cancel  
            If TypeOf myObject Is Arc Then  
                myArc = myObject  
                lw.WriteLine("selected object is an arc")  
                lw.WriteLine("center point: " & myArc.CenterPoint.ToString)  
                lw.WriteLine("radius: " & myArc.Radius.ToString)  
                lw.WriteLine("diameter: " & (myArc.Radius * 2).ToString)  
            Else  
                myLine = myObject  
                lw.WriteLine("selected object is a line")  
                lw.WriteLine("start point: " & myLine.StartPoint.ToString)  
                lw.WriteLine("end point: " & myLine.EndPoint.ToString)  
                lw.WriteLine("length: " & myLine.GetLength.ToString)  
            End If  
            lw.WriteLine("")  
        Loop  

    End Sub  

    Function SelectLineArc(ByVal prompt As String, ByRef selObj As NXObject) As Selection.Response  

        Dim theUI As UI = UI.GetUI  
        Dim title As String = "Select a line or arc"  
        Dim includeFeatures As Boolean = False  
        Dim keepHighlighted As Boolean = False  
        Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific  
        Dim cursor As Point3d  
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart  
        Dim selectionMask_array(1) As Selection.MaskTriple  

        With selectionMask_array(0)  
            .Type = UFConstants.UF_circle_type  
            .Subtype = 0  
        End With  
        With selectionMask_array(1)  
            .Type = UFConstants.UF_line_type  
            .Subtype = UFConstants.UF_line_normal_subtype  
        End With  

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, _  
         title, scope, selAction, _  
         includeFeatures, keepHighlighted, selectionMask_array, _  
         selobj, cursor)  
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then  
            Return Selection.Response.Ok  
        Else  
            Return Selection.Response.Cancel  
        End If  

    End Function  


End Module 

www.nxjournaling.com

RE: Brand new to Journaling

(OP)
Thank you very much for the reply!

RE: Brand new to Journaling

Would it be possible to adapt the code to also work for edges?

Denis Huskic
Data Prep
Kettering University
Class of '17

RE: Brand new to Journaling

dhusk09,
What exactly would you like to filter?
We can add edges into the mix then it would let you select any line, arc, or edge; is this what you want?

www.nxjournaling.com

RE: Brand new to Journaling

Yes. We have been looking for a way to select edges (on cylinders and rad's on mold features) and return a diameter value.
If it worked the same as the arcs in the above example, and returned only a diameter, then it would be perfect!

Denis Huskic
Data Prep
Kettering University
Class of '17

RE: Brand new to Journaling

Here is a journal that allows you to select only circular edges. I then test the edge that it is the correct type. This is ofcourse not necessary here. However you may want the code to select a body from which it is simple to get all faces and then get all the edges. In this case it would be necessary to test the edges. I have simply output as a message the arc diameter.

CODE -->

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features

Module ArcEdges
    Dim s As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = s.Parts.Work

    Sub Main()
        Dim response0 As Selection.Response = Selection.Response.Cancel
        Dim edge1 As Edge = Nothing
        Dim arc1 As Arc = Nothing
        Dim edgetype1 As Integer = Nothing
        Dim arc_evaluator As System.IntPtr
        Dim dia1 As Double = Nothing
        Dim arc_data As NXOpen.UF.UFEval.Arc = Nothing
start1:
        response0 = SelectAEdge(edge1)
        If response0 = Selection.Response.Cancel Then GoTo end1
        ufs.Modl.AskEdgeType(edge1.Tag, edgetype1)
        If edgetype1 = 3002 Then
            ufs.Eval.Initialize(edge1.Tag, arc_evaluator)
            ufs.Eval.AskArc(arc_evaluator, arc_data)
            dia1 = 2.0 * arc_data.radius
            MsgBox(dia1.ToString)
        End If
        GoTo start1
end1:
    End Sub

    Public Function SelectAEdge(ByRef selectedObject As Edge) As Selection.Response
        Dim ui As UI = ui.GetUI
        Dim message As String = "Select a Edge"
        Dim title As String = "Selection"
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim keepHighlighted As Boolean = True
        Dim includeFeatures As Boolean = True
        Dim response As Selection.Response
        Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim selectionMask_array(1) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_solid_type
            .Subtype = UFConstants.UF_solid_body_subtype
            .SolidBodySubtype = NXOpen.UF.UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
        End With
        Dim cursor As Point3d
        response = ui.SelectionManager.SelectObject(message, title, scope, _
                                           selectionAction, includeFeatures, _
                                           False, selectionMask_array, _
                                           selectedObject, cursor)
        If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
            Return Selection.Response.Cancel
        Else
            Return Selection.Response.Ok
        End If
    End Function
    
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function
End Module 

Regards

Frank Swinkels

RE: Brand new to Journaling

Thank you Frank and Cowski for those two journals!
I was able to add parts of Frank's journal to Cowski's to get it to return what I was looking for.

Where the

CODE --> vb

If TypeOf myObject 
section started in cowski's I changed it to

CODE --> vb

If TypeOf myObject Is Line Then   
                myLine = myObject  
                lw.WriteLine("selected object is a line")  
                lw.WriteLine("start point: " & myLine.StartPoint.ToString)  
                lw.WriteLine("end point: " & myLine.EndPoint.ToString)  
                lw.WriteLine("length: " & FormatNumber(myLine.GetLength.ToString, 4)) 
            ElseIf TypeOf myObject Is Arc Then 
                myArc = myObject  
                lw.WriteLine("selected object is an arc")  
                lw.WriteLine("diameter: " & FormatNumber((myArc.Radius * 2).ToString,4)) 
            Else
                edge1 = myObject
            ufs.Eval.Initialize(edge1.Tag, arc_evaluator)
            ufs.Eval.AskArc(arc_evaluator, arc_data)
            dia1 = 2.0 * arc_data.radius
                lw.WriteLine("selected object is an edge")
                lw.WriteLine("diameter: " & FormatNumber(dia1.ToString,4))
            End If  
            lw.WriteLine("") 

I also added another bit to the MaskTriple array

CODE --> vb

With selectionMask_array(2)
            .Type = UFConstants.UF_solid_type
            .Subtype = UFConstants.UF_solid_body_subtype
            .SolidBodySubtype = NXOpen.UF.UFConstants.UF_UI_SEL_FEATURE_CIRCULAR_EDGE
        End With 

Thanks for all the help!

Denis Huskic
Data Prep
Kettering University
Class of '17

RE: Brand new to Journaling

"I am just getting started with Journaling and am wondering if there is a file/list someplace of generic NX callouts someplace."

I was wondering the same thing.

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