Using the NXOpen Line class, I need to compare lines vs lines to see if they are the exact same line. How can I know how the lines will compare when using the .equals() method provided in the NX 8.5 API (which is the version I'm using). I could create test cases and narrow down the potential options, but I thought I'd ask here first.
Will the line.equals(otherLine) method compare the start points vs end points for each of the lines? Where can this information be found?
This is how I would like to parse through the list.
If Not lines.Contains(line) Then lines.Add(line) End If
However I could do something like this:
Dim lineFound As Boolean = False For each line As Line in lines if math.abs(line.start.x - otherLine.start.x) < 0.001 and...etc lineFound = True end if Next if not lineFound lines.add(otherline) end if
It's just not as clean! Thanks
Solved! Go to Solution.
The .Equals method is defined in the .net framework and is available to every object. Its behavior is slightly different depending on whether value types or reference types are passed to it. For a more complete discussion see:
Comparing value types is fairly straightforward either the two values are equal or they are not.
Dim a As Integer = 5 Dim b As Integer = 5 a.Equals(b)
Comparing reference types (objects are reference types) is trickier.
Dim line1 As Line = workPart.Curves.CreateLine(stpt, endpt) Dim line2 As Line = workPart.Curves.CreateLine(stpt, endpt) Dim line3 As Line = line1
The code above creates 3 references to line objects; 2 (overlapping) lines will appear in the graphics window. The line3 object variable references line1; we have 2 objects that reference the same instance of a line.
If the .Equals method uses the same implementation as the .net object.Equals method, then the above will return True because they reference the same object.
However, the .Equals method in the NXOpen API may be overridden to provide different behavior.
May return True or False, depending on the NXOpen implementation. It may be that the API developers have provided a way to test 2 different line objects to see if they occupy the same space. It is impossible to tell from the .net API reference document alone whether it compares object references or values on the line (start and end points, perhaps).
I'd suggest running a few tests; create 2 separate line objects that you know are equal (same start and end points), and examine the output of the .Equals method.
Note you might also want to test if the lines are "equal" when the endpoints are reversed:
Dim line1 As Line = workPart.Curves.CreateLine(stpt, endpt) Dim line2 As Line = workPart.Curves.CreateLine(endpt, stpt)
in this case, is line1 == line2?
Technically, they both occupy the same space, but the (vector) direction is different.
Wheher or not that is an issue for you depends on your application - it may be important, it may not.
Production: NX10.0.3.5 MP16/TC11.2
I'd rather be e-steamed than e-diseaseled
I agree that UF_CURVE_LINE_ARC_is_line_equal is your best bet. According to its documentation, it does a *geometric* comparison of the two lines, which is what you want, apparently. The Equals function is probably checking whether two memory locations are the same, which is a much stronger requirement.
If you want your code to be pretty, write a function called GeomEqual, or something like that. It should receive two lines, call UF_CURVE_LINE_ARC_is_line_equal, and then return a boolean. Once you have this, you can write code like
if GeomEqual(line1, line2) then ...