sure , here is my script :

Python:

```
import rhinoscriptsyntax as rs
import scriptcontext as sc
import ghpythonlib.components as ghcomp
import random
import math
class optimization:
def __init__(self,_srf):
self.srf = _srf
def boundry(self):
domainU = rs.SurfaceDomain(self.srf,0)
domainV = rs.SurfaceDomain(self.srf,1)
param1 = (domainU[0] , domainV[0])
param2 = (domainU[1] , domainV[1])
isoCrv = rs.ExtractIsoCurve(self.srf , param1 , 2)
for i in range(0,2):
isoCrv.append(rs.ExtractIsoCurve(self.srf , param2 , i))
boundingBoxPts = rs.BoundingBox(self.srf)
corners = [boundingBoxPts[0],boundingBoxPts[1],boundingBoxPts[2],boundingBoxPts[3]]
projectSrf = rs.AddSrfPt(corners)
edge = rs.ProjectCurveToSurface(isoCrv , projectSrf , (0,0,-1))
boundry = rs.JoinCurves(edge , True)
boundrySrf = rs.AddPlanarSrf(boundry)
return (boundrySrf , boundry)
def generateNods(self):
self.planarNods = []
bounds = self.boundry()
boundrySrf = bounds[0]
domainU = rs.SurfaceDomain(boundrySrf, 0)
domainV = rs.SurfaceDomain(boundrySrf, 1)
def remap(value , sourceStart , sourceEnd , targetStart , targetEnd):
newValue = (((value - sourceStart) / (sourceEnd - sourceStart)) * (targetEnd - targetStart)) + targetStart
return newValue
while(len(self.planarNods) < 3):
u = remap(random.uniform(0,1) , 0 , 1 , domainU[0] , domainU[1])
v = remap(random.uniform(0,1) , 0 , 1 , domainV[0] , domainV[1])
nod2D = rs.EvaluateSurface(boundrySrf , u , v)
boolean = rs.IsPointOnSurface(boundrySrf , nod2D)
if(boolean is True):
planarNods.append(nod2D)
self.nonPlanarNods = rs.ProjectPointToSurface(self.planarNods , self.srf , [0,0,1])
nods = (self.nonPlanarNods , self.planarNods)
return nods
def force(self):
distance = []
forces = []
nonPlanarAgents = self.nonPlanarNods
planarAgents = self.planarNods
for i in range(len(planarAgents)):
for j in range(len(planarAgents)):
dist = rs.Distance(planarAgents[i] , planarAgents[j])
distance.append(dist)
sortedDistance = sorted(distance)
smallestDistance = sortedDistance[1]
nearestIndex = distance.index(smallestDistance)
force = rs.VectorCreate(planarAgents[i] , planarAgents[nearestIndex])
forces.append(force)
distance = []
return (planarAgents , forces)
obj = optimization(surface)
b = obj.force()
#o = obj.generateNods()
#c = o[1]
a = b[0]
c = b[1]
```