"""
Script written by <Luis Quinones>
"""
import rhinoscriptsyntax as rs
import math
from System.Drawing import Color
import scriptcontext
def ColorAction(arrVerts,color,pos):
index = rs.PointArrayClosestPoint(arrVerts,pos)
result = color[index]
colorR = rs.ColorRedValue(result)
lum = colorR/255
return lum
def Main():
arrItems = [("Want to use Paint Driver ?",True),("Wanna Pull It to Something",False)]
arrOptionsBln = rs.CheckListBox(arrItems,"CHOOSE","Attraction_Type")
arrItems2 = [("Attraction Threshold",True),("Vector Move Scale Factor",False), ("Paint Affects Both",False)]
arrOptionsBln2 = rs.CheckListBox(arrItems2,"CHOOSE","Paint_Influence")
if not arrOptionsBln2:
print "Options not array"
if not arrOptionsBln:
print "Options not array"
MeshAction = arrOptionsBln[0]
print MeshAction
pullGeom = arrOptionsBln[1]
print pullGeom
AttractorThreshold = arrOptionsBln2[0]
print AttractorThreshold[1]
VectorTranslationScaling = arrOptionsBln2[1]
print VectorTranslationScaling
DoubleActionPaint = arrOptionsBln2[2]
print DoubleActionPaint
Gens = rs.GetInteger("Number of Generations",6,1)
Curves = rs.GetObjects("Select Base Crvs",rs.filter.curve)
Attract = rs.GetReal("CurvePointAttractionThreshold")
dblRatio = rs.GetReal("Distance For Vector To Move")
arrRebuildCount = rs.GetInteger("Curve Rebuild CP Count")
Rebuild = rs.GetInteger("Degree To Rebuild Curves")
strLayerNew = rs.AddLayer("NEWCURVES", Color.Red)
if bool(pullGeom[1]) == True :
srfArr = rs.GetObjects("Meshes to pull to",0)
pullthreshold = rs.GetReal("Set Thresh for mesh attractor")
snapThreshold = rs.GetReal("Set Snap Threshold")
ratio = rs.GetReal("Ratio of Distance to move")
if bool(MeshAction[1]) == True :
strLayer = rs.AddLayer("ptStore", Color.White)
strObject = rs.GetObject("ColorMesh",filter = 32,select = False)
if bool(MeshAction[1]) == True:
arrVerts = rs.MeshVertices(strObject)
color = rs.MeshVertexColors(strObject)
for i in range(Gens):
if scriptcontext.escape_test(False):
print "ESC pressed "
break
rs.EnableRedraw(False)
for j in range(len(Curves)):
if scriptcontext.escape_test(False):
print "ESC pressed "
break
rs.RebuildCurve(Curves[j],Rebuild,arrRebuildCount)
arrNewPos = []
PointCount = rs.CurvePointCount(Curves[j])
arrCrvDiv = rs.CurvePoints(Curves[j])
if arrCrvDiv:
test = "0"
else:
print "Nope"
for k in range(PointCount):
if scriptcontext.escape_test(False):
print "ESC pressed "
break
arrCrvPts = []
if bool(MeshAction[1]) == True:
threshMult = ColorAction(arrVerts,color,arrCrvDiv[k])
if threshMult < 0.2 :
threshMult == 0
else:
threshMult = 1
if bool(VectorTranslationScaling[1]) == True:
#print "only will affect VECTOR"
dblRatio2 = dblRatio*threshMult
print "dblRatio2 = " + str(dblRatio2)
newThreshold = Attract
print "Thresh = " + str(newThreshold)
for L in range(len(Curves)):
if scriptcontext.escape_test(False):
print "ESC pressed "
break
if bool(AttractorThreshold[1]) == True:
newThreshold = Attract * threshMult
dblRatio2 = dblRatio
if bool(DoubleActionPaint[1]) == True:
dblRatio2 = dblRatio*threshMult
newThreshold = Attract * threshMult
print "dblRatio2 = " + str(dblRatio2)
print "Thresh = " + str(newThreshold)
if j != L :
arrCrvParam = rs.CurveClosestPoint(Curves[L],arrCrvDiv[k])
crvPt = rs.EvaluateCurve(Curves[L],arrCrvParam)
arrCrvPts.append(crvPt)
IndClosestCrv = rs.PointArrayClosestPoint(arrCrvPts,arrCrvDiv[k])
#print "NextClosestIndex = ",IndClosestCrv
crvPt = arrCrvPts[IndClosestCrv]
#print crvPt
dist = rs.Distance(arrCrvDiv[k],crvPt)
if dist < newThreshold :
vector = rs.VectorCreate(crvPt,arrCrvDiv[k])
vector = rs.VectorScale(vector,dblRatio2)
NewPosition = rs.PointAdd(vector,arrCrvDiv[k])
else:
NewPosition = arrCrvDiv[k]
arrNewPos.append(NewPosition)
newcurve = rs.AddCurve(arrNewPos,Rebuild)
rs.EnableRedraw(True)
rs.ObjectLayer(newcurve,strLayerNew)
rs.DeleteObject(Curves[j])
#rs.ObjectColor(newcurve,[j,j,j])
Curves[j] = newcurve
basecrvs = rs.ObjectsByLayer(strLayerNew)
rs.EnableRedraw(True)
Main()
Update