Reference the Point in a Feature

Hi All,

I'm looking for a little help in putting together a vb journal that will list the names and coordinates of many point features that I have selected from a work part (in NX9).

I think I need to select the features so that I can get the names, but then the features don't have any location info.

Here's an excerpt:

Dim selectedObjects() As NXObject
Dim myPoint As Point
Dim myFeature As Features.PointFeature
For Each myFeature In selectedObjects
' Somehow set myPoint as the point contained in myFeature
' So that I can do something like:
lw.WriteLine(myFeature.GetFeatureName & " - " & myFeature.Name)
lw.WriteLine(myPoint.Coordinates.X.ToString("N3") & vbTab & _ myPoint.Coordinates.Y.ToString("N3") & vbTab & _ myPoint.Coordinates.Z.ToString("N3"))
Next

Am I even going about this the right way? Should I be selecting the points instead of the features?
Any help would be appreciated.

Thanks,
Seth

If you have a reference to a point feature, you can use the .GetEntities method to access the point object itself. The code below shows one way to do this.

Option Strict Off
Imports System
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()

For Each tempFeature As Features.Feature In theSession.Parts.Work.Features

If TypeOf (tempFeature) Is Features.PointFeature Then

'get the point object from the feature
Dim nxObj() As NXObject = tempFeature.GetEntities
Dim thePt As Point = nxObj(0)
lw.WriteLine("feature: " & tempFeature.GetFeatureName)
lw.WriteLine("point location: " & thePt.Coordinates.ToString)
lw.WriteLine("")

End If

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

Thanks very much!
It was the GetEntities function that I was missing. I actually stumbled across it in the object browser, but couldn't work out how to implement it.
Thanks again.

So I'm still working on this journal, and trying to handle a few more selection cases. I'd like the user to be able to select a bunch of points from the graphics window, and have my journal be able to tell if a point is part of a feature.
I've defined:
Dim selectedObjects() As NXObject
Dim featCollection As Features.FeatureCollection = workPart.Features
and i'm using:
featCollection.GetAssociatedFeature(selectedObject)

but I know that if I select a featureless point i get a null reference exception.
So I'd like to do something like:
If featCollection.GetAssociatedFeature(selectedObject) <> Null Then
' Do something with the feature
Else
' Skip it
End If

But I can't figure out how to implement it.
Any tips?
Thanks again.

Looking at the API reference doc, it looks like the following should work:

dim theFeat as features.feature
theFeat = featCollection.GetAssociatedFeature(selectedObject)
if isNothing(theFeat) then
'not part of a feature
else
'theFeat is the associated feature
end if