GetLine returns Tupple to World coordinates

Hi,

I have just realized that GetLine method returns World coordinates of two points. It makes sense however I just moved the CPlane and spend some time I realized its behaviour. I think it would be useful to include it in the documentation that points are according to the World coordinates and not the actual CPlane.

By the way I started building a script but something is not working properly. The XFormWorldtoCPlane does not translate.

profile CPlane.3dm (25.7 KB)

import Rhino
import rhinoscriptsyntax as rs
import time

world = rs.PlaneFromFrame( [0,0,0], [1,0,0], [0,1,0] )
rs.ViewCPlane (None, world)
# curve = rs.GetObject("Select the path", filter=4 )
# rs.SetUserText (curve, "Name", "route01", False)
profile = rs.GetObject ("Select profile",0,False,False,None,False)
plane = rs.CurvePlane (profile, segment_index=-1)
plane0 = rs.ViewCPlane (None, plane)
startX = rs.GetLine(mode=0, point=None, message1="X Axis of the profile", message2=None, message3=None)
print startX[0]
print startX[1]
point1 = rs.AddPoint(startX[0])
point2 = rs.AddPoint(startX[1])
point1 = rs.XformWorldToCPlane (startX[0], plane0)
point2 = rs.XformWorldToCPlane (startX[1], plane0)
print point1
print point2

Sometimes “< CPLane>.RemapToPlaneSpace(WorldXY.Point, out CPlane.Point)” does what you want.

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Plane_RemapToPlaneSpace.htm

// Rolf

Thank you, It is interesting , however the return value is a Boolean and it has two Point3d parameter. I want to get the Point3D coordinates as a result .

That (the result) is what you get in the second (out) parameter. Like so:

var ResultPoint = Point3d.Unset;
if (YourPlane.RemapToPlaneSpace(WorldPoint, out ResultPoint))
{
  // use your "ResultPoint" safely, or just run the command without any check...
}

No checking

var ResultPoint = Point3d.Unset;
YourPlane.RemapToPlaneSpace(WorldPoint, out ResultPoint);
// use your ResultPoint.

// Rolf

Rhino SDK functions always returns 3-D points in world coordinates unless otherwise specified.

– Dale

That’s true. After I think over its logic. :slight_smile:

Hi Dale,

I found a bug in the code. The code did not work before but when I introduce a new line rs.CPlane() in the code it works just fine. Could you have a look at it? (Row no.12)

import Rhino
import rhinoscriptsyntax as rs
import time

world = rs.PlaneFromFrame( [0,0,0], [1,0,0], [0,1,0] )
rs.ViewCPlane (None, world)
# curve = rs.GetObject("Select the path", filter=4 )
# rs.SetUserText (curve, "Name", "route01", False)
profile = rs.GetObject ("Select profile",0,False,False,None,False)
plane = rs.CurvePlane (profile, segment_index=-1)
plane0 = rs.ViewCPlane (None, plane)
rs.ViewCPlane ()
startX = rs.GetLine(mode=0, point=None, message1="X Axis of the profile", message2=None, message3=None)
print startX[0]
print startX[1]
point1 = rs.AddPoint(startX[0])
point2 = rs.AddPoint(startX[1])
point1 = rs.XformWorldToCPlane (startX[0], plane0)
point2 = rs.XformWorldToCPlane (startX[1], plane0)
print point1
print point2

Thanks RIL,

I tried this method however I got None value in Python.

import rhinoscriptsyntax as rs
import Rhino
import Rhino.Geometry
import scriptcontext

world = rs.PlaneFromFrame( [0,0,0], [1,0,0], [0,1,0] )
rs.ViewCPlane (None, world)

inputPt = rs.GetObject("select points", 1)
inputPt = rs.coerce3dpoint(inputPt)

curve = rs.GetObject("select curve")
curve = rs.CurvePlane (curve, segment_index=-1)

plane = rs.ViewCPlane (None, curve)
plane = rs.coerceplane(plane)

world_point = inputPt

world_to_plane = Rhino.Geometry.Transform.ChangeBasis(plane, Rhino.Geometry.Plane.WorldXY)
plane_point = world_point
point = plane_point.Transform(world_to_plane)
id = scriptcontext.doc.Objects.AddPoint(point)

How about this?

import Rhino
import rhinoscriptsyntax as rs

def Test():
    
    curve_id = rs.GetObject("Select curve")
    if not curve_id: return
    
    point_id = rs.GetObject("Select point", 1)
    if not point_id: return
    
    point = rs.coerce3dpoint(point_id)
    print "Point in world-xy plane coordinates = ", point
    
    curve_plane = rs.CurvePlane(curve_id)
    xform = Rhino.Geometry.Transform.ChangeBasis(Rhino.Geometry.Plane.WorldXY, curve_plane)
    point.Transform(xform)
    print "Point in curve plane coordinates = ", point

Test()

– Dale

Thanks, Dale.

I learnt a lot again. So, CPlanes can be different in every view and rs.ViewCPlane returns the previous(!) CPlane in the view (It is tricky). C#-vise by applying method for an object variable it changes its value so we are able to use the same variable with the modified data. As well as planes do not need to be coerced.