# Translate script from python to c#

**URL:** <https://discourse.mcneel.com/t/translate-script-from-python-to-c/89649>\
**Category:** Grasshopper\
**Tags:** python\
**Created:** [October 1, 2019, 6:45am UTC](https://discourse.mcneel.com/t/translate-script-from-python-to-c/89649 "2019-10-01T06:45:44Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![flokart](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/flokart/32/765122_2.png) [@flokart](https://discourse.mcneel.com/u/flokart)\
**Post date:** [October 1, 2019, 8:47am UTC](https://discourse.mcneel.com/t/translate-script-from-python-to-c/89649/4 "2019-10-01T08:47:25Z")

</div>

Thanks for the links.

_List of sorted curves?_  
_Sorted how?_

Sorted by intersection.  
First all LineEndPoint Intersection and second all lines with intersection between LineEndPoints.  
The goal is to calculate all weigth points for a booth rig like [Dancergraham](https://discourse.mcneel.com/u/Dancergraham) mentioned in this post [Result forces on a grid](https://discourse.mcneel.com/t/result-forces-on-a-grid/87887/2).

This represents the rig above the booth where all light instalations are fixed.

 ![Capture](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/e/e/ee3ad85dc5eae2bf53e6a94d424937604051f205.png)

This is the code to get the curve order (thats what i try to make in c#)

```python
import Rhino as rh

C = [] # Sorted rig

# Order to calculate 
def calculation_order(x):
    if len(x) >= 0:
        for j in x:
            L = []
            for e in x:
                if e != j:
                    CrvEnd = rh.Geometry.CurveEnd.Both
                    ej = rh.Geometry.Curve.Trim(j,CrvEnd,2)
                    #E.append(ej)
                    L.append(rh.Geometry.Curve.ClosestPoint(ej,e.PointAtStart,1)[0])
                    L.append(rh.Geometry.Curve.ClosestPoint(ej,e.PointAtEnd,1)[0])
                    
            if any(L) == False:
                C.append(j)
                x.remove(j)
                return calculation_order(x)
calculation_order(x)

```

And this is the code to calculate the weight for all endpoints.  
Only the endpoints with a higher count than 1 are calculatet.

```python
import Rhino as rh

L = []
D = {}

for i in C:
    SP,EP = i.PointAtStart,i.PointAtEnd
    L.append(SP)
    L.append(EP)
    D[SP] = []
    D[EP] = []

J = []

for i in range(0,len(C)):
    
    # create Start and Endpoint weights for all rig parts
    SP,EP = C[i].PointAtStart,C[i].PointAtEnd
    weight = (rh.Geometry.Curve.GetLength(C[i])*z)/2
    
    D[SP].append(weight)
    D[EP].append(weight)
    
    
    for j in D:
        if rh.Geometry.Curve.GetLength(C[i]) > rh.Geometry.Curve.ClosestPoint(C[i],j,1)[1] > 0:
            print i
            
            SP_factor = rh.Geometry.Point3d.DistanceTo(SP,j)/rh.Geometry.Curve.GetLength(C[i])
            EP_factor = 1 - SP_factor
            
            SP_weight = sum(D.get(j))*EP_factor
            EP_weight = sum(D.get(j))*SP_factor
            
            D[SP].append(SP_weight)
            D[EP].append(EP_weight)
            
            
            
            sum(D.get(SP))
            sum(D.get(EP))
            
            J.append(j)

D1 = {}
SL = (set(L))-(set(J))

for i in SL:
    if i in D:
        D1[i] = sum(D[i])

Dv = D1.values()
Dk = D1.keys()

```

 ![Capture](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/c/d/cd9a59edce47d7fbf2378ba90848937314895bf9.png)

 ![Capture_01](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/6/3/633c9b66d1a1b44249c7f2a1ae099e63a67c5ea4.png)

I try to make this in c# just for learning purpose and to make fast loading compiled tools for grasshopper

---

_[View the full topic](https://discourse.mcneel.com/t/translate-script-from-python-to-c/89649)._
