def checkContainment(self,a,b,c): t1=rs.PointInPlanarClosedCurve(a,self.crv) t2=rs.PointInPlanarClosedCurve(b,self.crv) t3=rs.PointInPlanarClosedCurve(c,self.crv) if(t1!=0 and t2!=0 and t3!=0): return True else: return False
def get_dist(pt,poly): # find closest point on axis curve param = rs.CurveClosestPoint(axis, pt) # get plane perpendicular to curve ck,pl = axis.PerpendicularFrameAt(param) # part responsible for flat end caps # if distance from point to plane is bigger than 0, # return that distance pp = rs.PlaneClosestPoint(pl,pt) d2 = rs.Distance(pt,pp) if d2>0.01: return d2 # else change the basis of the polygon from world xy # to that plane to check for distance and inside/outside pm = (param-axis.Domain[0])/(axis.Domain[1]-axis.Domain[0]) wxy = rs.WorldXYPlane() tf = rg.Transform.PlaneToPlane(wxy,pl) ang = sa + pm*(ea-sa) tr = rg.Transform.Rotation(ang, pl.Normal, pl.Origin) tpts = rs.CurvePoints(poly) for p in tpts: p.Transform(tf) p.Transform(tr) ply = rs.AddPolyline(tpts) prm = rs.CurveClosestPoint(ply,pt) cp = rs.EvaluateCurve(ply,prm) d = rs.Distance(pt,cp) # if the point is inside the curve, reverse the distance bln = rs.PointInPlanarClosedCurve(pt,ply,pl) if bln: d *= -1 return d
def find_point(point, zones): for zone in zones: result = rs.PointInPlanarClosedCurve(point, zone.curve) if result == 1: print "Point in zone '{}'".format(zone.name) else: print "Point not in zone '{}'".format(zone.name)
def checkPoly(self, pts, poly): sum = 0 for i in pts: m = rs.PointInPlanarClosedCurve(i, poly) if (m != 0): sum += 1 poly2 = rs.AddPolyline(pts) pts2 = rs.CurvePoints(poly) for i in pts2: m = rs.PointInPlanarClosedCurve(i, poly2) if (m != 0): sum += 1 rs.DeleteObject(poly2) if (sum > 0): return False else: return True
def groupByBB(objs): pairs = map(objBBPtPair, objs) for bb in groupbb: lvl = rs.GetUserText(bb, 'level') for pair in pairs: result = rs.PointInPlanarClosedCurve(pair[1], bb) if result == 1: rs.SetUserText(pair[0], "level", lvl)
def get_cut_curve(self): if self.compensation == 0: return rs.CopyObject(self.nurbs_curve) offset_distance = self.general_input["cut_diam"] * 0.5 scl_obj = rs.ScaleObject(self.nurbs_curve, self.point, (1.2, 1.2, 1), True) offset_points = rs.BoundingBox(scl_obj) rs.DeleteObject(scl_obj) offset_point_a = offset_points[0] offset_point_b = self.point if not rs.PointInPlanarClosedCurve(self.point, self.nurbs_curve): offset_point_b = self.find_point_in_curve(self.nurbs_curve) offset_a = rs.OffsetCurve(self.nurbs_curve, offset_point_a, offset_distance, None, 2) offset_b = rs.OffsetCurve(self.nurbs_curve, offset_point_b, offset_distance, None, 2) #Revisa si el offset no genero curvas separadas y si es el caso asigna la curva original como offset comparativo if not offset_a or len(offset_a) != 1: self.log.append( "offset error: el cortador no cabe en una de las curvas, se reemplazo con la curva original." ) if offset_a: rs.DeleteObjects(offset_a) offset_a = rs.CopyObject(self.nurbs_curve) if not offset_b or len(offset_b) != 1: self.log.append( "offset error: el cortador no cabe en una de las curvas, se reemplazo con la curva original." ) if offset_b: rs.DeleteObjects(offset_b) offset_b = rs.CopyObject(self.nurbs_curve) #Revisa el area para saber cual es el offset interno o externo if rs.CurveArea(offset_a) < rs.CurveArea(offset_b): in_offset = offset_a out_offset = offset_b else: in_offset = offset_b out_offset = offset_a #Responde dependiendo que compensacion se necesita if self.compensation == 1: rs.DeleteObject(in_offset) return out_offset elif self.compensation == -1: rs.DeleteObject(out_offset) return in_offset else: rs.DeleteObject(in_offset) rs.DeleteObject(out_offset) return None
def find_point_in_curve(self, crv): offset_points = rs.BoundingBox(crv) diagonal = rs.AddLine(offset_points[0], offset_points[2]) test_points = rs.DivideCurveLength(diagonal, POINT_TOL, create_points=False, return_points=True) rs.DeleteObject(diagonal) for point in test_points: if rs.PointInPlanarClosedCurve(point, crv): return point return self.point
def removePoly(bsp_tree, int_crv): del_crv = [] used_crv = [] for crv in bsp_tree: try: cen = rs.CurveAreaCentroid(crv)[0] if (rs.PointInPlanarClosedCurve(cen, int_crv) == 1): del_crv.append(crv) except: print("error") for crv in del_crv: bsp_tree.remove(crv) rs.DeleteObject(crv) return bsp_tree
def getpoints4lot(self,lots_,cpt_,value_ref_,actual_value_ref_): ## Loop through tree lots and add the point_nodes ## to each lot; returns lst of (listof points inside each lot) ## bpt_lst,lots: listof(listof(point data) debug = sc.sticky['debug'] lst_bpt_lst_ = [] lst_val_lst_ = [] lst_val_lst_actual_ = [] for j,lot in enumerate(lots_): boundary = lot.shape.bottom_crv neighbor = [] neighbor_val= [] neighbor_val_actual = [] # look through all cpts from dpts and add to neighborlst for i,cp in enumerate(cpt_): movedist = abs(lot.shape.cpt[2]-cp[2]) if abs(movedist-0.0)>0.1: if lot.shape.cpt[2] < cp[2]: movedist *= -1 vec = rc.Geometry.Vector3d(0,0,movedist) else: vec = rc.Geometry.Vector3d(0,0,0) if not lot.shape.is_guid(cp): cp = sc.doc.Objects.AddPoint(cp) copy_cp = rs.CopyObject(cp,vec) #copy_cp = rs.coerce3dpoint() #copy_cp = cp in_lot = 0 try: in_lot = int(rs.PointInPlanarClosedCurve(copy_cp,boundary,lot.shape.cplane)) except: pass #0 = point is outside of the curve #1 = point is inside of the curve #2 = point in on the curve if abs(float(in_lot) - 1.) <= 0.1: cp = rs.coerce3dpoint(cp) neighbor.append(cp)#,datalst[i]]) neighbor_val.append(value_ref_[i]) neighbor_val_actual.append(actual_value_ref_[i]) #d = rs.AddPoint(copy_cp[0], copy_cp[1],0) #debug.append(d) lst_bpt_lst_.append(neighbor) lst_val_lst_.append(neighbor_val) lst_val_lst_actual_.append(neighbor_val_actual) return lst_bpt_lst_,lst_val_lst_,lst_val_lst_actual_
def __init__(self, O): self.site = O self.add_pts = [] self.pts = rs.DivideCurve(O, 100) b = rs.BoundingBox(self.site) poly = rs.AddPolyline([b[0], b[1], b[2], b[3], b[0]]) div = 10 u = int((b[1][0] - b[0][0]) / div) v = int((b[2][1] - b[1][1]) / div) for i in range(int(b[0][0]), int(b[1][0]), u): for j in range(int(b[1][1]), int(b[2][1]), v): p = [i, j, 0] if (rs.PointInPlanarClosedCurve(p, self.site) != 0): #self.add_pts.append(p) self.pts.append(p) rs.DeleteObject(poly)
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 asign_clusters(self): geometry = [] for e,i in self.spkmodel_objects.iteritems(): if e != "curves_outside": for rh_object in i: geometry.append(rh_object) try: if self.spkmodel_objects["curves_outside"]: count = 0 for curve in self.spkmodel_objects["curves_outside"]: for point in geometry: if point.asignedcluster == -1: if rs.PointInPlanarClosedCurve(point.point,curve.curve): point.asignedcluster = count curve.asignedcluster = count curve.iscluster = True else: pass count += 1 except: pass
def add_attr_plt(): # get objects by layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) plot_objs = rs.ObjectsByLayer(relevant_layers_dict["plots"]) # read attribure labels (first row) attribute_labels_list = [] with open(proc_attributes_path, "r") as input_handle: rdr = csv.reader(input_handle) attribute_labels_list = next(rdr) for building_obj in building_objs: if rs.IsCurve(building_obj) and rs.IsCurveClosed(building_obj): crv = rs.coercecurve(building_obj) #building_center_pt = rs.CurveAreaCentroid(building_obj)[0] building_center_pt = crv.GetBoundingBox(True).Center for plot_obj in plot_objs: if rs.PointInPlanarClosedCurve(building_center_pt, plot_obj): for attr_label in set(attribute_labels_list).intersection( plot_attribs_list): #todo: intersection redundant # get building attribute plot_attr_val = int( rs.GetUserText(building_obj, attr_label)) # 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( plot_obj, num_of_apts_label) if num_of_apts_val != None: plot_attr_val += int(num_of_apts_val) rs.SetUserText(plot_obj, attr_label, plot_attr_val)
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: rs.SelectObject(building_obj) print(x_val, y_val, z_val) print(out_loop_counter) ########################################################################################################################################## # Extrude all buildings according to NUM_FLOORS attribute multiplied by FLOOR_HEIGHT constant # get all objects in building layer building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"]) for building_obj in building_objs: if rs.IsCurve(building_obj) and rs.IsCurveClosed(
def warp(self, crv): if rs.PointInPlanarClosedCurve(self.loc, crv) == 0: self.vel = PVector(-self.vel.X, -self.vel.Y, self.vel.Z)
oricharge = orichargeinput[i] affrange = affrangeinput[i] eddyconfig.append(Eddy_config(loc, gravity, oricharge, affrange, i)) eddycollection.append(Eddy(eddyconfig[i])) #generate flow particles crv = sc.doc.Objects.AddCurve(sitecrv) j = -1 for i in xrange(n_flow): u = random.uniform(0.0, 1.0) v = random.uniform(0.0, 1.0) a = sitesrf.PointAt(u, v) vel = PVector(random.uniform(0.0, 1.0), random.uniform(0.0, 1.0), 0) particle = PVector(a.X, a.Y, a.Z) if rs.PointInPlanarClosedCurve(a, crv) == 0: pass else: flowconfig.append( Flow_config(particle, PVector(0, 0, 0), PVector(0, 0, 0))) for config in flowconfig: flowcollection.append(Flow(config)) #=================================# #Draw #=================================# for i in xrange(100): for particle in flowcollection: particle.run(eddycollection, crv) for particle in flowcollection:
for i in range(listLen): area = floorNum*floorArea[i] buildingTotalArea.append(area) mmdList = [] for i in range(len(buildingTotalArea)): ### very ugly code plot_objs = rs.ObjectsByLayer("H0010A") building_center_pt = ghdoc.Objects.FindGeometry(buildings[0]).GetBoundingBox(True).Center for plot_obj in plot_objs: if rs.PointInPlanarClosedCurve(building_center_pt, plot_obj): oldUnitsNum[i] = int(rs.GetUserText(plot_obj, "NUM_APTS_C")) ### very ugly code mmd = oldUnitsNum[i]*12 mmdList.append(mmd) net = int(buildingTotalArea[i])-(floorNum*core)-mmdList[i] netAreas.append(net) for i in range(listLen): num = netAreas[i]/unitAverageSize newUnitsNum.append(int(num)) ##############################################################################
def Main(): input_curves = rs.GetObjects("Curves", rs.filter.curve, True, True) input_points = rs.GetObjects("Points for dogboone placement", rs.filter.point) if not input_curves or not input_points: return #Reads, asks and writes settings to document data_name = "dogbone2" values = rs.GetDocumentData(data_name, "settings") values = json.loads(values)["data"] if values else [ "35.0", "15.0", "9.525", "1" ] settings = ["Length:", "With:", "Diameter:", "Tolerance Offset:"] length, width, diam, aperture = [ float(i.replace(" ", "")) for i in rs.PropertyListBox( settings, values, "DogBone by dfmd", "Settings:") ] rs.SetDocumentData(data_name, "settings", json.dumps({"data": [length, width, diam, aperture]})) sorted_points = [] clean_curves = [] rs.EnableRedraw(False) for curve in input_curves: point_list = [] for point in input_points: if rs.PointInPlanarClosedCurve(point, curve, rs.CurvePlane(curve)) == 2: point_list.append(point) if point_list: sorted_points.append(rs.SortPointList(point_list)) #Clean curve # circle = rs.AddCircle(rs.CurveAreaCentroid(curve)[0],10000) # planar_surface = rs.AddPlanarSrf(circle) # projected_curve = rs.ProjectCurveToSurface(curve,planar_surface,(0,0,-1)) # clean_curves.append(projected_curve) # rs.DeleteObjects([circle,planar_surface,curve]) clean_curves.append(curve) #main_curve = rs.GetCurveObject("Selecciona curva",True)[0] #main_points = rs.SortPointList(rs.GetObjects("Selecciona puntos de referencia",rs.filter.point)) #input_curves = rebuild_curves(input_curves) for main_curve in clean_curves: main_points = sorted_points[clean_curves.index(main_curve)] bone_curves = [ create_bone(point, main_curve, length, width, diam / 2, aperture) for point in main_points ] #new_main_curve = rs.CopyObject(rs.ConvertCurveToPolyline(main_curve,False,False,True)) new_main_curve = rs.CopyObject(main_curve) completed = True for bone_curve in bone_curves: buffer_curve = rs.CurveBooleanDifference(new_main_curve, bone_curve) if len(buffer_curve) > 1: rs.DeleteObjects(buffer_curve) rs.DeleteObject(new_main_curve) completed = False break rs.DeleteObject(new_main_curve) new_main_curve = buffer_curve if not completed: super_curve = rs.CurveBooleanUnion(bone_curves) rare_curves = rs.CurveBooleanDifference(main_curve, super_curve) if len(rare_curves) > 1: areas = [rs.CurveArea(i) for i in rare_curves] sorted_curves = [ x for (y, x) in sorted(zip(areas, rare_curves)) ] rs.DeleteObjects(sorted_curves[:-1]) rs.DeleteObject(super_curve) rs.DeleteObjects(bone_curves + [main_curve])
__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") print(counter, crv)
if rs.IsCurve(curve) and boolfori: print "curva ottenuta" print boolfori puntidarimuovere = [] point = rs.BoundingBox(curve) px = point[0].X py = point[0].Y while (px < point[2].X): oldpy = py py = point[0].Y c2 = 0 if c1 == val: break while (py < point[2].Y): if rs.PointInPlanarClosedCurve((px, py), curve): for i in fori: print "fori" if rs.PointInPlanarClosedCurve((px, py), i): punto = rs.AddPoint(px, py) break c2 = c2 + 1 py = py + val print[c1, c2] if c2 > valSicurezza: break px = px + val c1 = c1 + 1 else: print "errore"
para_a = [ccx[0][5], ccx[1][5]] para_b = [ccx[0][7], ccx[1][7]] if para_b[0] > para_b[1]: para_b = [para_b[1], para_b[0]] probable_dash = rs.SplitCurve(polylines[i], para_a) edge = rs.TrimCurve(MN, para_b, False) edgepts = rs.CurvePoints(edge) for crv in probable_dash: crvpts = rs.CurvePoints(crv) if rs.PointCompare(crvpts[0], edgepts[0]): crvpts.reverse() newpl = rs.AddPolyline(edgepts + crvpts) if rs.PointInPlanarClosedCurve(pts[i], newpl): polylines[i] = newpl break ccx = rs.CurveCurveIntersection(polylines[j], MN) if ccx is None: continue para_a = [ccx[0][5], ccx[1][5]] para_b = [ccx[0][7], ccx[1][7]] if para_b[0] > para_b[1]: para_b = [para_b[1], para_b[0]] probable_dash = rs.SplitCurve(polylines[j], para_a) edge = rs.TrimCurve(MN, para_b, False) edgepts = rs.CurvePoints(edge)
i += i for j in range (0, count_y): j += j x = distance_x * i y = distance_y * j p = rs.AddPoint(x, y, 0) base_points.append(p) # Cull points outside curve culled_pts = [] if rs.IsCurveClosed(boundary_curve) and rs.IsCurvePlanar(boundary_curve): # Checking curve is ok for i in base_points: if i: result = rs.PointInPlanarClosedCurve(i, boundary_curve) if result==0: pass #print ('The point is outside of the closed curve.') elif result==1: #print('The point is inside of the closed curve.') culled_pts.append(i) else: ghenv.Component.AddRuntimeMessage(e, 'The curve must be planar and closed') # Cull closest points of curve rndm_cull_points = []
def point_in_zone(point, zone): result = True if rs.PointInPlanarClosedCurve(point, zone.curve) == 1 else False return result
while (px<point[2].X): oldpy = py py = point[0].Y c2 = 0 if c1 == val: break while (py<point[2].Y): # if rs.PointInPlanarClosedCurve([px,py],curve) and not rs.PointInPlanarClosedCurve([px,py],fori): # puntofinale =rs.AddPoint(px,py) # originepinza = rs.AddPoint(oldpx,oldpy) # pinzaorientata = rs.CopyObject(pinza,rs.VectorCreate(originepinza,puntofinale)) # print "successo" # print originepinza if rh.Geometry.Intersect.Intersection.CurveCurve(rs.coercecurve(pinza),rs.coercecurve(fori),0.1,0.1): print "true" if not rs.PointInPlanarClosedCurve((px,py),fori) and rs.PointInPlanarClosedCurve((px,py),curve): rs.AddPoint(px,py) c2= c2+1 py = py +val print [c1,c2] # originepinza = rs.CurveAreaCentroid(pinza) # rs.OrientObject(pinza,originepinza,[px,py]) px = px + val c1 = c1+1 else: print "errore"