I have created some Associative points and renamed like point1, point2 etc, and added in layer 10, below is my code
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
For Each myPoint As Point In workPart.Points
If myPoint.Layer = 10 Then
lw.WriteLine(myPoint.Name)
lw.WriteLine(myPoint.Coordinates.ToString)
End If
Next
End Sub
End Module
When I execute above code I am getting coordinates but not names of points
can you please let me know where is problem in my code and I need names of these points please help me
Thanks
re: point names
In NX, features (the entries you see in the part navigator) create and manage geometric objects. NX allows you to apply a name to the feature and/or the object. The code that you posted will report the name as applied to the object itself. Since you do not get any results, I'm going to assume that you have applied the names to the point features. Do your custom names show up in the part navigator? If so, those are feature names.
So, there are a few options here:
Which you use will depend on your needs. I can help with any of the above if you have specific questions.
Hi.
Hi.
Thanks for your quick reply,
Yes names are given to features and these names are appearing in part navigator;
I tried with another method, below is my code
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Features
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Dim mypoint1 As PointFeature
For Each myFeature As Feature In workPart.Features
If TypeOf (myFeature) Is PointFeature Then
mypoint1 = myFeature
lw.WriteLine(mypoint1.Name)
End If
Next
End Sub
End Module
This time I am getting feature name but I am note getting layer and coordinate properties,
My requirement is to process all the points in specific layer say layer 10 and get name and coordinate of point
can you please help me
thanks In Advance
re: point features
The point feature (myPoint1, in your code) has a .Location property that returns a Point3D structure. This is one way to get the coordinates of your point. Try the following:
lw.writeline(myPoint1.Location.ToString)
Alternatively, you could use the point feature's .GetEntities method to gain access to the point object and query its .Coordinates property (also returns a Point3D structure).
Hello,
Hello,
Thanks For Your reply,
when I am using location property I am Getting below Error
NXOpen.NXException: Feature has no Origin
at NXOpen.Feature.get Location()
since I need both Layer and coordinate properties I used GetEntities method but I am getting below error
System.IndexOutOfRangeException: Index was outside the bounds of the array
Below is my code
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Features
Module Module1
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Dim mypoint1 As PointFeature
For Each myFeature As Feature In workPart.Features
If TypeOf (myFeature) Is PointFeature Then
mypoint1 = myFeature
lw.WriteLine(mypoint1.Name)
Dim myNxObject() As NXObject
myNxObject = mypoint1.GetEntities()
Dim pt As Point = CType(myNxObject(0), Point)
lw.WriteLine(pt.Coordinates.ToString)
lw.WriteLine(pt.Layer)
End If
Next
End Sub
End Module
can you please suggest what is problem in my code
re: point coordinates
I created a simple part (3 point features) and ran your code; it completed successfully for me. What version of NX are you using? What features are contained in your part? Does your part have point sets or patterns of point features?
Earlier I was checking in
Earlier I was checking in lower version of NX, I was getting Error, Now I checked in higher version it is working fine
Thank you so much for your grate help
Thanks