I am trying to make a script that allows a user to pick an object to array and the automatically generates the correct amount of objects. I am slowly building this program up so currently it can only work on a 2D plane. It was working fine until I tried to add the possibility of spacing, now it’s giving me issues with a vector 3D. Can any give me insight as to why?
import rhinoscriptsyntax as rs
import math
def getCoords (firstPB, secPB): #this function gets the coordinates and returns the 2 x coordinates and the y cordinate.
x_coords1 =[pt.X for pt in firstPB]
x_coords2 =[pt.X for pt in secPB]
for pnt in x_coords1:
xcord1 = pnt
for pnt in x_coords2:
xcord2 = pnt
y_coords=[pt.Y for pt in firstPB]
for pnt in y_coords:
ycord = pnt
return xcord1, xcord2, ycord
def getDistance(xcord1, xcord2, ycord): #this function gets the distance between two points by taking the coords gotten from the prvious function
distance = math.sqrt(((xcord1- xcord2)*(xcord1- xcord2))) #this will always be positive
return distance
#end function return distance
def frange(start, stop=None, step=None):
#Use float number in range() function
# if stop and step argument is null set start=0.0 and step = 1.0
if stop == None:
stop = start + 0.0
start = 0.0
if step == None:
step = 1.0
while True:
if step > 0 and start >= stop:
break
elif step < 0 and start <= stop:
break
yield ("%g" % start) # return float number
start = start + step
firstPB = rs.GetPointCoordinates(“Please select the first point of the big surface”)
secPB = rs.GetPointCoordinates(“Please select the second point of the big surface”)
firstPS = rs.GetPointCoordinates(“Please select the first point of the small surface”)
secPS = rs.GetPointCoordinates(“Please select the second point of the small surface”)
#adding spacing
space = rs.GetReal("Please enter the amount of space between each object ")
startCord, endCord, yCord = getCoords(firstPB, secPB)
smallStart, smallEnd, y = getCoords(firstPS, secPS)
lengthBig = getDistance(startCord, endCord, yCord)
smallLength = getDistance(smallStart, smallEnd, y)
startDistance = secPS #start by the end of the second point of the smaller object
amnt = math.floor(lengthBig/smallLength) #this ensures there arnet too many
obj = rs.GetObject(“Select object to array.”)
for count in frange(amnt):
xform = rs.XformTranslation([startDistance,yCord,0]) #y,x,z
arrayObj = rs.CopyObject(obj)
if arrayObj: rs.TransformObject(arrayObj, xform)
newX = startDistance[0] + space
startDistance = [newX, yCord, 0]
#startDistance = smallLength + space #issue, trying to add .5 to a coordinate, cant just dump it on the number