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!

Brand new to Journaling 2

Status
Not open for further replies.

Johnasti

Automotive
Jan 14, 2013
12
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?
 
Replies continue below

Recommended for you

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:
[COLOR=blue]Option Strict Off[/color]  
[COLOR=blue]Imports[/color] System  
[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.UF  

[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=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow  
        lw.Open()  

        [COLOR=blue]Dim[/color] myObject [COLOR=blue]As[/color] NXObject  
        [COLOR=blue]Dim[/color] myArc [COLOR=blue]As[/color] Arc  
        [COLOR=blue]Dim[/color] myLine [COLOR=blue]As[/color] Line  

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

    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Function[/color] SelectLineArc(ByVal prompt [COLOR=blue]As[/color] String, [COLOR=blue]ByRef[/color] selObj [COLOR=blue]As[/color] NXObject) [COLOR=blue]As[/color] Selection.Response  

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

        [COLOR=blue]With[/color] selectionMask_array(0)  
            .Type [COLOR=blue]=[/color] UFConstants.UF_circle_type  
            .Subtype [COLOR=blue]=[/color] 0  
        End [COLOR=blue]With[/color]  
        [COLOR=blue]With[/color] selectionMask_array(1)  
            .Type [COLOR=blue]=[/color] UFConstants.UF_line_type  
            .Subtype [COLOR=blue]=[/color] UFConstants.UF_line_normal_subtype  
        End [COLOR=blue]With[/color]  

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

    End [COLOR=blue]Function[/color]  


End [COLOR=blue]Module[/color]


www.nxjournaling.com
 
Would it be possible to adapt the code to also work for edges?

Denis Huskic
Data Prep
Kettering University
Class of '17
 
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
 
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
 
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
 
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:
If TypeOf myObject
section started in cowski's I changed it to
Code:
            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:
  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
 
"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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor