Showing results for 
Search instead for 
Do you mean 
Reply

Find Curves on a Specific Layer

Hello there,

 

I am trying to collect the curves on a certain layer with the following code:

 

Dim allCurves() As Curve = workPart.Curves.ToArray()
Dim curvesOnLayer(0) As Curve
Dim count As Integer
			
For Each cv As Curve In allCurves
    If cv.Layer = currentLayer Then
	ReDim Preserve curvesOnLayer(count)
	curvesOnLayer(count) = cv
	count += 1
    End If
Next

(currentLayer is defined somewhere else)

But it couldn't find any curves. I manually selected the features with the "Curve" selection intent on, and I could select them. So I am sure they are curve features.

 

I was wondering what is wrong with the code.

 

Thanks,

Kai

13 REPLIES

Re: Find Curves on a Specific Layer

In your code, what is the value of "currentLayer"? Are you sure that the curves that you are seeing reside on the layer that "currentLayer" represents?

Re: Find Curves on a Specific Layer

Thanks, cowski1.

 

Yes, I am sure about that.

Re: Find Curves on a Specific Layer

Try running this code to see if you get the same result (change the targetLayer value to your desired layer number before running the code):

 

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, "find curves on layer")

        lw.Open()

        Dim curvesOnLayer As New List(Of Curve)
        Dim targetLayer As Integer = 1

        For Each tempCurve As Curve In theSession.Parts.Work.Curves
            If tempCurve.Layer = targetLayer Then
                curvesOnLayer.Add(tempCurve)
            End If
        Next

        lw.WriteLine(curvesOnLayer.Count.ToString & " curves found on layer: " & targetLayer.ToString)

        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: Find Curves on a Specific Layer

[ Edited ]

Thanks, @cowski1. It still can't find the curves.

 

The file I am working on is an assembly. The curve is actually a linked composite curve in a component part. But I could select it as a curve manually.

 

Re: Find Curves on a Specific Layer

Can you post your test prt file?

Are you working in context of an assembly?

Re: Find Curves on a Specific Layer

The file I am working on is an assembly. The curve is actually a linked composite curve in a component part. But I could select it as a curve manually.

 

Capture.JPG

 

It is a large product file. I am sorry I cannot post it here.

Re: Find Curves on a Specific Layer

Is the curve linked from the component to the assembly or the other way around?

Which part is the work part when you run the journal?

Re: Find Curves on a Specific Layer

The curve is linked from the component to the assembly.

 

The workpart is the assembly.

Re: Find Curves on a Specific Layer

There must be something else going on in your assembly. I did a quick test; I created a line in the component and wave linked it to the assembly. The assembly is the display and work part, when running the code above, the linked line was found.