In Revit I draw a shape using property lines and import it into Dynamo.

Then using Python I draw a line between two random points (making sure this is all within my shape.)

Then I want to find the apexes of my shape that lie between the ends of my random line (if I drew perpendicular lines up and down from the random lines start and end points to intersect with the shape)

It works about 90% of the time… But I can’t work out why on earth sometimes I get an empty list returned.

The image below shows:
Red - the shape before I rotated it all to make the baseline horizontal (this makes the maths way easier)
Blue shape + points = rotated shape + its apexes
Blue line (my rotated random line)
vertical blue lines - every point between these I want my script to find… I’ve circled them in green.

You can see in this instance my list is empty instead of being a list of the green circled points:

Which line in the diagram above represents the baseline? The blue line? Is it possible that the baseline is vertical or close to it? Keep in mind as you rotate the baseline, the distance between the horizontal extents gets smaller since you’re not measuring perpendicular to the rotated line.

Ah, I see. I had it backwards then. Can you show us the outputs for the baseline extents (P1_X and P2_X) as well as the individual X values for the RotatedApexes?

These are the apexes above…
Below is:
[4] this is meant to be the apexes with X values between the line endpoint X values
[5] P1 _X
[6] P1 _Y
[7] Point 1
[8] this is meant to be rotated P2_X
[9] Rotated P2
[10] Original P2

So the issue is that sometimes P2r_X is giving a false reading… but I have no idea why!

Yup that’s exactly where I noticed your issue. Previously, you get P2r_X from the original rotated location, but then you reorder P1 and P2r to ensure the P1 is always the leftmost point. You don’t update P2r_X at this point, so you potentially have P1 and P2r_X being the same points.

Now you’re updating it after checking base extents so you always have both values.