Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Get points from selected sketch

Hello,

I am new to NX programing, a have some experience with CATIA Macros. I work with vb.

I want to create Coordinate Systems on points from selected sketch Sketch. I have problem with using selection, how to get points when i select sketch. 

 

Dim point1 As NXOpen.Point = CType(workPart.Points.FindObject("ENTITY 2 8 1"), NXOpen.Point)

 

(in catia it was just change one number like

 For i = 1 to sketch.points.count

Dim point1 As NXOpen.Point = CType(workPart.Points.FindObject("ENTITY 2 i 1"), NXOpen.Point)

 

I know i must replace this with user sel, but dont know how to do it.

 

Thx a lot.

 

Option Strict Off
Imports System
Imports NXOpen


Function SelectAnObject(prompt As String, ByRef selObj As NXObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim typeArray() As Selection.SelectionType = {Selection.SelectionType.All, Selection.SelectionType.Faces, Selection.SelectionType.Edges, Selection.SelectionType.Features}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(prompt, "Selection", Selection.SelectionScope.AnyInAssembly, False, typeArray, selobj, cursor)
If resp = Selection.Response.ObjectSelected Or resp = Selection.Response.ObjectSelectedByName Then
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function


Module NXJournal
Sub Main (ByVal args() As String)


Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display

Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing

If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If

Dim datumCsysBuilder1 As NXOpen.Features.DatumCsysBuilder
datumCsysBuilder1 = workPart.Features.CreateDatumCsysBuilder(nullNXOpen_Features_Feature)


Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

theSession.SetUndoMarkName(markId1, "Datum CSYS Dialog")


Dim nullNXOpen_Xform As NXOpen.Xform = Nothing

Dim point1 As NXOpen.Point = CType(workPart.Points.FindObject("ENTITY 2 8 1"), NXOpen.Point)

Dim point2 As NXOpen.Point
point2 = workPart.Points.CreatePoint(point1, nullNXOpen_Xform, NXOpen.SmartObject.UpdateOption.WithinModeling)

Dim nXObject1 As NXOpen.NXObject
Dim xform1 As NXOpen.Xform
xform1 = workPart.Xforms.CreateExtractXform(point1, NXOpen.SmartObject.UpdateOption.WithinModeling, False, nXObject1)


Dim point3 As NXOpen.Point = CType(nXObject1, NXOpen.Point)

Dim point4 As NXOpen.Point
point4 = workPart.Points.CreatePoint(point3, nullNXOpen_Xform, NXOpen.SmartObject.UpdateOption.WithinModeling)
point4.RemoveViewDependency()
point4.RemoveViewDependency()


Dim datumAxis1 As NXOpen.DatumAxis = CType(workPart.Datums.FindObject("DATUM_CSYS(3) X axis"), NXOpen.DatumAxis)

Dim direction1 As NXOpen.Direction
direction1 = workPart.Directions.CreateDirection(datumAxis1, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)


Dim datumAxis2 As NXOpen.DatumAxis = CType(workPart.Datums.FindObject("DATUM_CSYS(3) Y axis"), NXOpen.DatumAxis)

Dim direction2 As NXOpen.Direction
direction2 = workPart.Directions.CreateDirection(datumAxis2, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)


Dim xform2 As NXOpen.Xform
xform2 = workPart.Xforms.CreateXform(point4, direction1, direction2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0)

Dim markId2 As NXOpen.Session.UndoMarkId
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Datum CSYS")

Dim markId3 As NXOpen.Session.UndoMarkId
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Datum CSYS")

Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem
cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform2, NXOpen.SmartObject.UpdateOption.WithinModeling)


theSession.SetUndoMarkName(markId1, "Datum CSYS")

datumCsysBuilder1.Csys = cartesianCoordinateSystem1
datumCsysBuilder1.DisplayScaleFactor = 1.25

Dim nXObject2 As NXOpen.NXObject
nXObject2 = datumCsysBuilder1.Commit()

datumCsysBuilder1.Destroy()

End Sub
End Module

 

This is code take with jurnal whic i changed.  

6 REPLIES

Re: Get points from selected sketch

NXOpen.Sketch.GetAllGeometry() will return an array of NXOpen.NXObjects containing all of the curves and points in the sketch. Loop through the objects in this array and retain those that are points.

Re: Get points from selected sketch

Here's a quick journal showing the usage of NXOpen.Sketch.GetAllGeometry() as mentioned by @JimB. It processes the first sketch it finds in the work part and writes point information to the information window.

 

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
 
Module Module1
 
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
 
    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow
 
    Sub Main()
 
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ")
 
        lw.Open()
 
        Dim partSketches() As Sketch = theSession.Parts.Work.Sketches.ToArray
 
        'if there are no sketches, exit journal
        If partSketches.Length = 0 Then
            Return
        End If
 
        'process the first sketch
        Dim sketchObjects() As NXObject = partSketches(0).GetAllGeometry
        If sketchObjects.Length = 0 Then
            lw.WriteLine(partSketches(0).Name & " contains no geometry")
        End If
 
        Dim sketchPoints As New List(Of Point)
        For Each temp As NXObject In sketchObjects
            If TypeOf (temp) Is Point Then
                sketchPoints.Add(temp)
            End If
        Next
 
        lw.WriteLine(partSketches(0).Name & " contains " & sketchPoints.Count.ToString & " point objects")
        For Each temp As Point In sketchPoints
            lw.WriteLine(temp.Coordinates.ToString)
        Next
 
        lw.Close()
 
    End Sub
 
 
    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

Re: Get points from selected sketch

Thx both of u,i made first steep, i get coorinates of the points from the selected sketch, i ll continue.  Whic is the best way for multiselection.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports System.Windows.Forms
Imports NXOpen.UF
Imports System.Collections.Generic
Module NXJournal
    Function SelectSketch() As Sketch
        Dim ui As UI = ui.GetUI
        Dim message As String = "Select Sketch"
        Dim title As String = "Selection"
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim keepHighlighted As Boolean = False
        Dim includeFeatures As Boolean = True
        Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim selectionMask_array(0) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_sketch_type
            .Subtype = 0
        End With
        Dim selectedObject As NXObject = Nothing
        Dim cursor As Point3d
        ui.SelectionManager.SelectObject(message, title, scope, selectionAction, includeFeatures, keepHighlighted, selectionMask_array, selectedObject, cursor)
        Dim Sketch As Sketch = CType(selectedObject, Sketch)
        If Sketch Is Nothing Then
            Return Nothing
        End If
        Return Sketch

    End Function
    Sub Main(ByVal args() As String)

        Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
        Dim workPart As NXOpen.Part = theSession.Parts.Work
        Dim displayPart As NXOpen.Part = theSession.Parts.Display
        Dim ufs As UFSession = UFSession.GetUFSession()
        ' ----------------------------------------------
        '   Menu: Insert->Datum/Point->Datum CSYS...
        ' ----------------------------------------------

        Dim markId1 As NXOpen.Session.UndoMarkId
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

        Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing

        If Not workPart.Preferences.Modeling.GetHistoryMode Then
            Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
        End If

        Dim datumCsysBuilder1 As NXOpen.Features.DatumCsysBuilder
        datumCsysBuilder1 = workPart.Features.CreateDatumCsysBuilder(nullNXOpen_Features_Feature)


        Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
        Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

        theSession.SetUndoMarkName(markId1, "Datum CSYS Dialog")


        Dim nullNXOpen_Xform As NXOpen.Xform = Nothing
        
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim Sketch1 As Sketch = SelectSketch()
        Dim sketchObjects() As NXObject = Sketch1.GetAllGeometry

        Dim sketchPoints As New List(Of Point)
        For Each temp As NXObject In sketchObjects
            If TypeOf (temp) Is Point Then
                sketchPoints.Add(temp)
            End If
        Next

        lw.WriteLine(sketchObjects(0).Name & " contains " & sketchPoints.Count.ToString & " point objects")
        For Each temp As Point In sketchPoints
            lw.WriteLine(temp.Coordinates.ToString)
        Next
        lw.Close()



        Dim point1 As NXOpen.Point = CType(workPart.Points.FindObject("ENTITY 2 8 1"), NXOpen.Point)

        Dim point2 As NXOpen.Point
        point2 = workPart.Points.CreatePoint(point1, nullNXOpen_Xform, NXOpen.SmartObject.UpdateOption.WithinModeling)

        Dim nXObject1 As NXOpen.NXObject
        Dim xform1 As NXOpen.Xform
        xform1 = workPart.Xforms.CreateExtractXform(point1, NXOpen.SmartObject.UpdateOption.WithinModeling, False, nXObject1)

        Dim point3 As NXOpen.Point = CType(nXObject1, NXOpen.Point)

        Dim point4 As NXOpen.Point
        point4 = workPart.Points.CreatePoint(point3, nullNXOpen_Xform, NXOpen.SmartObject.UpdateOption.WithinModeling)
        point4.RemoveViewDependency()
        point4.RemoveViewDependency()

        Dim datumAxis1 As NXOpen.DatumAxis = CType(workPart.Datums.FindObject("DATUM_CSYS(4) X axis"), NXOpen.DatumAxis)
        ' ----------------------------------------------
               Dim direction1 As NXOpen.Direction
        direction1 = workPart.Directions.CreateDirection(datumAxis1, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)
     
        Dim datumAxis2 As NXOpen.DatumAxis = CType(workPart.Datums.FindObject("DATUM_CSYS(4) Y axis"), NXOpen.DatumAxis)
        
        Dim direction2 As NXOpen.Direction
        direction2 = workPart.Directions.CreateDirection(datumAxis2, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)


        Dim xform2 As NXOpen.Xform
        xform2 = workPart.Xforms.CreateXform(point4, direction1, direction2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0)

        Dim markId2 As NXOpen.Session.UndoMarkId
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Datum CSYS")

        Dim markId3 As NXOpen.Session.UndoMarkId
        markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Datum CSYS")

        Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem
        cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform2, NXOpen.SmartObject.UpdateOption.WithinModeling)


        theSession.SetUndoMarkName(markId1, "Datum CSYS")

        datumCsysBuilder1.Csys = cartesianCoordinateSystem1
        datumCsysBuilder1.DisplayScaleFactor = 1.25

        Dim nXObject2 As NXOpen.NXObject
        nXObject2 = datumCsysBuilder1.Commit()

        datumCsysBuilder1.Destroy()

    End Sub
End Module

Re: Get points from selected sketch

It works now, thanx again, any suggestion are welcome.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports System.Windows.Forms
Imports NXOpen.UF
Imports System.Collections.Generic
Module NXJournal
    'Function For SKetch selection
    Function SelectSketch() As Sketch
        Dim ui As UI = ui.GetUI
        Dim message As String = "Sketch selection for creating AS ..."
        Dim title As String = "Sketch Selection"
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim keepHighlighted As Boolean = False
        Dim includeFeatures As Boolean = True
        Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim selectionMask_array(0) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_sketch_type
            .Subtype = 0
        End With
        Dim selectedObject As NXObject = Nothing
        Dim cursor As Point3d
        ui.SelectionManager.SelectObject(message, title, scope, selectionAction, includeFeatures, keepHighlighted, selectionMask_array, selectedObject, cursor)
        Dim Sketch As Sketch = CType(selectedObject, Sketch)
        If Sketch Is Nothing Then
            Return Nothing
        End If
        Return Sketch
    End Function
    'Function For Axis selection
    Function SelectAxis() As DatumAxis
        Dim ui As UI = ui.GetUI
        Dim message As String = "Axis selection (x and y)"
        Dim title As String = "Axis selection"
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim keepHighlighted As Boolean = False
        Dim includeFeatures As Boolean = True
        Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim selectionMask_array(0) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_datum_axis_type
            .Subtype = 0
        End With
        Dim selectedObject As NXObject = Nothing
        Dim cursor As Point3d
        ui.SelectionManager.SelectObject(message, title, scope, selectionAction, includeFeatures, keepHighlighted, selectionMask_array, selectedObject, cursor)
        Dim Axis As DatumAxis = CType(selectedObject, DatumAxis)
        If Axis Is Nothing Then
            Return Nothing
        End If
        Return Axis
    End Function

    Sub Main(ByVal args() As String)
        Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
        Dim workPart As NXOpen.Part = theSession.Parts.Work
        Dim displayPart As NXOpen.Part = theSession.Parts.Display
        Dim ufs As UFSession = UFSession.GetUFSession()

        Dim markId1 As NXOpen.Session.UndoMarkId
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
        Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing

        If Not workPart.Preferences.Modeling.GetHistoryMode Then
            Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
        End If

        Dim datumCsysBuilder1 As NXOpen.Features.DatumCsysBuilder
        datumCsysBuilder1 = workPart.Features.CreateDatumCsysBuilder(nullNXOpen_Features_Feature)
        Dim unit1 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), NXOpen.Unit)
        Dim unit2 As NXOpen.Unit = CType(workPart.UnitCollection.FindObject("Degrees"), NXOpen.Unit)

        theSession.SetUndoMarkName(markId1, "Datum CSYS Dialog")


        Dim nullNXOpen_Xform As NXOpen.Xform = Nothing

        'Calling the sketch Function, sketch selection, addinf points in the list
        Dim Sketch1 As Sketch = SelectSketch()
        Dim sketchObjects() As NXObject = Sketch1.GetAllGeometry

        Dim sketchPoints As New List(Of Point)
        For Each temp As NXObject In sketchObjects
            If TypeOf (temp) Is Point Then
                sketchPoints.Add(temp)

            End If
        Next
        'Axis Selection
        Dim Axis1 As DatumAxis = SelectAxis()
        Dim Axis2 As DatumAxis = SelectAxis()

        'For loop for creating of AS
        Dim i As Integer
        For i = 0 To sketchpoints.count.tostring - 1
            Dim point1 As NXOpen.Point = CType(sketchpoints(i), NXOpen.Point)

            Dim point2 As NXOpen.Point
            point2 = workPart.Points.CreatePoint(point1, nullNXOpen_Xform, NXOpen.SmartObject.UpdateOption.WithinModeling)

            Dim nXObject1 As NXOpen.NXObject
            Dim xform1 As NXOpen.Xform
            xform1 = workPart.Xforms.CreateExtractXform(point1, NXOpen.SmartObject.UpdateOption.WithinModeling, False, nXObject1)


            Dim point3 As NXOpen.Point = CType(nXObject1, NXOpen.Point)

            Dim point4 As NXOpen.Point
            point4 = workPart.Points.CreatePoint(point3, nullNXOpen_Xform, NXOpen.SmartObject.UpdateOption.WithinModeling)
            point4.RemoveViewDependency()
            point4.RemoveViewDependency()




            Dim datumAxis1 As NXOpen.DatumAxis = CType(Axis1, NXOpen.DatumAxis)
            Dim direction1 As NXOpen.Direction
            direction1 = workPart.Directions.CreateDirection(datumAxis1, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)

           
            Dim datumAxis2 As NXOpen.DatumAxis = CType(Axis2, NXOpen.DatumAxis)
            Dim direction2 As NXOpen.Direction
            direction2 = workPart.Directions.CreateDirection(datumAxis2, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)


            Dim xform2 As NXOpen.Xform
            xform2 = workPart.Xforms.CreateXform(point4, direction1, direction2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0)

            Dim markId2 As NXOpen.Session.UndoMarkId
            markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Datum CSYS")

            Dim markId3 As NXOpen.Session.UndoMarkId
            markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Datum CSYS")

            Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem
            cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform2, NXOpen.SmartObject.UpdateOption.WithinModeling)


            theSession.SetUndoMarkName(markId1, "Datum CSYS")

            datumCsysBuilder1.Csys = cartesianCoordinateSystem1
            datumCsysBuilder1.DisplayScaleFactor = 1.25

            Dim nXObject2 As NXOpen.NXObject
            nXObject2 = datumCsysBuilder1.Commit()

        Next
        datumCsysBuilder1.Destroy()
        Messagebox.show("Done...")
    End Sub
End Module
Solution
Solution
Accepted by topic author Harun_
‎08-30-2016 02:13 PM

Re: Get points from selected sketch

[ Edited ]

The For loop was simplified. Also, a custom message was added to the SelectAxis function.

 

You might want to add a check to see if there is a sketch available in the part before prompting the user to select one. Also, if the selected sketch does not contain any points, a message to the user would help them understand why the journal didn't do anything.

 

Option Strict Off
Imports System
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF

Module NXJournal

    'Function For SKetch selection
    Function SelectSketch() As Sketch
        Dim ui As UI = ui.GetUI
        Dim message As String = "Sketch selection for creating AS ..."
        Dim title As String = "Sketch Selection"
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim keepHighlighted As Boolean = False
        Dim includeFeatures As Boolean = True
        Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim selectionMask_array(0) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_sketch_type
            .Subtype = 0
        End With
        Dim selectedObject As NXObject = Nothing
        Dim cursor As Point3d
        ui.SelectionManager.SelectObject(message, title, scope, selectionAction, includeFeatures, keepHighlighted, selectionMask_array, selectedObject, cursor)
        Dim Sketch As Sketch = CType(selectedObject, Sketch)
        If Sketch Is Nothing Then
            Return Nothing
        End If
        Return Sketch
    End Function
	
    'Function For Axis selection
    Function SelectAxis(byval selectionMessage as string) As DatumAxis
        Dim ui As UI = ui.GetUI
        'Dim message As String = "Axis selection (x and y)"
        Dim title As String = "Axis selection"
        Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
        Dim keepHighlighted As Boolean = False
        Dim includeFeatures As Boolean = True
        Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
        Dim selectionMask_array(0) As Selection.MaskTriple
        With selectionMask_array(0)
            .Type = UFConstants.UF_datum_axis_type
            .Subtype = 0
        End With
        Dim selectedObject As NXObject = Nothing
        Dim cursor As Point3d
        ui.SelectionManager.SelectObject(selectionMessage, title, scope, selectionAction, includeFeatures, keepHighlighted, selectionMask_array, selectedObject, cursor)
        Dim Axis As DatumAxis = CType(selectedObject, DatumAxis)
        If Axis Is Nothing Then
            Return Nothing
        End If
        Return Axis
    End Function

    Sub Main(ByVal args() As String)
        Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
        Dim workPart As NXOpen.Part = theSession.Parts.Work

        Dim markId1 As NXOpen.Session.UndoMarkId
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Datum CSYS on sketch points")
        Dim nullNXOpen_Features_Feature As NXOpen.Features.Feature = Nothing

        Dim datumCsysBuilder1 As NXOpen.Features.DatumCsysBuilder
        datumCsysBuilder1 = workPart.Features.CreateDatumCsysBuilder(nullNXOpen_Features_Feature)


        'Calling the sketch Function, sketch selection, addinf points in the list
        Dim Sketch1 As Sketch = SelectSketch()
        Dim sketchObjects() As NXObject = Sketch1.GetAllGeometry

        Dim sketchPoints As New List(Of Point)
        For Each temp As NXObject In sketchObjects
            If TypeOf (temp) Is Point Then
                sketchPoints.Add(temp)

            End If
        Next
        'Axis Selection
        Dim Axis1 As DatumAxis = SelectAxis("Select X direction")
        Dim Axis2 As DatumAxis = SelectAxis("Select Y direction")

        'For loop for creating of AS
        For each tempPoint as Point in sketchPoints

            Dim datumAxis1 As NXOpen.DatumAxis = CType(Axis1, NXOpen.DatumAxis)
            Dim direction1 As NXOpen.Direction
            direction1 = workPart.Directions.CreateDirection(datumAxis1, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)

            Dim datumAxis2 As NXOpen.DatumAxis = CType(Axis2, NXOpen.DatumAxis)
            Dim direction2 As NXOpen.Direction
            direction2 = workPart.Directions.CreateDirection(datumAxis2, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling)

            Dim xform2 As NXOpen.Xform
            xform2 = workPart.Xforms.CreateXform(tempPoint, direction1, direction2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0)

            Dim cartesianCoordinateSystem1 As NXOpen.CartesianCoordinateSystem
            cartesianCoordinateSystem1 = workPart.CoordinateSystems.CreateCoordinateSystem(xform2, NXOpen.SmartObject.UpdateOption.WithinModeling)

            datumCsysBuilder1.Csys = cartesianCoordinateSystem1
            datumCsysBuilder1.DisplayScaleFactor = 1.25

            Dim nXObject2 As NXOpen.NXObject
            nXObject2 = datumCsysBuilder1.Commit()

        Next
        datumCsysBuilder1.Destroy()
        Messagebox.show("Done...")
    End Sub
End Module

 

Re: Get points from selected sketch

I want also this part, where i say whic axis but didnt know how, so thx

 

Dim Axis1 As DatumAxis = SelectAxis("Select X direction")
Dim Axis2 As DatumAxis = SelectAxis("Select Y direction")

 

I can add those checks.

 

I didnt undrstand this with loop Smiley Sad

 

Dim xform2 As NXOpen.Xform
xform2 = workPart.Xforms.CreateXform(tempPoint, direction1, direction2, NXOpen.SmartObject.UpdateOption.WithinModeling, 1.0)

 

U put temp point in this line only. 

And yah ur code look more smaller. Smiley Happy

 

Thx a lot for ur time. Smiley Happy