Showing results for 
Search instead for 
Did you mean: 

How to create a point in the Parent part in an assembly.


Hi, All

I have a situation where I need to create a point (Associative) based on the inputs user selects like in a Point Dialog.

My intention is, In what way I can create an associative point given that user will select inputs as below
        1. For Intersection point.
        2. Selects an Existing point (no need to create a point).
        3. Create point on curve if user selects a curve,

To achieve this is there any API available?

Case 1: Part File
            No issues, I can use SelectionManager.PointConstruct to create an associative point.
Case 2: Assembly File.
            Tried to use the point constructor in assembly, but it creates points in the assembly only and are not associative to the selected objects parent part.
            1. How can I find out the selected object parent part?
            2. How can I get the actual selected object (from assembly or from part file) and create a point inside the parent part selected part making it associative to the selected object.


In a nutshell I'm trying to replicate the point constructor option from assembly point of view.
i.e if user selects two curves then should create an intersection point, and so on.


Kindly guide me on the same and let me know the API commands to achieve the same.

If you can post some sample code, will be highly helpful.


Hope I'm clear on this.

Thanks and Regards,


Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4

Re: How to create a point in the Parent part in an assembly.


One simple aproach is to do a two stage approach.  My example code is to select a component.  I then get the owning part file and set the part as the work part.  You can then create the point which will be in the "parent part" of the object. 


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies

Module selectionstep1
    Dim s As Session = Session.GetSession()
    Dim ui As UI = ui.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim wp As Part = s.Parts.Work
    Dim dp As Part = s.Parts.Display
    Sub Main()
        ' select a component
        Dim prompt As String = "Select a component"
        Dim comp1 As Component = Nothing
        Dim response1 As Selection.Response = Selection.Response.Cancel
        response1 = select_a_component("Select the component", comp1)
        Dim compPart As Part = Nothing
        compPart = FnGetPartFromComponent(comp1)
        ' change the work part
        ' now do the point creation as normal

        ' return to assembly
    End Sub
    Private Function select_a_component(ByVal prompt As String, ByRef obj As NXObject) As Selection.Response
        Dim mask(0) As Selection.MaskTriple
        With mask(0)
            .Type = UFConstants.UF_component_type
            .Subtype = UFConstants.UF_component_subtype
            .SolidBodySubtype = 0
        End With
        Dim cursor As Point3d = Nothing
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim resp As Selection.Response = _
        ui.SelectionManager.SelectTaggedObject(prompt, prompt, _
            Selection.SelectionScope.AnyInAssembly, _
            Selection.SelectionAction.ClearAndEnableSpecific, _
            False, False, mask, obj, cursor)
        If resp = Selection.Response.ObjectSelected Or _
           resp = Selection.Response.ObjectSelectedByName Then
            Return Selection.Response.Ok
            Return Selection.Response.Cancel
        End If
    End Function
    Private Function FnGetPartFromComponent(ByRef instance As NXOpen.Assemblies.Component) As NXOpen.Part
        Dim tag As NXOpen.Tag = -1
        ufs.Part.AskTagOfDispName(instance.DisplayName, tag)
        Dim part As Part = s.Parts.Work
        For Each prt As NXOpen.Part In s.Parts
            If prt.Tag = tag Then
                FnGetPartFromComponent = prt
                Return prt
                Exit For
            End If
        Return Nothing
    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

Frank Swinkels


Re: How to create a point in the Parent part in an assembly.


Hi, Frank


Thanks for your code,


I would like to know, is there any way to access the parts and From Point Dialog itself,

i.e in the following sequence, 


1. Opens Assembly file.

2. Start the Point Constructor dialog.

3. User will select Intersection option from dialog,

4. User Selects

        a. Curve 1,

        b. Line 1

5. Now point will be created (In assembly itself... but not associative...)


So, this is where im looking for solution.


I dont want the point to be created in assemby, rather than that i want it to be created in the part itself. 




As it gets created in assembly itself, i want the point to be associative to the selected elements.






Windows 7 x64
NX 8.5, NX 9.0. And also NX 7.5
Visual Studio 2010 SP1, 2012 Update 4

Re: How to create a point in the Parent part in an assembly.

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

You can query the selected object to find what part file owns it. This part could then be made the "work" part, this can be done "behind the scenes" in your code. The newly created point would then be owned by the same part that owns the selected object. This is basically the same strategy that Frank used in his code, only the component selection step would be "hidden" from the user.


If you want to create an associative point in the assembly based on geometry selected from components, you will need to wave link the desired component geometry into the assembly part, then use the linked geometry to create the point in the assembly part.

Re: How to create a point in the Parent part in an assembly.


Let me first say that I meant to show you a SIMPLE approach.  Consider the first of your desired methods.  Since you want to use the point construction dialog for creating the point its associated curves are also in the assembly part.  Yes you can edit the point parameters but only to the assembly curve(s).  Now to do this the process would be as follows.


1. Use a selection menu to select the curves (assuming you want an intersection point.)

2. Change the work part

3. Create the point using

Dim point2 As Point

point2 = workPart.Points.CreatePoint(curve1,curve2, helpPoint1, helpPoint2, SmartObject.UpdateOption.WithinModeling) (NX9)


For this you need additionally at least one help point.


So that the point construct dialog is not used at all.  This makes it quite complex to have all the other point options available.


Frank Swinkels