How to rotate multiple objects continuously following a circular path?

How to rotate multiple objects continiously which is following a circular path?

Hello everyone, I have no idea about scripting, and I have just searching about what it is. I have a problem for one of my project, I think its a simple thing but after trying a lot I didn’t recieve any successfull solutions.

Hi @Derin_İncekaş, below is an example using RhinoScriptSyntax:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def SamplePolarArray():
    
    obj_ids = rs.GetObjects("Select objects to array", 0, True, False)
    if not obj_ids: return
    
    line_id = rs.GetObject("Select axis line", 4, False, False)
    if not line_id: return
    
    if not rs.IsLine(line_id): return
    
    number_of_items = rs.GetInteger("Number of items", 10, 2)
    if not number_of_items: return
    
    center_point = rs.CurveStartPoint(line_id)
    axis_vector = rs.CurveEndPoint(line_id) - center_point
    
    for angle in rs.frange(0, 360.0, 360.0 / number_of_items): 
        if angle == 0 or angle >= 360: continue
        rs.RotateObjects(obj_ids, center_point, angle, axis_vector, True)

SamplePolarArray()

_
c.

Thank you so much for the answer! However, the thing that I mention about rotating is like continiously without stopping. Like here array gives me this result. How can it be like an animation, those things turning around the circle?

is it possible??

Hi @Derin_İncekaş,

you might post a file with the before and after result what you want to achieve. Do you want ArrayPolar (copy the objects multiple times) or do you want to create a new surface eg. something like Revolve ?

Ps. It is often the best approach to first use regular Rhino commands and then try to script what they do to automate the process.

_
c.

1 Like

For an end product actually, not trying to create new surface or things etc. Exactly like in the gif, from the center point of the circle turning the objects on it like a wheel constantly.

x

I am fascinated to know an eventual answer.
But what would an animation give you that your gif does not?

– cs

I am planning to use it as a representation technique for an end product which is a sci-fi theme :slight_smile:

Would you want to export it as an animation?

No actually, just a screen recording.

Hi,
This is a starting point, instead of using static spheres you may want to make it use your custom selected objects. The path can be any curve.
If you are using Rhino8WIP we can use imageio to take a screenshot of the viewport and generate a gif, otherwise for Rhino7 which doesn’t support Rhinocode you should record your screen using a separate application.

import rhinoscriptsyntax as rs
import Rhino
import math
import time

def create_spheres_on_path():
    spheres = []
    for i in range(0, 200, 50):
        sphere = rs.AddSphere([i, 0, 0], 20)
        spheres.append(sphere)
    return spheres



def move_spheres_along_path(spheres, path, iteration_count, pause_duration=0.01):
    domain = path.Domain
    step_size = (domain[1] - domain[0]) / iteration_count
    for i in range(iteration_count+1):
        t = domain[0] + i * step_size
        point_on_path = path.PointAt(t)
        
        for sphere in spheres:
            rs.MoveObject(sphere, point_on_path - rs.SurfaceAreaCentroid(sphere)[0])
        rs.Redraw()
        time.sleep(pause_duration)
def main():
    spheres = create_spheres_on_path()
    crv = rs.GetObject("Select a path")
    path= rs.coercecurve(crv)
    move_spheres_along_path(spheres, path, iteration_count=500, pause_duration=0.01)

if __name__ == "__main__":
    main()

Wow, thank you so much for the extra info as well. This script is really close to my aim. The only thing is here the spherese are rotating, but I want to choose my objects instead of those spheres.