Cplane with python

hello,

i searched but I don’t understand how we can move the Cplane,
when I scripted :

cplane=rs.PlaneFromPoints(pt1, pt2, pt3)
rs.ViewCPlane(view=None, plane=cplane)
pt5=rs.AddPoint(0,0,0)

pt5 is on the 0 of rhino world coordinates i would it place my pt5 on pt1, how can I do?

pt5=rs.coerce3dpoint([0,0,0])
plane.Origin=pt5

Will move the origin of the plane “plane” to 0 (if that’s what you want)

no … I’m not sur you understand my question…

i fact, without script i use the _CPlane command and i draw all my works without thinking about the world general Cplane, and at the end i reset the world general Cplane…

i would like to make it in the script:

  • move cplane with 3 points
  • draw a box 3000 x 1200 x 400 at the origine of the cplane
  • reset the cplane

all that i found, is:
addpoints
move points to the new coordinate
draw the box with the moved points

is it the way to make it?

OK, but if you are just wanting to draw a box at some arbitrary plane coordinates, why not just either draw it directly at the plane, or, draw it at the world origin then transform it to the new plane. If you are going to change the CPlane back to what it was before immediately after making the box, there is no reason really to change the CPlane at all.

Hang on a few, I can create a sample.

Two ways to build the box directly on the plane:

import rhinoscriptsyntax as rs

#these points are arbitrary for the example
pt1=rs.coerce3dpoint([10,10,10])
pt2=rs.coerce3dpoint([20,20,20])
pt3=rs.coerce3dpoint([0,20,10])
c_plane=rs.PlaneFromPoints(pt1, pt2, pt3)

leng=3000
wid=1200
ht=400

c1=c_plane.Origin
c2=c1+leng*c_plane.XAxis
c3=c2+wid*c_plane.YAxis
c4=c1+wid*c_plane.YAxis
c5=c1+ht*c_plane.ZAxis
c6=c2+ht*c_plane.ZAxis
c7=c3+ht*c_plane.ZAxis
c8=c4+ht*c_plane.ZAxis
rs.AddBox([c1,c2,c3,c4,c5,c6,c7,c8])

or, a little more RhinoCommon

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

#these points are arbitrary for the example
pt1=Rhino.Geometry.Point3d(10,10,10)
pt2=Rhino.Geometry.Point3d(20,20,20)
pt3=Rhino.Geometry.Point3d(0,20,10)
plane=Rhino.Geometry.Plane(pt1, pt2, pt3)

#another way of making the box without 8 corner points...
box_len=Rhino.Geometry.Interval(0,3000)
box_wid=Rhino.Geometry.Interval(0,1200)
box_ht=Rhino.Geometry.Interval(0,400)
box=Rhino.Geometry.Box(plane,box_len,box_wid,box_ht)
sc.doc.Objects.AddBox(box)
sc.doc.Views.Redraw()

Thanks, but I need to cover a flat area of ​​3m X 1.2m X 0.4m block. this surface to be covered is rectangular but never oriented in the same way. this is why I would like to first select the point of origin of this surface, then the two points which give the length and the width of the surface.
then I have to create a loop to cover the surface: we lay a block, if there is room to lay a second one, then we lay it, otherwise we cut it lengthwise and collect the scrap to start the second line And so on…

two possibilities either I follow X and Y then I move all the generated blocks, or I move the construction plan to generate the blocks directly in the right place…

I understand that you prefer the first solution… No?

Well, as I said before, I personally prefer not to change the CPlane in a viewport if one is not actually going to work in the Rhino interface in that CPlane, because the risk is if the script is cancelled in the middle the viewport remains stuck in that changed CPlane. But your experience may vary.

For me it doesn’t matter if the items are created directly in the planes that are desired or creating them on the World XY plane and then transforming them to the desired plane. The result is the same. The first works a little more like Grasshopper. For scripts, the second method may be easier if you have lots of objects that take the same transformation, because you don’t need to worry about the difference between world and CPlane coordinates when creating objects, you just grab them all and transform them plane to plane at the end.

This is the second method…

import rhinoscriptsyntax as rs

leng=3000
wid=1200
ht=400

#make the box on world XY
wxy_plane=rs.WorldXYPlane()
c1=wxy_plane.Origin
c2=c1+leng*wxy_plane.XAxis
c3=c2+wid*wxy_plane.YAxis
c4=c1+wid*wxy_plane.YAxis
c5=c1+ht*wxy_plane.ZAxis
c6=c2+ht*wxy_plane.ZAxis
c7=c3+ht*wxy_plane.ZAxis
c8=c4+ht*wxy_plane.ZAxis
w_box=rs.AddBox([c1,c2,c3,c4,c5,c6,c7,c8])

#these points are arbitrary for the example
pt1=rs.coerce3dpoint([10,10,10])
pt2=rs.coerce3dpoint([20,20,20])
pt3=rs.coerce3dpoint([0,20,10])
c_plane=rs.PlaneFromPoints(pt1, pt2, pt3)

#create the transformation and transform the box (no copy)
xform=rs.XformRotation1(wxy_plane,c_plane)
c_box=rs.TransformObject(w_box,xform,False)