Turn string from usertext into plane object

Dear all.

any suggestions how is can turn the string of a plane object into an actual plan object again?

import rhinoscriptsyntax as rs

objects = rs.GetObjects(message="Select polysurface  ", filter=16, preselect=False, select=False,)

for obj in objects:
    box = rs.BoundingBox(obj)
    plane = rs.PlaneFromPoints(box[0], box[1], box[4])
    rs.SetUserText(obj, "plane", plane)

for obj in objects:
    string = rs.GetUserText(obj, "plane")
    #What is the easiest way to turn the string into an actuall plane object?

In grasshopper i use this constructor, so deconstruct the plane to an origin & two vectors, then rebuild.

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

Are you looking for rs.coerceplane?

import rhinoscriptsyntax as rs

objects = rs.GetObjects(message="Select polysurface  ", filter=16, preselect=False, select=False,)

for obj in objects:
    box = rs.BoundingBox(obj)
    plane_id = rs.PlaneFromPoints(box[0], box[1], box[4])
    plane = rs.coerceplane(plane_id)
import rhinoscriptsyntax as rs
from operator import add
import re

objects = rs.GetObjects(message="Select polysurface  ", filter=16, preselect=False, select=False,)
for obj in objects:
    box = rs.BoundingBox(obj)
    plane = rs.PlaneFromPoints(box[0], box[1], box[4])
    rs.SetUserText(obj, "plane", plane)

for obj in objects:
    values = re.findall(r"[-\d.]+", rs.GetUserText(obj, "plane"))
    origin = [float(values[0]), float(values[1]), float(values[2])]
    x_axis = [float(values[3]), float(values[4]), float(values[5])]
    y_axis = [float(values[6]), float(values[7]), float(values[8])]
    plane = rs.PlaneFromPoints(origin, map(add, x_axis, origin), map(add, y_axis, origin))

StringToPlane.py (707 Bytes)

This is exactly what I was looking for, also coded in a very nice way. Thank you for the lesson!