I’m sure someone has solved this, but I have not been able to find it yet. I would like to draw a closed polyline on the C-Plane whose corners are exactly at the 4 corners of the active viewport. I know this has something to do with this API “Transform Screen to World Coordinates” documentation in C++, but I can’t figure it out how to do this in C# or python in Grasshopper.
The reason I want to do this is that I would like to be able to select the outside frame of the viewport as a curve while Make2D with curves that are inside the frame. The Make2D should then output a rectangle that should be the exact proportion and proper location of an image saved with ViewCaptureToFile. If I am right, it seems like this would make lining up vector drawings and raster underlays in Illustrator easier without all of the fussy scaling. You could just snap the image to the corners of the rectangle and the drawing and images should be aligned.
Maybe I’m just making this harder than it has to be so please enlighten me with a better way to do this! @andheum I bet you know how to do this! I feel like some of your Human tools are so close to providing the right combination of parameters.
Rhino.Display.RhinoViewport.ClientToWorld(Point2d) is I believe what you are looking for. This takes the pixel coordinates and returns a line that sort of follows the line into the screen. Intersect this with the desired CPlane to get the point you are after.
Use RhinoViewport.Bounds to get the pixel coordinates of the corners of the viewport
Thanks Andrew. A couple days ago I made a python component that does basically the same thing (but doesn’t seem to work for 2-pt perspective). I started testing it and then discovered that in Rhino 6, the Make2D has an option for automatically projecting the viewport rectangle to the cplane! In addition, for some reason both your script and my script doesn’t produce a rectangle that works when in perspective view. If the curve is offset in by a small amount, Make2D includes it but if not, it ignores it. Works fine for parallel views.
Of course, you script is about 10% the size of my script in python. I couldn’t find the ClientToWorld method in python so I went about it differently. ViewRectFlat.gh (42.1 KB)