def displayPolyline(poly): # 根据对象实例, 在gh中绘制polyline, rectangle继承polyline if not isinstance(poly, Polyline): return start_pt_x, start_pt_y = poly.start_pt.x, poly.start_pt.y vec_lst = poly.vec_lst[:] pt = rs.CreatePoint(start_pt_x, start_pt_y) pt_lst = [pt] for vec in vec_lst: start_pt_x += vec.x; start_pt_y += vec.y pt = rs.CreatePoint(start_pt_x, start_pt_y) pt_lst.append(pt) poly = rs.AddPolyline(pt_lst) return poly
def displaypolyveclength(polyline): #根据一个多段线,输出gh中点的列表和向量的列表,和需要表现得长度得txt与点 corner_list = [] #角点列表 vector_list = [] #向量列表 txt_length = [] #长度txt列表 median_point = [] #文字标记点得列表 for i in range(0,len(polyline.vec_lst)): temp_point = polyline.pt_lst[i] temp_vec = polyline.vec_lst[i] corner_list.append(rs.CreatePoint(temp_point.x,temp_point.y,0)) vector_list.append(rs.CreateVector(temp_vec.x,temp_vec.y,0)) txt_length.append(str(temp_vec.getLength())) median_point.append(rs.CreatePoint(temp_point.x+temp_vec.x/2,temp_point.y+temp_vec.y/2,0)) return corner_list,vector_list,txt_length,median_point
def GeneratePoints(mesh_faces, random_coordinates): #create a list to hold the points generated pointcloud = [] #extract the value of each vertexs coordinate for mesh_face in mesh_faces: #get the vertices of the triangular face vertex_a = mesh_face[0] vertex_b = mesh_face[1] vertex_c = mesh_face[2] #for each random coordinate in the list of random coordinates for random_coordinate in random_coordinates: #calculate the 3d point equivalent to the random normalized coordinate #determine the r1 and r2 values (should be equal to 2 of (s,r,t)) r1 = random_coordinate.Y r2 = random_coordinate.Z #calculate the 3d cartesian equivalent point_x = (1 - math.sqrt(r1)) * vertex_a.X + math.sqrt(r1) * ( 1 - r2) * vertex_b.X + math.sqrt(r1) * r2 * vertex_c.X point_y = (1 - math.sqrt(r1)) * vertex_a.Y + math.sqrt(r1) * ( 1 - r2) * vertex_b.Y + math.sqrt(r1) * r2 * vertex_c.Y point_z = (1 - math.sqrt(r1)) * vertex_a.Z + math.sqrt(r1) * ( 1 - r2) * vertex_b.Z + math.sqrt(r1) * r2 * vertex_c.Z #create a new point to hold the 3d point equivalent point = rs.CreatePoint(point_x, point_y, point_z) #add that point to the point cloud (CHECK IF THE POINT EXISTS ON THE SURFACE OF THE MESHFACE) pointcloud.append(point) #return the pointcloud as a list of pointcloud lists if (len(pointcloud) == len(mesh_faces) * len(random_coordinates)): #return the pointcloud (list of points) return pointcloud else: #return false to indicate an error return False
def setObjZPair(obj): if rs.IsBlockInstance(obj): # pt = rs.CreatePoint(obj) return [obj, round(objBBPts(obj)[0].Z, 3)] elif rs.IsCurve(obj): return crvPtZpair(obj) elif rs.IsPolysurfaceClosed(obj): return brepPtZPair(obj) elif rs.IsSurface(obj): return srfPtZPair(obj) elif rs.IsPoint(obj): pt = rs.CreatePoint(obj) return [obj, round(pt.Z, 3)] # elif rs.IsBlockInstance(obj): # # pt = rs.CreatePoint(obj) # return [obj, round(objBBPts(obj)[0].Z, 3)] else: pass
def get_distance(self,x,y,z): p = rs.CreatePoint(x,y,z) param=rs.CurveClosestPoint(self.c, p) cp=rs.EvaluateCurve(self.c,param) dv = map_values(param,self.c.Domain[0],self.c.Domain[1],0,1) r = (1-dv)*self.r1 + dv*self.r2 d = rs.Distance(p,cp) - r return d
def makeFirstLevel(_num): for x in range(_num): for y in range(_num): if random.random() > 0.1: newPt = rs.CreatePoint((x, y, 0)) rs.AddSphere(newPt, 1.0) pts.append(newPt) return pts
def firstLine(quantity): myPoints = [] for x in range(quantity): myTempPoint = rs.CreatePoint( (x * quantity, 0, quantity * random.random())) myPoints.append(myTempPoint) return myPoints
def makeLevels(_points, _z, _num, _probability): levels = _z for point in _points: for x in range(_num): for y in range(_num): currentPt = rs.CreatePoint((x, y, 0)) if point == currentPt: if random.random() > _probability: newPt = rs.CreatePoint((x, y, _z)) rs.AddSphere(newPt, 1.0) else: pts.remove(point) levels = levels + 1 _probability = _probability + 0.2 if levels < 5: makeLevels(lv1, levels, 10, _probability) else: return False
def setObjZPair(obj): if rs.IsCurve(obj): return crvPtZpair(obj) elif rs.IsSurface(obj): return srfPtZPair(obj) elif rs.IsPoint(obj): pt = rs.CreatePoint(obj) return [obj, round(pt.Z, 3)] else: pass
def __init__(self, PQ, user): self.id = 'P{0:05}'.format(PQ) self.activity = user.nextactivity self.color = ACTIVITIES_COLORS[self.activity] self.user = user.nr self.nextlocation = user.nextlocation self.departed = False self.todiscard = False x = random.randint(0, boxSIZE) y = random.randint(0, boxSIZE) height = boxSIZE * 2 self.coordinates = rs.CreatePoint(x, y, height)
def followingLines(currentLine, quantity, y, count): myPoints = [] for point in currentLine: print point.X myTempPoint = rs.CreatePoint( (point.X, count * quantity, point.Z + random.random() * 2)) myPoints.append(myTempPoint) for point in myPoints: rs.AddSphere(point, quantity) count = count + 1 if (count < target): followingLines(myPoints, quantity, count, count)
def moveToOrigin(input): x = [] y = [] z = [] for i in input: x.append(i.X) y.append(i.Y) z.append(i.Z) output = [] for i in input: output.append(rs.CreatePoint(i.X - min(x), i.Y - min(y), i.Z - min(z))) return (output)
def FindCentroidOfPoints(ids): if not ids: return # first point pt_sum = rs.PointCoordinates(rs.CreatePoint(ids[0])) # sum rest of points for i in xrange(1, len(ids)): pt_sum += rs.PointCoordinates(ids[i]) # divide with amount of points to get average pt_sum = pt_sum / len(ids) return pt_sum
def add_attr_bld(): # set current working dir os.chdir(working_dir_path) # Add attributes to plots with open(proc_attributes_path, "r") as input_handle: rdr = csv.reader(input_handle) # read attribure labels (first row) attribute_labels_list = next(rdr) # get x, y, z attributes indices x_idx, y_idx, z_idx = attribute_labels_list.index( "Position X"), attribute_labels_list.index( "Position Y"), attribute_labels_list.index("Position Z") # get all objects in plots layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) for attributes_row in rdr: x_val, y_val, z_val = float(attributes_row[x_idx]), float( attributes_row[y_idx]), float(attributes_row[z_idx]) related_building_pnt = rs.CreatePoint(x_val, y_val, z_val) for building_obj in building_objs: if rs.IsCurve(building_obj) and rs.IsCurveClosed(building_obj): crv = rs.coercecurve(building_obj) if rs.PointInPlanarClosedCurve(related_building_pnt, crv): for attr_label, attr_val in zip( attribute_labels_list, attributes_row): # if NUM_APTS_C already set, add to it num_of_apts_label = "NUM_APTS_C" if attr_label == num_of_apts_label: num_of_apts_val = rs.GetUserText( building_obj, num_of_apts_label) if num_of_apts_val != None: attr_val = int(attr_val) attr_val += int(num_of_apts_val) rs.SetUserText(building_obj, attr_label, attr_val)
def process(objs, grade, func): isUG = trp.boolToggle(grade) groups = trp.groupByElevation(objs, isUG) trp.setLevel(groups, isUG, func) """setting lvldbdict as ordered for some reason """ levels = [trp.createObjDict(x[0][0]) for x in groups] lvlk = [x['level'] for x in levels] lvldict = dict(zip(lvlk, levels)) lvlpt = [rs.CreatePoint((0, 0, float(x['elevation']))) for x in levels] lvlptdict = dict(zip(lvlk, lvlpt)) # pts = [" ".join(map(str,[0,0,float(x['elevation'])]))] # lvlptdict sc.sticky['lvlptdict'] = lvlptdict sc.sticky["lvldict"] = lvldict sc.sticky["levels"] = json.dumps(levels) rs.SetDocumentUserText("lvldict", json.dumps(lvldict)) rs.SetDocumentUserText("levels", json.dumps(levels))
def DomeAxisOrigo(treeIn, treeOut, axisIn, origoIn): for i in range(treeIn.BranchCount): treeBranch = treeIn.Branch(i) treePath = treeIn.Path(i) for j in range(treeBranch.Count): elem = treeBranch[j] x = elem.X y = elem.Y z = elem.Z if axisIn == 0: x2 = z y2 = x z2 = y elif axisIn == 1: x2 = y y2 = z z2 = x else: x2 = x y2 = y z2 = z origoIn = rs.coerce3dpoint(origoIn) Ox = origoIn.X Oy = origoIn.Y Oz = origoIn.Z x3 = x2 + Ox y3 = y2 + Oy z3 = z2 + Oz ujelem = rs.CreatePoint(x3, y3, z3) treeOut.Add(ujelem, treePath)
def GenerateCoordinate(coordinate_count): #list to hold the random points generated random_coordinates = [] random_coordinate = [] random_normal_coordinate = [] #generate 3 random values from 0 - 1 for i in range(coordinate_count): r = random.uniform(0, 1) random_coordinate.append(r) #if the correct amount of ordinates have been generated if (len(random_coordinate) == coordinate_count): #calculate the sum of the random_coordinate s = sum(random_coordinate) for coordinate in random_coordinate: #normalize the coordinate value by dividing by the sum normalized = coordinate / s random_normal_coordinate.append(normalized) #if the length of the normal coordinate list is full if (len(random_normal_coordinate) == coordinate_count): #create a point object from the normalized random coordinate normal_point = rs.CreatePoint(random_normal_coordinate[0], random_normal_coordinate[1], random_normal_coordinate[2]) return normal_point
return int(100 * (i.X**2 + i.Y**2 + i.Z**2)**0.5) def sortPoints(listInput): listOutput = [] for input in listInput: dist = [] listOutput.append(sorted(input, key=dist_from_origin)) return listOutput def comparePoints(input1, input2): similar = True zeroPoint = rs.CreatePoint(0, 0, 0) rotationAxis = rs.CreateVector(0, 0, 1) import math def rotate(input): result = [] for ii in [0, 90, 180, 270]: list = [] for i in input: v = rs.CreateVector(i) v.Rotate(math.radians(int(ii)), rotationAxis) list.append(v) result.append(list) return result
#some vector math stuff with user prompts #vector add + sub + dot + cross #command line prompts, message box, listbox import rhinoscriptsyntax as rs #create and origin point, the default is 0, 0, 0 origin = rs.GetPoint("Select Origin", (0, 0, 0)) #if we don't get an origin for some reason, make it 0, 0, 0 if origin == None: origin = rs.CreatePoint(0, 0, 0) originPt = rs.AddPoint(origin) #prompt user for a first point pt1 = rs.GetPoint("Pick First Point", origin) rs.AddPoint(pt1) #create a vector between the origin and the point, represent this with a colored line vector1 = rs.VectorCreate(pt1, origin) rs.ObjectColor(rs.AddLine(origin, pt1), (255, 0, 0)) #prompt the user for a second point pt2 = rs.GetPoint("Pick a second point", origin) rs.AddPoint(pt2) #create a vector between the origin and the point, represent this with another colorerd line vector2 = rs.VectorCreate(pt2, origin) rs.ObjectColor(rs.AddLine(origin, pt2), (0, 0, 255)) #create some options for Vector operations and prompt user for input with List of options options = ("Vector Addition", "Vector Subtraction", "Vector Dot Product", "Vector Cross Product")
PODS_Occupancy_inTIME = [] PATHS_inTIME = [] avrageCOMMUTEdistance_inTIME = [] avrageCOMMUTEtime_inTIME = [] users_ACTIVITIES_inTIME = [] TEXT_coordinate_inTIME = [] TEXT_inTIME = [] # to delete! PRINT_LOG_inTIME = [] PRINT_LOG = [str(), str(), str(), str(), str()] TIME = [] iNR = 0 Vzero = rs.CreateVector(0, 0, 0) Pzero = rs.CreatePoint(0, 0, 0) hbS = boxSIZE / 2 # half of box size pheryphery_border1 = squeezing_area * hbS pheryphery_border2 = boxSIZE - pheryphery_border1 squeezing_multiplier = squeezingPOWER / (pheryphery_border1)**2 maxHALOsize = BUILDINGS_Halo maxflow = 0 def IDcomponent(cooridante): id_component, distance = divmod(cooridante, module) id_component = int(id_component) id_component = min(id_component, partitions - 1) id_component = max(id_component, 0) return id_component
__author__ = "tanya" __version__ = "2021.03.17" import rhinoscriptsyntax as rs import Rhino as rh import scriptcontext as sc sc.doc = rh.RhinoDoc.ActiveDoc all_objs = rs.AllObjects() #obj_crv = rs.coercecurve(all_objs[0]) #print(obj_crv) #pnt = rs.CreatePoint(float(-22), float(-1), float(0)) pnt = rs.CreatePoint(float(42), float(-3), float(0)) counter = 0 for obj in all_objs: crv = rs.coercecurve(obj) in_curve = rs.PointInPlanarClosedCurve(pnt, crv) counter += 1 if (in_curve): print(counter, "Tada") points = rs.PolylineVertices(curve) pnt = rs.CreatePoint(float(235), float(240), float(0)) rs.SetUserText(curve, "PartNo", "KM40-4960")
op = lambda x, y: x * y + y + 1 ''' Center of form ''' pcenter = .5 * p1 + .5 * p2 ''' Square of radius ''' rad2 = rad * rad ''' create list of points ''' pt = [] dx = (p2.X - p1.X) / (rx - 1) ry = int(0.5 + (p2.Y - p1.Y) / dx) for i in range(0, ry + 1): for j in range(0, rx): x = p1.X + j * dx y = p1.Y + i * dx if op(i, j) % mod == 0: p = rs.CreatePoint(x, y, 0.0) d = dist2(p, pcenter) if d < rad2: z = 0.02 * d pt.append(rs.CreatePoint(x, y, z)) a = pt ''' create list of lines ''' ln = [] d2 = dist * dist for j in range(0, len(pt)): for i in range(0, len(pt)): if i != j and dist2(pt[i], pt[j]) < d2: ln.append(rs.AddLine(pt[i], pt[j])) b = ln
def get_distance(self, x, y, z): p = rs.CreatePoint(x, y, z) param = rs.SurfaceClosestPoint(self.s, p) cp = rs.EvaluateSurface(self.s, param[0], param[1]) d = rs.Distance(p, cp) - self.t / 2.0 return d
relevant_layers_dict = {"buildings": "2200", "plots": "chelkot lines"} rs.CurrentLayer(relevant_layers_dict["buildings"]) # remove all redundant layers for layer_name in rs.LayerNames(): if layer_name not in relevant_layers_dict.values: rs.PurgeLayer(layer_name) # get all objects in building layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) #obj_crv = rs.coercecurve(all_objs[0]) #print(obj_crv) #pnt = rs.CreatePoint(float(-22), float(-1), float(0)) pnt = rs.CreatePoint(float(0), float(0), float(0)) counter = 0 for obj in building_objs: crv = rs.coercecurve(obj) in_curve = rs.PointInPlanarClosedCurve(pnt, crv) counter += 1 if (in_curve): print(counter, "Tada") rs.SetUserText(obj, "PartNo12", "3") print(rs.GetUserText(obj, "PartNo14")) print(counter, crv)
import Rhino.Geometry as rg from compas_vol.primitives import VolSphere, VolBox from compas_vol.combinations import Union,Subtraction from compas.geometry import Sphere, Box, Frame from compas.rpc import Proxy s = VolSphere(Sphere((0, 0, 0), 6)) b = VolBox(Box(Frame.worldXY(), 10, 10, 10), 1.5) u = Union(s, b) t = Subtraction(b, s) p = Proxy('compas_vol.utilities') #p.stop_server() #p = Proxy('compas_vol.utilities') bounds = ((-25,25,100), (-25,25,100), (-25,25,100)) vs,fs = p.get_vfs_from_tree(str(t), bounds, 1.0) mesh = rg.Mesh() for v1, v2, v3 in vs: mesh.Vertices.Add(v1, v2, v3) for f in fs: if len(set(f))>2: mesh.Faces.AddFace(f[0], f[1], f[2]) mesh.Compact() mesh.Normals.ComputeNormals() a = mesh b = [rs.CreatePoint(v1,v2,v3) for v1, v2, v3 in vs]
def objPtPair(obj): return obj, rs.CreatePoint(obj)
x_idx, y_idx, z_idx = attribute_labels_list.index( "Position X"), attribute_labels_list.index( "Position Y"), attribute_labels_list.index("Position Z") # get all objects in building layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) out_loop_counter = 0 xy_found = 0 for attributes_row in rdr: out_loop_counter += 1 x_val, y_val, z_val = float(attributes_row[x_idx]), float( attributes_row[y_idx]), float(attributes_row[z_idx]) related_building_pnt = rs.CreatePoint(x_val, y_val, z_val) xy_found = False in_loop_counter = 0 for building_obj in building_objs: in_loop_counter += 1 if rs.IsCurve(building_obj) and rs.IsCurveClosed( building_obj) and (rs.CurveArea(building_obj)[0] > MIN_BUILDING_AREA_SQM): crv = rs.coercecurve(building_obj) if rs.PointInPlanarClosedCurve(related_building_pnt, crv): xy_found = True for attr_label, attr_val in zip(attribute_labels_list, attributes_row): rs.SetUserText(building_obj, attr_label, attr_val) if not xy_found:
centroid.Y = Y_mean print('Iteration {}'.format(iteration + 1)) Centroid_X_values = [] Centroid_Y_values = [] for centroidPoint in centroidPoints: Centroid_X_values.append(centroidPoint.X) Centroid_Y_values.append(centroidPoint.Y) return (Centroid_X_values, Centroid_Y_values) # Final loop pointXs = [] pointYs = [] outputPoints = [] for point in PointsRaw: px, py = DeconstructPoint(point) pointXs.append(px) pointYs.append(py) CXs, CYs = K_means(NumberOfsubdivisionClasses, pointXs, pointYs, iterationNumber) for i in range(len(CXs)): point = rs.CreatePoint(CXs[i], CYs[i], 0) outputPoints.append(point) a = outputPoints
def center_point(self): cps = [ ghc.Area(tfa_srfc).centroid for tfa_srfc in self.space_tfa_surfaces ] cp = ghc.Average(cps) return rs.CreatePoint(*cp)
for jj in range(3): while counter2[ii][jj] < len(AllIntCoord[ii][jj]) - 1: if AllIntCoord[ii][jj][counter2[ii][jj]] == AllIntCoord[ii][jj][ counter2[ii][jj] + 1]: del AllIntCoord[ii][jj][counter2[ii][jj]] else: counter2[ii][jj] = counter2[ii][jj] + 1 # Create the matrix with all the points for ii in range(N_blocks): for zz in range(len(AllIntCoord[ii][2])): for yy in range(len(AllIntCoord[ii][1])): for xx in range(len(AllIntCoord[ii][0])): AllIntPts[ii].append( rs.CreatePoint(AllIntCoord[ii][0][xx], AllIntCoord[ii][1][yy], AllIntCoord[ii][2][zz])) AllIntPts[ii] = rs.SortPoints(AllIntPts[ii], order=5) # respectively z,y,x # Sort all IntPoints indexes for ii in range(N_blocks): N_subBlock[ii] = (len(AllIntCoord[ii][0]) - 1) * ( len(AllIntCoord[ii][1]) - 1) * (len(AllIntCoord[ii][2]) - 1) for jj in range(N_subBlock[ii]): if jj == 0: IndOpenSees[ii][0][jj] = [ len(AllIntCoord[ii][0]), 0, 1, len(AllIntCoord[ii][0]) + 1 ] IndOpenSees[ii][1][jj] = [ len(AllIntCoord[ii][0]) * len(AllIntCoord[ii][1]) +