GetPoint.OnDynamicDraw with dynamic display within?


#1

I was trying to get a dynamic display within Rhino.Input.Custom.GetPoint.OnDynamicDraw. The point would be to include an iterative process dependent on the mouse position, and show these iterations (e.g. mouse moves once, but as a result, geometry changes 10x, and I want to show that as an animation).

I was trying to achieve this by making OnDynamicDraw() recursive (couldn’t get it to work) or opening a new conduit (also doesn’t work like this). Any thoughts on how to make this work? I’m not a total noob at Python, but this level of Rhinocommon use is a bit beyond me.

import Rhino
import System.Drawing
import scriptcontext as sc

class GetLines(Rhino.Input.Custom.GetPoint):
    
    def OnDynamicDraw(self, args):
        for i in range(10):
            pt3 = Rhino.Geometry.Point3d(0,0,i)
            line = args.Display.DrawLine(pt3, args.CurrentPoint, System.Drawing.Color.Green, 2)

class GetLinesRecursive(Rhino.Input.Custom.GetPoint):
    
    def __init__(self):
        self.count = 0
    
    def OnDynamicDraw(self, args):
        
        print self.count
    
        if self.count < 10:
            pt3 = Rhino.Geometry.Point3d(0,0,self.count)
            line = args.Display.DrawLine(pt3, args.CurrentPoint, System.Drawing.Color.Green, 2)
            self.count += 1
            OnDynamicDraw(args)
        else:
            pass

class GetLinesConduit(Rhino.Input.Custom.GetPoint):
    
    def __init__(self):
        self.count = 0
    
    def OnDynamicDraw(self, args):
        
        while self.count < 10:
            pt3 = Rhino.Geometry.Point3d(0,0,self.count)
            conduit = DrawConduit(pt3, args.CurrentPoint, System.Drawing.Color.Green)
            conduit.Enabled = True
            sc.doc.Views.Redraw()
            conduit.Enabled = False
            self.count += 1

class DrawConduit(Rhino.Display.DisplayConduit):
    
    def __init__(self, pt3, pt4, color):
        self.pt3 = pt3
        self.pt4 = pt4
        self.color = color
        
    def DrawOverlay(self, args):
        args.Display.DrawLine(pt3, pt4, color, 2)

gp = GetLines()
gp.Get()

gp2 = GetLinesRecursive()
gp2.Get()

gp3 = GetLinesConduit()
gp3.Get()

#2

Anyone? I’d be happy to rephrase if the question isn’t clear? Any help much appreciated!


(Dale Fugier) #3

Please? :wink:

– Dale


#4

Yes, I’m grovelling…


#5

I think Dale was asking for you to rephrase, Groveling is not usually necessary with him unless you’re requesting a new feature that will take more than an hour or two to code, and then it doesn’t do much good anyway.


#6

Ah… I see. Well, I’m not sure how to restate the problem; but the simplest I can think of it this:

Is it possible to redraw geometry within a call to OnDynamicDraw of GetPoint? If so, how would I approach this?


(Dale Fugier) #7

Hi @dveenendaal,

Rather than trying to explain your implementation, perhaps you should begin what what you are trying to do (big picture) and why? What problem are you trying to solve. Once this is understood, we will be better at helping with an implementation.

– Dale


#8

What?
I wish to visualize an iterative process (form finding) as the mouse moves. The mouse moves a point that works as an attractor/constraint. That point is part of temporary geometry in the display. Once the user is satisfied, the geometry is added to the drawing.

Why?
A single mouse move requires a few iterations to solve (for equilibrium). Early iterations may already reveal the validity of a mouse move, so presenting this geometry as feedback to the user is useful in his decision making.

Implementation
I have everything working that I’m describing except visualizing iterations sequentially. They are all drawn at once per mouse move when I use GetPoint.


(Dale Fugier) #9

You might consider working on a way to flatten (e.g. remove the recursiveness) form your algorithm. Then, just draw the results…


#10

So, it’s not possible?

The algorithm is inherently recursive, because the problem is nonlinear, hence the iterations for each mouse move.


(Dale Fugier) #11

Hi @dveenendaal,

It’s probably do-able. But your code isn’t providing me enough clues on how I can help - sorry.

– Dale