Showing results for 
Search instead for 
Do you mean 

Select Curves in a rectangle

Hi I would like to write an api .net program that deletes all curves in a bounded area (given by two points (x,y)) The work is on a drawing sheet, and I know the boundaries of the area that I want to clear. I can select all lines, and check each one's end points, but I have thousands of lines, Is there a simple way to do it in NX api .NET? Thanks a lot, Idit Gvirtz

Re: Select Curves in a rectangle

[ Edited ]

Your code should cycle through all lines in the file. If a given line's end-points are inside the rectangle, then the line is inside the recetangle, so you should add this line to the delete list.


Here's some example code. It uses SNAP functions, but the basic idea would be same using NX/Open functions


Option Infer On
Imports Snap, Snap.Create

Public Class MyProgram

    Public Shared Sub Main()

      ' Use the rectangle from (3,4) to (7,9), as an example
      Dim lowerLeft  = New Position(3,4)
      Dim upperRight = New Position(7,9)

      Dim deleteList As New List(Of NX.Line)

      For Each lin In Snap.Globals.WorkPart.Lines
         Dim startPtIn = PointInRectangle(lowerLeft, upperRight, lin.StartPoint)  
         Dim   endPtIn = PointInRectangle(lowerLeft, upperRight, lin.EndPoint)  
         If startPtIn And endPtIn Then deleteList.Add(lin)

    End Sub

   Private Shared Function PointInRectangle(lowerLeft As Position, upperRight As Position, pt As Position) As Boolean
      Dim inside As Boolean = True
      If pt.X > upperRight.X Then inside = False
      If pt.Y > upperRight.Y Then inside = False
      If pt.X < lowerLeft.X Then inside = False
      If pt.Y < lowerLeft.Y Then inside = False
      Return inside
   End Function

End Class

Re: Select Curves in a rectangle

Hi Yamada

Thanks a lot,