Best way to script interactive extrusion ? (Python / Py+Rhinocommon)


#1

Hi All
I would like to crate my own script for extruding objects but I would like to try to understand better how to get display interaction so I’m asking if you could, please, post an example on how to get interactive extrusion.

Just a simple one, select a curve, drag a mouse, while dragging the object update by extruding, pick a point and the object it’s created.

Thanks for answering me


(Dale Fugier) #2

Rhino’s Extrusion command(s) dynamically draw the end result in a point pick operation. In RhinoCommon, you’d inherit a new class from Rhino.Input.Custom.GetPoint. Within this class, you’d override the OnMouseMove and OnDynamicDraw virtual functions.

In OnMouseMove, you’d calculate the geometry you want to dynamically draw, based on the current viewport and current mouse point. In OnDynamicDraw, you’d draw the geometry you calculated in OnMouseMove.

I don’t have an Extrustion-type example to show you. But here is a simple example of inheriting a new class from ```Rhino.Input.Custom.GetPoint``. In this example, all I do is dynamically draw a text dot. But you might get the idea of what you need to do from this.

import Rhino
import rhinoscriptsyntax as rs

class SampleGetTextDotPoint(Rhino.Input.Custom.GetPoint):
    def OnDynamicDraw(self, e):
        e.Display.DrawDot(e.CurrentPoint, e.CurrentPoint.ToString())

def SampleTextDot():
    gp = SampleGetTextDotPoint();
    gp.Get()
    if (gp.CommandResult() == Rhino.Commands.Result.Success):
        rs.AddTextDot(gp.Point().ToString(), gp.Point())
        rs.Redraw()
 
if __name__=="__main__":
    SampleTextDot()

#3

Thanks Dave,
I’ll give it a try and see if I can manage by myself to put an extrusion script together.

Thanks.


(Matt Gaydon) #4

@dale

Would an edit of the script work if I wanted to dynamically move a clipping plane ? Either in space or along a Crv or Vector? Or do I need some more complex coding for event handling.

I have been able to edit the script to constrain it to a curve but not make the clipping plane dynamic like if you drag it with a gumball.

Thanks Matt


#5

Hi Dale
how can I represent the coordinates with 2 digits of precision?
Ciao Vittorio


(Dale Fugier) #6

How about this?

import Rhino
import rhinoscriptsyntax as rs

def FormatPointString(p):
        x = p.X.ToString("0.00")
        y = p.Y.ToString("0.00")
        z = p.Z.ToString("0.00")
        s = "{0},{1},{2}".format(x, y, z)
        return s

class SampleGetTextDotPoint(Rhino.Input.Custom.GetPoint):
    def OnDynamicDraw(self, e):
        p = e.CurrentPoint
        s = FormatPointString(p)
        e.Display.DrawDot(p, s)
 
def SampleTextDot():
    gp = SampleGetTextDotPoint();
    gp.Get()
    if (gp.CommandResult() == Rhino.Commands.Result.Success):
        p = gp.Point()
        s = FormatPointString(p)
        rs.AddTextDot(s, p)
        rs.Redraw()
 
if __name__=="__main__":
    SampleTextDot()

#7

Thanks Dale
It is Ok
Ciao Vittorio