Please convert Python script to C# script

I left a message to ask you a favor.

Grasshopper uses Python to work, and to reduce operating time, it wants to convert Python scripts into C# scripts.

If you don’t mind, can I ask for your code?

I will study hard with the content you answered.
Thank you.

import Rhino.Geometry as rh

tolerance = 0.001

count = 0

while count < 100:
    count += 1
    found = 0
    for i, r1 in enumerate(regions):
        for j, r2 in enumerate(regions):
            if r1 == r2:
            int = rh.Curve.CreateBooleanIntersection(r1, r2, tolerance)
            # intersection found
            if len(int) > 0:
                # move
                p1 = rh.Point3d(x[i], y[i], 0)
                p2 = rh.Point3d(x[j], y[j], 0)
                vec = rh.Vector3d(p1) - rh.Vector3d(p2)
                vec *= d
                x[i] += vec.X
                y[i] += vec.Y
                found += 1
    if found == 0:

print "Executed {} cycles".format(count)

Hi @yongg0323,

Can you post a simple GH file that contains the use of this code?

– Dale (7.7 KB)

Thank you for your interest.
I have attached the file.

if it is just for circles you could speed it up a lot by using the radius to see if they collide instead of create a BooleanIntersection.

1 Like

Hi @yongg0323,

See the attached. Note, I made no optimizations - I’ll leave that to you. (14.9 KB)

– Dale


Thank you for your answer. There was no significant difference in the speed of work when using the same logic using Python and C#.

Thank you. It will be a good learning material.

I’m still not good at it, so I’ll study later and try it.

1 Like