×
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: Getting component and edges from point

Journal: Getting component and edges from point

Journal: Getting component and edges from point

(OP)
I am trying to figure out how to get the component and edges from a point. For this journal it will have you select a corner point on a body, and from there; I plan to use the component the body is under and the respective edges from that corner to move it. I need the edges to create a csys(I have code for), I don't have code for selecting the edges. Thanks in advanced!

Denis Huskic
Data Prep NX7.5
Kettering University
Class of '17

RE: Journal: Getting component and edges from point

The following code doesn't do everything you want, but it should be a good start.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
 
Module Module1
 
    Dim theSession As Session = Session.GetSession()
    Dim theUI As UI = UI.GetUI()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = theSession.ListingWindow
    Dim pickedPoint As Point
    Dim myModelingTolerance As Double
 
    Sub Main()
 
        theUfSession.Modl.AskDistanceTolerance(myModelingTolerance)
 
        Dim workPart As Part = theSession.Parts.Work
        lw.Open()
 
        Dim myPointTag As Tag
 
        If Not select_point("Select Point", myPointTag) = UFConstants.UF_UI_OK Then
            Exit Sub
        End If
 
        lw.WriteLine("pickedPoint: " & pickedPoint.Coordinates.ToString)
 
        AskParents(myPointTag)
 
    End Sub
 
    Sub AskParents(ByVal objTag As Tag)
 
        Dim n_parents As Integer
        Dim parentTags As Tag()
        Dim myPoint As Point
        Dim myEdge As Edge
        Dim myXform As Xform
        Dim myTaggedObject As TaggedObject
        myTaggedObject = Utilities.NXObjectManager.Get(objTag)
 
        If myTaggedObject.GetType.ToString.ToLower.Contains("point") Then
            myPoint = myTaggedObject
            lw.WriteLine("the tagged object: " & myTaggedObject.GetType.ToString)
            lw.WriteLine("")
 
            Try
                theUfSession.So.AskParents(objTag, UFConstants.UF_SO_ASK_ALL_PARENTS, n_parents, parentTags)
                lw.WriteLine("num parents: " & n_parents.ToString)
                For Each parentTag As Tag In parentTags
                    Dim parent_object As TaggedObject = Utilities.NXObjectManager.Get(parentTag)
 
                    AskParents(parent_object.Tag)
 
                    If parent_object.ToString.ToLower.Contains("edge") Then
                        myEdge = parent_object
                        lw.WriteLine("")
                        lw.WriteLine("edge type: " & myEdge.SolidEdgeType.ToString)
                        lw.WriteLine("edge length: " & myEdge.GetLength.ToString)
                        lw.WriteLine("edge owning part: " & myEdge.OwningPart.FullPath.ToString)
 
                        Dim partTag As Tag = myEdge.OwningPart.Tag
                        Dim occTags() As Tag
                        theUfSession.Assem.AskOccsOfPart(Tag.Null, partTag, occTags)
                        lw.WriteLine("number of occurences: " & occTags.Length.ToString)
                        For Each temp As Tag In occTags
                            Dim myComp As Assemblies.Component
                            myComp = Utilities.NXObjectManager.Get(temp)
                            Dim myCompPos As Point3d
                            Dim myCompOrientation As Matrix3x3
                            myComp.GetPosition(myCompPos, myCompOrientation)
 
                            lw.WriteLine("")
                            lw.WriteLine("component name: " & myComp.Name)
                            lw.WriteLine("component display name: " & myComp.DisplayName)
                            lw.WriteLine("distance from picked point: " & MeasureDistance(pickedPoint, myComp).ToString)
 
                            If MeasureDistance(pickedPoint, myComp) < myModelingTolerance Then
                                lw.WriteLine("** This is the component that was picked **")
                            End If
 
                            lw.WriteLine("")
                        Next
 
                        lw.WriteLine("")
                    End If
                Next
 
            Catch ex As Exception
                ' NXOpen.NXException: Current object is not smart
                lw.WriteLine(" Error: " + ex.Message)
                lw.WriteLine("    " & myTaggedObject.GetType.ToString)
            End Try
 
 
        End If
 
 
    End Sub
 
    Function select_point(ByVal cue As String, ByRef pt_tag As Tag) As Integer
 
        Dim base_pt As Double() = New Double(2) {}
        'Dim point_tag As NXOpen.Tag = NXOpen.Tag.Null
        Dim response As Integer = 0
        Dim base_method As UFUi.PointBaseMethod = UFUi.PointBaseMethod.PointEndPt
 
        theUfSession.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
        theUfSession.Ui.PointConstruct(cue, base_method, pt_tag, base_pt, response)
        theUfSession.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
 
        Dim pointLocation As Point3d
        pointLocation.X = base_pt(0)
        pointLocation.Y = base_pt(1)
        pointLocation.Z = base_pt(2)
        pickedPoint = theSession.Parts.Display.Points.CreatePoint(pointLocation)
        'pickedPoint.SetVisibility(SmartObject.VisibilityOption.Visible)
 
        Return response
 
    End Function
 
    Function SelectPointObject(ByVal prompt As String, ByRef selPoint As Point) As Selection.Response
 
        Dim selObj As TaggedObject
        Dim theUI As UI = UI.GetUI
        Dim title As String = "Select a Point"
        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.AnyInAssembly
        Dim selectionMask_array(0) As Selection.MaskTriple
 
        With selectionMask_array(0)
            .Type = UFConstants.UF_point_type
            .Subtype = UFConstants.UF_all_subtype
        End With
 
        Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
         title, scope, selAction, _
         includeFeatures, keepHighlighted, selectionMask_array, _
         selobj, cursor)
        If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
            selPoint = selObj
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If
 
    End Function
 
    Function MeasureDistance(ByVal obj1 As DisplayableObject, ByVal obj2 As DisplayableObject) As Double
 
        Dim result As Double
 
        Try
            Dim nullNXObject As NXObject = Nothing
 
            Dim measureDistanceBuilder1 As MeasureDistanceBuilder
            measureDistanceBuilder1 = theSession.Parts.Display.MeasureManager.CreateMeasureDistanceBuilder(nullNXObject)
 
            measureDistanceBuilder1.InfoWindow = False
 
            measureDistanceBuilder1.Mtype = MeasureDistanceBuilder.MeasureType.Minimum
 
            Dim nullUnit As Unit = Nothing
 
            Dim measureDistance1 As MeasureDistance
            measureDistance1 = theSession.Parts.Display.MeasureManager.NewDistance(nullUnit, MeasureManager.MeasureType.Minimum, obj1, obj2)
 
            result = measureDistance1.Value
 
            'measureDistance1.Information()
 
            measureDistance1.Dispose()
 
        Catch ex As NXException
            MsgBox(ex.Message)
            Return Nothing
 
        End Try
 
 
        Return result
 
    End Function
 
 
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
 
        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
 
    End Function
 
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