IntersectionResult parameter getter throws an InvalidOperationException

IntersectionResult parameter getter throws an InvalidOperationException

matyas.csanady3GW48
Participant Participant
735 Views
8 Replies
Message 1 of 9

IntersectionResult parameter getter throws an InvalidOperationException

matyas.csanady3GW48
Participant
Participant

Hey everybody! As the title mentions I'm having some surprising difficulties with the IntersectionResult class. Long story short I check the intersection of 2 line elements (i know for a fact that these 2 lines intersect) with (link)

SetComparisonResult result = line1.Intersect(line2, out resultArray);

It's all nice and fine at this point since the result and resultArray are not null. I can get the IntersectionResult out of the IntersectionResultArray for example by:

IntersectionResult intResult = resultArray.get_Item(0);

But I'm intersected in IntersectionResult.Parameter property (link), and when i try to get the value of this parameter an InvalidOperationException is thrown. Checking the Parameter property documentation again it claims that it happens when it has not been set yet "Thrown in the getter when this property has not been set by the method providing the result. ".
Checking this Parameter property in debug reveals that it's not the only one failing. As you can see on the picture the "Distance", "EdgeObject", "EdgeParameter" and "Parameter" all fail with InvalidOperationException.

Kép.png

This issue occurred to me in a C# addin in all current version versions (22->25). For testing purposes I've created a python script that you can paste into RevitPytonShell and it results is the same error across all versions.

results = clr.Reference[DB.IntersectionResultArray]()

t = DB.Transaction(doc, "Line Creation")
t.Start()

lineV = DB.Line.CreateBound(DB.XYZ(0,0,0), DB.XYZ(0,10,0))
lineH = DB.Line.CreateBound(DB.XYZ(-5,5,0), DB.XYZ(5,5,0))

doc.Create.NewDetailCurve(uidoc.ActiveView, lineV)
doc.Create.NewDetailCurve(uidoc.ActiveView, lineH)

result = lineV.Intersect(lineH, results)

intResult = results.get_Item(0)
# For example this works
print("XYZPoint: {}".format(intResult.XYZPoint))
# But the following all fail
print("Distance: {}".format(intResult.Distance))
print("EdgeObject: {}".format(intResult.EdgeObject))
print("EdgeParameter: {}".format(intResult.EdgeParameter))
print("Parameter: {}".format(intResult.Parameter))

t.Commit()

 

Even if it's outside of a Transaction (since Line creation and Line.Intersect does not require that), the results are the same.

results = clr.Reference[DB.IntersectionResultArray]()

lineV = DB.Line.CreateBound(DB.XYZ(0,0,0), DB.XYZ(0,10,0))
lineH = DB.Line.CreateBound(DB.XYZ(-5,5,0), DB.XYZ(5,5,0))
result = lineV.Intersect(lineH, results)

intResult = results.get_Item(0)
# For example this works
print("XYZPoint: {}".format(intResult.XYZPoint))
# But the following all fail
print("Distance: {}".format(intResult.Distance))
print("EdgeObject: {}".format(intResult.EdgeObject))
print("EdgeParameter: {}".format(intResult.EdgeParameter))
print("Parameter: {}".format(intResult.Parameter))

 

 Would appreciate any help with this problem!

0 Likes
Accepted solutions (1)
736 Views
8 Replies
Replies (8)
Message 2 of 9

jeremy_tammik
Alumni
Alumni

I would like to pass this on to the development team for analysis, including a complete minimal sample in order for them to be able to reproduce the issue with a single click, if possible. Could you create a simple RVT (that can be empty) including a C# macro to execute to reproduce the problem, please? Thank you!

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 9

matyas.csanady3GW48
Participant
Participant

Hi Jeremy!

Thank you for your quick reply and for the fact that you forward this issue to the DEV team. As you asked for I've created a macro that is able reproduce the same exception with a single click. I've attached an empty Revit project file that contains this macro, as expected running the macro throws the same exception.

0 Likes
Message 4 of 9

jeremy_tammik
Alumni
Alumni

Thank you for creating the macro. I see that the RVT filename ends in R22. Does that stand for Revit 2022? Could you please try it out in a more recent version? I believe that the next major release is being expected soon, and the development team (and all of Autodesk) refuse to support more than three major versions back, so Revit 2022 is out of scope. Thank you!

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 9

matyas.csanady3GW48
Participant
Participant

I've updated it to Revit2025 and attached it.

0 Likes
Message 6 of 9

mhannonQ65N2
Collaborator
Collaborator

The Curve.Intersect method does not set the IntersectionResult's Parameter property. Look at the documentation for Curve.Intersect to see which properties are set and what they mean.

0 Likes
Message 7 of 9

tamas.deri
Advocate
Advocate

Whoever designed this part of the API deserves a raise. /s

It seems that the Parameter and Distance properties of the IntersectResult object will never get set by any of the methods creating it. So what was the intent?

Message 8 of 9

mhannonQ65N2
Collaborator
Collaborator

IntersectionResult's Parameter and Distance properties are both set by the Curve.Project method. The problem with IntersectionResult is that it is used to return results for several different geometric methods.

0 Likes
Message 9 of 9

jeremy_tammik
Alumni
Alumni
Accepted solution

Thank you for the clear clarification. I shared it on the blog to avoid future similar confusion:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open