Dynamic move object with Python Common


#1

Hi Steve
I want move one object dynamically but the below Python code don’t make it, where is my error?:

#-*- encoding: utf-8 -*-
#  Rhino Common  Dynamic move object

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def move_obj():
    obj=rs.GetObject("select one object")
    
    pt_start=rs.GetPoint("Reference point")  # con metodo script     
    #************** funzione che disegna dinamicamente *********************
    
    def GetPointDynamicDrawFunc( sender, args ): 
        vect=args.CurrentPoint-pt_start
        translation = rs.coerce3dvector(vect, True)
        translation=Rhino.Geometry.Transform.Translation(translation)
        print translation
        a=Rhino.DocObjects.RhinoObject.GetDynamicTransform(obj,translation)
        print a    
        
    gp = Rhino.Input.Custom.GetPoint()#creo oggetto gp    
    gp.DynamicDraw += GetPointDynamicDrawFunc  # chiamo in continuazione la funzione che mi mostra la linea dinamica
    gp.Get()   # qui ottengo i dati quando clicco     
    if( gp.CommandResult() == Rhino.Commands.Result.Success ):
        pt = gp.Point() 
        print pt

move_obj()

Ciao Vittorio


(Menno Deij - van Rijswijk) #2

You don’t do any drawing in “GetPointDynamicDrawFunc” you only calculate the translation.

args.Display.DrawObject(...)

#3

Hi Menno

I add a line args.Display.DrawObject(obj) but nothing works.
Can You Help me?

#-*- encoding: utf-8 -*-
#  Rhino Common  Dynamic move object
import System.Drawing.Color
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def move_obj():
    obj=rs.GetObject("select one object")    
    
    obj_color=System.Drawing.Color.Black
    pt_start=rs.GetPoint("Reference point")  # con metodo script     
    #************** funzione che disegna dinamicamente *********************
    
    def GetPointDynamicDrawFunc( sender, args ): 
        vect=args.CurrentPoint-pt_start        
        translation=Rhino.Geometry.Transform.Translation(translation)        
        Rhino.DocObjects.RhinoObject.GetDynamicTransform(obj,translation)        
        args.Display.DrawObject(obj) #What should I put in brackets?
        #args.Display.DrawObject(obj,obj_color) #that does not work 
    gp = Rhino.Input.Custom.GetPoint()#creo oggetto gp    
    gp.DynamicDraw += GetPointDynamicDrawFunc  # chiamo in continuazione la funzione che mi mostra la linea dinamica
    gp.Get()   # qui ottengo i dati quando clicco     
    if( gp.CommandResult() == Rhino.Commands.Result.Success ):
        pt = gp.Point() 
        print pt

move_obj()

(Menno Deij - van Rijswijk) #4

Try this

    def GetPointDynamicDrawFunc( sender, args ): 
        vect=args.CurrentPoint-pt_start        
        translation=Rhino.Geometry.Transform.Translation(vect)        
        args.Display.DrawObject(obj.Geometry, translation)

I created this in C# to test:


protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    ObjRef oRef;
    Result res = RhinoGet.GetOneObject("select one object", false, ObjectType.AnyObject, out oRef);
    if (res != Result.Success) return res;

    RhinoObject obj = oRef.Object();
    GeometryBase geo = obj.Geometry;
    Point3d from;
    res = RhinoGet.GetPoint("select ref point", false, out from);
    if (res != Result.Success) return res;

    GetPoint gp = new GetPoint();
    gp.DynamicDraw += (o, a) =>
                            {
                                Vector3d vect = a.CurrentPoint - from;
                                Transform trans = Transform.Translation(vect);
                                a.Display.DrawObject(obj, trans);
                            };
    GetResult result = gp.Get();
    if (result == GetResult.Point)
    {
        Point3d to = gp.Point();
        geo.Transform(Transform.Translation(to - from));
        doc.Objects.Add(geo);
    }

    return Result.Success;
}


(Gianpaolo Savio) #5
#-*- encoding: utf-8 -*-
#  Rhino Common  Dynamic move object
import System.Drawing.Color
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs


def move_obj():
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select object", True, Rhino.DocObjects.ObjectType.AnyObject)
    if rc!=Rhino.Commands.Result.Success: return
    obj = objref.Object()
    if not obj: return
    rc, pt_start = Rhino.Input.RhinoGet.GetPoint("Start point", False)
    if( rc!=Rhino.Commands.Result.Success ): return 
    def GetPointDynamicDrawFunc( sender, args ): 
        vect=args.CurrentPoint-pt_start        
        translation=Rhino.Geometry.Transform.Translation(vect)          
        args.Display.DrawObject(obj,translation) 
    gp = Rhino.Input.Custom.GetPoint()
    gp.DynamicDraw += GetPointDynamicDrawFunc
    gp.Get()   
    if( gp.CommandResult() == Rhino.Commands.Result.Success ):
        pt = gp.Point() 
        print pt

move_obj()

(Dale Fugier) #6

https://github.com/dalefugier/SamplePy/blob/master/SampleMove.py