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

Getting coordinates of points withing the Point Set

Hello everyone! I again need some help. 

How to get coordinates of each point contained within the point set?

Well, I think I know how to get coordinates of points, the question is to how to get to the individual points when I have a 'Point Set' feature in a tree. And what's more difficult for me, it may not be Point Set itself, but copy of it made by use of Instance Geometry tool.

Can this be done? Any ideas?

22 REPLIES

Re: Getting coordinates of points withing the Point Set

If you have a Point Set feature, you can use the .GetEntities method to get the individual point objects that belong to the set.

 

If you use Mirror Feature to mirror a point set, the mirror feature will contain a point set feature that you can query. Other "instance" type functions (such as pattern geometry) are a bit more problematic since they do not reference the feature itself, but only the underlying geometry. In this case, you can iterate through the Points collection and use the .AskObjectFeat to determine which feature the point belongs to (if any).

Re: Getting coordinates of points withing the Point Set

Thank you! I'll try it. Basically, there's not much problem for me to change a model so that it has instanced curves and original Point Set feature on each curve.

Re: Getting coordinates of points withing the Point Set

Please advice how can I pick a feature? Is it done the same way as I pick an object by name and type, or is it another way for a feature?

Solution
Solution
Accepted by topic author Scaffold
‎10-10-2015 06:02 AM

Re: Getting coordinates of points withing the Point Set

Similar to how a part has a .Bodies collection or a .Points collection, it also has a .Features collection. You can iterate through the collection to process each feature or find a specific feature.

 

The code below iterates through the features collection and reports the points found in each "point set" feature.

 

Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        For Each myFeature As Features.Feature In workPart.Features
            If TypeOf (myFeature) Is Features.PointSet Then
                lw.WriteLine(".GetFeatureName: " & myFeature.GetFeatureName)
                lw.WriteLine(".Name: " & myFeature.Name)
                lw.WriteLine(".FeatureType: " & myFeature.FeatureType)
                lw.WriteLine(".Timestamp: " & myFeature.Timestamp.ToString)
                lw.WriteLine("")

                Dim myPoints() As NXObject = myFeature.GetEntities

                For Each tempPt As Point In myPoints
                    lw.WriteLine(tempPt.Coordinates.ToString)
                Next

            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

Re: Getting coordinates of points withing the Point Set

Thank you very much! Smiley Happy

I'll have a look and get back to you if I have questions.

Re: Getting coordinates of points withing the Point Set

@cowski1

If you use Mirror Feature to mirror a point set, the mirror feature will contain a point set feature that you can query.

I'm currently battling with using a Mirror Feature and it seems there is no way to actually get the resulting mirrored features.

For instance in a test part I created 2 associative line features and a block feature. I mirrored these using Mirror Feature (which produces an nxopen.features.Mirror). But if I use the getEntities() method all I get back are 2 Line objects (not features) and the block seems to be ignored.

Do you know how to get the mirrored features?

 

I'm now looking at the Mirror type of Instance Geometry instead. That produces an nxopen.features.Geomcopy which has getBodies(), getFaces() and getEdges() methods along with the getEntities(). I think for me that will be better.

 

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Getting coordinates of points withing the Point Set

[ Edited ]

The following code will iterate through the features collection of the work part and report on each mirror feature (the normal mirror features, not the wave link mirror body features).

 

Code was written/tested on NX 9.0.3.4

 

Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

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

            If tempFeature.FeatureType = "Mirror Feature" Then

                Dim mirrorBuilder As Features.MirrorBuilder = workPart.Features.CreateMirrorBuilder(tempFeature)
                Dim mirrorFeatures() As Features.Feature = mirrorBuilder.FeatureList.GetArray
                mirrorBuilder.Destroy()

                lw.WriteLine(tempFeature.GetFeatureName & " mirrors the following features:")
                For Each mirrorFeature As Features.Feature In mirrorFeatures
                    lw.WriteLine("  " & mirrorFeature.GetFeatureName)
                Next
                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

 

Re: Getting coordinates of points withing the Point Set

Maybe I wasn't clear. I know I can get the features that the Mirror is using as input, what I want is to be able to get the objects it creates as output.

As I said I can get curves using the getEntities() method, but bodies etc are not returned.

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Getting coordinates of points withing the Point Set

Sorry, I misunderstood your question.

 

I think this is a good question to ask GTAC. It seems to me that the API has some bugs regarding mirror features (.FeatureType is misleading at best). I created a small file and used the "mirror feature" command; querying the .FeatureType returns "Mirror Feature", but .GetType.ToString returns: "NXOpen.Features.Mirror". It seems that .FeatureType isn't reporting the true feature type; I get the error "cannot cast Mirror to Mirror Feature", indicating that .FeatureType is incorrect for this feature. For some reason, MirrorFeature has a .GetBodies method where the newer Mirror does not.