def blkObjs(blkid): blockName = rs.BlockInstanceName(blkid) objref = rs.coercerhinoobject(blkid) idef = objref.InstanceDefinition idefIndex = idef.Index lvl = levels[rs.GetUserText(blkid, 'level')] height = float(lvl['height']) xform = rs.BlockInstanceXform(blkid) objects = [x for x in rs.BlockObjects(blockName) if rs.IsSurface(x)] masses = map(lambda x: massFromSrf(x, height), objects) # masses = map(lambda x: rs.SetUserText(x, 'blkname', blockName), masses) # newblk = rs.AddBlock(masses, (0,0,0), name=name, delete_input=True) objects.extend(masses) newGeometry = [] newAttributes = [] for object in objects: newGeometry.append(rs.coercegeometry(object)) ref = Rhino.DocObjects.ObjRef(object) attr = ref.Object().Attributes attr.SetUserString('blkname', blockName) newAttributes.append(attr) InstanceDefinitionTable = sc.doc.ActiveDoc.InstanceDefinitions InstanceDefinitionTable.ModifyGeometry(idefIndex, newGeometry, newAttributes) # rs.TransformObjects(masses, xform) rs.DeleteObjects(masses)
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 curvature(self, points=None): """""" if not points: points = self.heightfield() curvature = [] if rs.IsPolysurface(self.guid): rs.EnableRedraw(False) faces = {} for point in points: bcp = rs.BrepClosestPoint(self.guid, point) uv = bcp[1] index = bcp[2][1] try: face = faces[index] except (TypeError, IndexError): face = rs.ExtractSurface(self.guid, index, True) faces[index] = face props = rs.SurfaceCurvature(face, uv) curvature.append((point, (props[1], props[3], props[5]))) rs.DeleteObjects(faces.values()) rs.EnableRedraw(False) elif rs.IsSurface(self.guid): for point in points: bcp = rs.BrepClosestPoint(self.guid, point) uv = bcp[1] props = rs.SurfaceCurvature(self.guid, uv) curvature.append((point, (props[1], props[3], props[5]))) else: raise RhinoSurfaceError('object is not a surface') return curvature
def setObjAreaValue(obj): if rs.IsSurface(obj): setSrfAreaValue(obj) elif rs.IsPolysurface(obj) and rs.IsPolysurfaceClosed(obj): setBrepFA(obj) else: pass
def shape_from_ref(r): with parameter(immediate_mode, False): obj = _geometry_from_id(r) ref = native_ref(r) if isinstance(obj, geo.Point): return point.new_ref(ref, fromPt(obj.Location)) elif isinstance(obj, geo.Curve): if rh.IsLine(r) or rh.IsPolyline(r): if rh.IsCurveClosed(r): return polygon.new_ref( ref, [fromPt(p) for p in rh.CurvePoints(r)[:-1]]) else: return line.new_ref(ref, [fromPt(p) for p in rh.CurvePoints(r)]) elif obj.IsCircle(Rhino.RhinoMath.ZeroTolerance): return circle.new_ref(ref, fromPt(rh.CircleCenterPoint(r)), rh.CircleRadius(r)) elif rh.IsCurveClosed(r): return closed_spline.new_ref( ref, [fromPt(p) for p in rh.CurvePoints(r)]) else: return spline.new_ref(ref, [fromPt(p) for p in rh.CurvePoints(r)]) elif rh.IsObject(r) and rh.IsObjectSolid(r): return solid(native_ref(r)) elif rh.IsSurface(r) or rh.IsPolysurface(r): return surface(native_ref(r)) else: raise RuntimeError("{0}: Unknown Rhino object {1}".format( 'shape_from_ref', r))
def setObjAreaValue(obj): if rs.IsSurface(obj): setSrfAreaValue(obj) elif rs.IsPolysurface(obj) and rs.IsPolysurfaceClosed(obj): setBrepFA(obj) else: rs.SetUserText(obj, "area", 'na')
def write_strip_data(layer, point_ind): # get all surfaces on layer strips = rs.ObjectsByLayer(layer) strip_ind = 1 strip_dict = {} for strip in strips: # get only surfaces if rs.IsSurface(strip): if rs.IsSurfacePlanar(strip): strip_dict['Strip=' + layer + str(strip_ind)] = [] strip_brep = rs.coercebrep(strip) edges = Rhino.Geometry.Brep.DuplicateEdgeCurves(strip_brep) edge_ids = [] ind = 0 for edge in edges: edge_id = sc.doc.Objects.AddCurve(edge) if edge_id: rs.ObjectName(edge_id, 'active' + str(ind)) edge_ids.append(edge_id) ind += 1 # Get strip geometry # change color to help find strip rs.ObjectColor(strip, color=(255, 0, 255)) start_edge = rs.GetObject('Select start edge.', 4, False, False, active_strip_filter) start_length = rs.CurveLength(start_edge) sp = rs.CurveMidPoint(start_edge) rs.ObjectName(rs.AddPoint(sp), name='SP_' + str(point_ind)) end_edge = rs.GetObject('Select end edge.', 4, False, False, active_strip_filter) end_length = rs.CurveLength(end_edge) ep = rs.CurveMidPoint(end_edge) rs.ObjectName(rs.AddPoint(ep), name='SP_' + str(point_ind)) # Clean up rs.DeleteObjects(edge_ids) rs.ObjectColor(strip, color=(128, 0, 128)) # write to json start = { 'Point': point_ind, 'GlobalX': round(sp.X, 4), 'GlobalY': round(sp.Y, 4), 'WALeft': round(start_length * 0.5, 4), 'WARight': round(start_length * 0.5, 4), 'Autowiden': 'No' } point_ind += 1 end = { 'Point': point_ind, 'GlobalX': round(ep.X, 4), 'GlobalY': round(ep.Y, 4), 'WBLeft': round(end_length * 0.5, 4), 'WBRight': round(end_length * 0.5, 4), } strip_dict['Strip=' + layer + str(strip_ind)].append(start) strip_dict['Strip=' + layer + str(strip_ind)].append(end) point_ind += 1 strip_ind += 1 return strip_dict
def ColorBySize(): try: objs = rs.GetObjects("Select objects to color", 1073815613, preselect=True) if objs is None: return print "Select First Color" firstColor = rs.GetColor() if firstColor is None: return print "Select Second Color" secondColor = rs.GetColor(firstColor) if secondColor is None: return rs.EnableRedraw(False) colorLine = rs.AddLine(firstColor, secondColor) areas = [] for obj in objs: if rs.IsCurve(obj): if rs.IsCurveClosed(obj): areas.append(rs.CurveArea(obj)[0]) else: areas.append(rs.CurveLength(obj)) elif rs.IsSurface(obj): areas.append(rs.SurfaceArea(obj)[0]) elif rs.IsPolysurface(obj): if rs.IsPolysurfaceClosed(obj): areas.append(rs.SurfaceVolume(obj)[0]) elif rs.IsHatch(obj): areas.append(rs.Area(obj)) else: print "Only curves, hatches, and surfaces supported" return newAreas = list(areas) objAreas = zip(newAreas, objs) objAreas.sort() objSorted = [objs for newAreas, objs in objAreas] areas.sort() normalParams = utils.RemapList(areas, 0, 1) colors = [] for t in normalParams: param = rs.CurveParameter(colorLine, t) colors.append(rs.EvaluateCurve(colorLine, param)) for i, obj in enumerate(objSorted): rs.ObjectColor(obj, (colors[i].X, colors[i].Y, colors[i].Z)) rs.DeleteObject(colorLine) rs.EnableRedraw(True) return True except: 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 revol(r): if rh.IsCurve(r): return native_ref(rh.AddRevSrf(r, axis, start, end)) elif rh.IsSurface(r) or rh.IsPolysurface(r): out_refs = revolve_borders(r, axis, start, end, True) in_refs = revolve_borders(r, axis, start, end, False) return subtract_refs(single_ref_or_union(out_refs), [native_ref(r) for r in in_refs], shape) else: raise RuntimeError("Can't revolve the shape")
def heightfield(self, density=10, over_space=True): """""" try: du, dv = density except TypeError: du = density dv = density du = int(du) dv = int(dv) xyz = [] rs.EnableRedraw(False) if rs.IsPolysurface(self.guid): faces = rs.ExplodePolysurfaces(self.guid) elif rs.IsSurface(self.guid): faces = [self.guid] else: raise RhinoSurfaceError('object is not a surface') if over_space: for guid in faces: face = RhinoSurface(guid) uv = face.space(density) for u, v in uv: xyz.append(list(rs.EvaluateSurface(face.guid, u, v))) else: for guid in faces: bbox = rs.BoundingBox(guid) xmin = bbox[0][0] xmax = bbox[1][0] ymin = bbox[0][1] ymax = bbox[3][1] xstep = 1.0 * (xmax - xmin) / (du - 1) ystep = 1.0 * (ymax - ymin) / (dv - 1) seeds = [] for i in xrange(du): for j in xrange(dv): seed = xmin + i * xstep, ymin + j * ystep, 0 seeds.append(seed) points = map(list, rs.ProjectPointToSurface(seeds, guid, [0, 0, 1])) xyz += points if len(faces) > 1: rs.DeleteObjects(faces) rs.EnableRedraw(True) return xyz
def sweep_path_profile(path, profile, rotation, scale): if rh.IsCurve(profile): return single_ref_or_union( sweep_path_curve(path, profile, rotation, scale)) elif rh.IsSurface(profile): o_refs, i_refs = ([ solid_sweep_path_curve(path, border, rotation, scale) for border in rh.DuplicateSurfaceBorder(profile, i) ] for i in (1, 2)) if i_refs == []: return single_ref_or_union(o_refs) else: return subtract_refs(single_ref_or_union(o_refs), single_ref_or_union(i_refs)) else: raise RuntimeError('Continue this')
def getAdjacentSrfs(srf, layername='CladdingDivide'): sel = rs.ObjectsByLayer(layername) srfs = [] trash = [] adjacent = [] for o in sel: if rs.IsSurface(o): srfs.append(o) for i in range(0, len(srfs)): compare = srfs[i] if srf == compare: continue #action flag = isShareEdge(srf, compare) if flag: adjacent.append(compare) pass rs.DeleteObjects(trash) return adjacent
def assignBlockToPanel(obj): """ Assigns block containing a base surface to a surface with the matching name. Block, base surface, and target surface must all have the same name. input: target surface (with name) returns: None """ allBlockNames = rs.BlockNames() for eachBlockName in allBlockNames: if rs.ObjectName(obj) == eachBlockName: blockName = eachBlockName print "Matching Block Found" objBasePt = rs.SurfaceEditPoints(obj)[0] objYPt = rs.SurfaceEditPoints(obj)[1] objXPt = rs.SurfaceEditPoints(obj)[2] objXVec = rs.VectorCreate(objXPt, objBasePt) objXLength = rs.VectorLength(objXVec) objYLength = rs.Distance(objBasePt, objYPt) blockObjs = rs.BlockObjects(blockName) for blockObj in blockObjs: if rs.ObjectName(blockObj) == blockName: print "Contains base plane" if rs.IsSurface(blockObj): blockBasePt = rs.SurfaceEditPoints(blockObj)[0] blockYPt = rs.SurfaceEditPoints(blockObj)[1] blockXPt = rs.SurfaceEditPoints(blockObj)[2] blockXVec = rs.VectorCreate(blockXPt, blockBasePt) rotAngle = rs.VectorAngle(objXVec, blockXVec) blockXLength = rs.VectorLength(blockXVec) blockYLength = rs.VectorLength( rs.VectorCreate(blockYPt, blockBasePt)) xScale = objXLength / blockXLength yScale = objYLength / blockYLength newScale = [yScale, xScale, 1] rs.InsertBlock(blockName, objBasePt, scale=newScale, angle_degrees=rotAngle) break else: print "Error: Base plane was not a surface"
def AddCoordinateTag(obj): dots = [] if rs.IsCurve(obj): pts = rs.CurveEditPoints(obj) elif rs.IsSurface(obj): pts = rs.SurfaceEditPoints(obj) elif rs.IsBrep(obj): srfs = rs.ExplodePolysurfaces(obj) pts = [] for srf in srfs: pts+=rs.SurfaceEditPoints(srf) rs.DeleteObjects(srfs) try: pts except: return for pt in pts: dots.append(rs.AddTextDot('X: '+str(pt.X)+'\nY: '+str(pt.Y)+'\nZ: ' +str( pt.Z), pt)) return dots
def GetSurfaceFromFractureLayer(self, layer_name): """ gets surfaces from fracture layer and returns the surfaces. An auxilliary method to trim extruding fractures. Parameters ---------- layer_name: str name of frature layer """ surfs = [] # Will add found surfaces here # Don't try if the layer does not exist if rs.IsLayer(layer_name): # Get all identifiers for objects in the layer allobs = rs.ObjectsByLayer(layer_name) for i in allobs: if rs.IsSurface(i): # If this object is a surface surfs.append(i) # Add to list return surfs
def descent(self, points=None): """""" if not points: points = self.heightfield() tol = rs.UnitAbsoluteTolerance() descent = [] if rs.IsPolysurface(self.guid): rs.EnableRedraw(False) faces = {} for p0 in points: p = p0[:] p[2] -= 2 * tol bcp = rs.BrepClosestPoint(self.guid, p) uv = bcp[1] index = bcp[2][1] try: face = faces[index] except (TypeError, IndexError): face = rs.ExtractSurface(self.guid, index, True) faces[index] = face p1 = rs.EvaluateSurface(face, uv[0], uv[1]) vector = [p1[_] - p0[_] for _ in range(3)] descent.append((p0, vector)) rs.DeleteObjects(faces.values()) rs.EnableRedraw(True) elif rs.IsSurface(self.guid): for p0 in points: p = p0[:] p[2] -= 2 * tol bcp = rs.BrepClosestPoint(self.guid, p) uv = bcp[1] p1 = rs.EvaluateSurface(self.guid, uv[0], uv[1]) vector = [p1[_] - p0[_] for _ in range(3)] descent.append((p0, vector)) else: raise RhinoSurfaceError('object is not a surface') return descent
def space(self, density=10): """""" try: du, dv = density except TypeError: du = density dv = density density_u = int(du) density_v = int(dv) uv = [] rs.EnableRedraw(False) if rs.IsPolysurface(self.guid): faces = rs.ExplodePolysurfaces(self.guid) elif rs.IsSurface(self.guid): faces = [self.guid] else: raise Exception('Object is not a surface.') for face in faces: domain_u = rs.SurfaceDomain(face, 0) domain_v = rs.SurfaceDomain(face, 1) du = (domain_u[1] - domain_u[0]) / (density_u - 1) dv = (domain_v[1] - domain_v[0]) / (density_v - 1) for i in range(density_u): for j in range(density_v): uv.append((domain_u[0] + i * du, domain_v[0] + j * dv)) if len(faces) > 1: rs.DeleteObjects(faces) rs.EnableRedraw(True) return uv
def divSrfsToMesh(srfs,width=1500,extrudeVect=None): meshes=[] for s in srfs: if not rs.IsSurface(s):continue top,bot,verts=getSrfTopBotVertCrvs(s) if extrudeVect is None: p1=rs.CurveStartPoint(verts[0]) p2=rs.CurveEndPoint(verts[0]) if p1[2]>p2[2]: extrudeVect=p1-p2 else: extrudeVect=p2-p1 if bot is None: continue pts=rs.DivideCurve(bot,round(rs.CurveLength(bot)/width)) meshes.append(meshExtrudePtsByVect(pts,extrudeVect)) rs.DeleteObjects([top,bot]) rs.DeleteObjects(verts) mesh=rs.JoinMeshes(meshes,True) return mesh
def blkFace(obj): cameraPos = rs.ViewCamera() cameraPos.Z = 0 plane = rs.WorldXYPlane() if rs.IsBlockInstance(obj): plane = blkPlane(obj) elif rs.IsSurface(obj): plane = srfPlane(obj) targetpos = plane.Origin targetpos.Z = 0 viewdir = rs.VectorUnitize(cameraPos - targetpos) angle = rs.VectorAngle(viewdir, plane.YAxis) newXform = rs.XformRotation3(plane.YAxis, viewdir, plane.Origin) rs.TransformObject(obj, newXform)
# use rhinoscriptsyntax to get all the functions in one shot import rhinoscriptsyntax as rs import random import time import Rhino count = 0 selected = rs.SelectedObjects() # for obj in selected: # count += 1 if (selected): print("number of objects selected: " + str(len(selected))) if len(selected) == 1 and rs.IsSurface(selected): print("got one") obj = selected else: print("don't got one") obj = rs.GetSurfaceObject("surface to porcupine-ify", select=True) print(obj) scale = rs.GetReal("distance away from surface", 1) # ucount = rs.GetInteger("# of u points") # vcount = rs.GetInteger("# of v points") srfcurves = [] srfpoints = [] extensionpoints = []
def ConnectPointss(surface, pointss, diagonalDirection, bRing, step): # print "bRing",bRing # 01 if (rs.IsSurface(surface)): curves = [] polylines = [] step = int(step) # 11 if not bRing: if diagonalDirection == 1: for i in range(len(pointss) - 1): i = len(pointss) - i - 2 puvs = [] pls = [] surfObj = rs.coercerhinoobject(surface).Geometry for j in range(len(pointss[0])): if i + j >= len(pointss): break p = pointss[(i + j)][j] pls.append(p) puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) crv = ghc.CurveOnSurface(surfObj, puvs, False)[0] curves.append(crv) polyline = rs.AddPolyline(pls) polylines.append(polyline) for i in range(len(pointss[0]) - 1): i = i + 1 puvs = [] pls = [] surfObj = rs.coercerhinoobject(surface).Geometry for j in range(len(pointss)): if i + j >= len(pointss[0]): break p = pointss[j][(i + j)] pls.append(p) puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) crv = ghc.CurveOnSurface(surfObj, puvs, False)[0] curves.append(crv) polyline = rs.AddPolyline(pls) polylines.append(polyline) if diagonalDirection == -1: for i in range(len(pointss) - 1): i = len(pointss) - i - 2 puvs = [] pls = [] surfObj = rs.coercerhinoobject(surface).Geometry for j in range(len(pointss[0])): if i + j >= len(pointss): break p = pointss[(i + j)][len(pointss[0]) - j - 1] pls.append(p) puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) crv = ghc.CurveOnSurface(surfObj, puvs, False)[0] curves.append(crv) polyline = rs.AddPolyline(pls) polylines.append(polyline) for i in range(len(pointss[0]) - 1): i = i + 1 puvs = [] pls = [] surfObj = rs.coercerhinoobject(surface).Geometry for j in range(len(pointss)): if i + j >= len(pointss[0]): break p = pointss[j][len(pointss[0]) - (i + j) - 1] pls.append(p) puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) crv = ghc.CurveOnSurface(surfObj, puvs, False)[0] curves.append(crv) polyline = rs.AddPolyline(pls) polylines.append(polyline) if diagonalDirection == 0: polylines = [rs.AddPolyline(pls) for pls in pointss] # 11 成环 else: # print len(pointss) for i in range(int(len(pointss) / step)): puvs = [] surfObj = rs.coercerhinoobject(surface).Geometry pls = [] for j in range(len(pointss[0])): # print (i*step+j*diagonalDirection)%len(pointss) p = pointss[(i * step + j * diagonalDirection) % len(pointss)][j] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) pls.append(p) crv = ghc.CurveOnSurface(surfObj, puvs, False)[0] curves.append(crv) polyline = rs.AddPolyline(pls) polylines.append(polyline) return curves
def InterporateCurves(surface, curves, m, n, loop, bAdaptive, bRatio, bRing=False): """在两个方向上分别生成m,n条生成插值曲线""" bEdgeBePoint = False m = int(m) n = int(n) icurvesn = [] icurvesm = [] ipointssnm = [] ipointssmn = [] if len(curves) == 4: curve01 = curves[0] curve12 = curves[1] curve23 = curves[2] curve30 = curves[3] if len(curves) == 3: curve01 = curves[0] curve12 = curves[1] curve23 = rs.CurveEndPoint(curves[1]) curve30 = curves[2] rm = 1 rn = 1 # print len(curves) if bRatio: rm = (rs.CurveLength(curve23) / rs.CurveLength(curve01))**(1 / (m)) # rn=1 rn = (rs.CurveLength(curve30) / rs.CurveLength(curve12))**(1 / (n)) points01 = DivideCurveByNumberAndRatio(curve01, n + 1, 1 / rn) points12 = DivideCurveByNumberAndRatio(curve12, m + 1, rm) if len(curves) == 4: points23 = DivideCurveByNumberAndRatio(curve23, n + 1, rn) global points000 points000 = points23[:] if len(curves) == 3: points23 = [curve23] * (n + 2) points30 = DivideCurveByNumberAndRatio(curve30, m + 1, 1 / rm) # print "points01",points01 # print "points23",points23 # if bRing: # points23=ghc.ShiftList(points23,1,True) # if rs.IsCurveClosed(curve23)and rs.IsCurveClosed(curve30): # points30=ghc.ShiftList(points30,1,True) bpoints = points01 + points12 + points23 + points30 if bRing: points23 = ghc.ShiftList(points23, 1, True) for i in range(n): if (rs.IsSurface(surface)): icurve = rs.ShortPath(surface, points01[i + 1], points23[::-1][i + 1]) else: icurve = rs.AddLine(points01[i + 1], points23[::-1][i + 1]) icurvesn.append(icurve) count = 0 ipointss = [] while (count < loop): # 完整的一次循环,count=+2 ipointssnm = [] ipointssnm = [] relativeLengths = [] if (bAdaptive and count != 0): curvesm = icurvesm[:] curvesm.insert(0, curve01) curvesm.append(curve23) sumMidLength = 0 midLengths = [] for ii in range(m + 1): midLength = (rs.CurveLength(curvesm[ii]) + rs.CurveLength(curvesm[ii + 1])) * 0.5 midLengths.append(midLength) sumMidLength += midLength relativeLengths = [ midLength / sumMidLength for midLength in midLengths ] points12 = DivideCurveByRelativeLengths(curve12, relativeLengths) points30 = DivideCurveByRelativeLengths( curve30, list(reversed(relativeLengths))) for icurve in icurvesn: if (bAdaptive and count != 0): # print "relativeLengths1",relativeLengths ipoints = DivideCurveByRelativeLengths(icurve, relativeLengths) else: ipoints = DivideCurveByNumberAndRatio(icurve, m + 1, rm) ipointssnm.append(ipoints) # global surfObj surfObj = rs.coercerhinoobject(surface).Geometry # print surfObj icurvesm = [] for i in range(m): if (rs.IsSurface(surface)): puvs = [] p = points30[-(i + 1) - 1] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) for j in range(n): # 转换数据类型 p = ipointssnm[j][i + 1] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) if not bRing: p = points12[i + 1] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) # print (count) # print (puvs[2]) crv = ghc.CurveOnSurface(surfObj, puvs, bRing)[0] icurvesm.append(crv) else: ps = [] p = points30[-(i + 1) - 1] ps.append(p) for j in range(n): # 转换数据类型 p = ipointssnm[j][i + 1] pm = rs.MeshClosestPoint(surface, p)[0] ps.append(pm) # points12和points03的节点位置可能不完全重合,曲线的朝向影响了分段结果 if not bRing: p = points12[i + 1] else: p = points30[-(i + 1) - 1] ps.append(p) crv = rs.AddPolyline(ps) # print rs.IsCurveClosed(crv) icurvesm.append(crv) count = count + 1 points03 = list(reversed(points30)) ipointss = ipointssnm ipointss.insert(0, points03) if not bRing: ipointss.append(points12) if (count >= loop): print('循环正常结束') break ipointssmn = [] relativeLengths = [] if (bAdaptive and count != 0): curvesn = icurvesn[:] curvesn.insert(0, curve30) curvesn.append(curve12) sumMidLength = 0 midLengths = [] for ii in range(n + 1): midLength = (rs.CurveLength(curvesn[ii]) + rs.CurveLength(curvesn[ii + 1])) * 0.5 midLengths.append(midLength) sumMidLength += midLength # print "midLengths",midLengths relativeLengths = [ midLength / sumMidLength for midLength in midLengths ] points01 = DivideCurveByRelativeLengths(curve01, relativeLengths) points23 = DivideCurveByRelativeLengths( curve23, list(reversed(relativeLengths))) if rs.IsCurveClosed(curve23): points23 = ghc.ShiftList(points23, 1, True) for icurve in icurvesm: if (bAdaptive and count != 0): # print "relativeLengths2",relativeLengths ipoints = DivideCurveByRelativeLengths(icurve, relativeLengths) else: ipoints = DivideCurveByNumberAndRatio(icurve, n + 1, 1 / rn) # print n+1,1/rn,rs.IsCurveClosed(icurve) # print "ipoints",len(ipoints) ipointssmn.append(ipoints) icurvesn = [] # global surfObj surfObj = rs.coercerhinoobject(surface).Geometry # print surfObj for i in range(n): if (rs.IsSurface(surface)): ps = [] puvs = [] p = points01[(i + 1)] ps.append(p) puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) for j in range(m): # 转换数据类型 p = ipointssmn[j][i + 1] puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) p = points23[-(i + 1) - 1] ps.append(p) puv = ghc.SurfaceClosestPoint(p, surfObj)[1] puvs.append(puv) crv = ghc.CurveOnSurface(surfObj, puvs, False)[0] crvm = rs.AddPolyline(ps) icurvesn.append(crv) else: ps = [] p = points01[(i + 1)] ps.append(p) for j in range(m): # 转换数据类型 p = ipointssmn[j][i + 1] pm = rs.MeshClosestPoint(surface, p)[0] ps.append(pm) p = points23[-(i + 1) - 1] ps.append(p) crv = rs.AddPolyline(ps) icurvesn.append(crv) count = count + 1 ipointss = ipointssmn points32 = list(reversed(points23)) ipointss.insert(0, points01) ipointss.append(points32) # print count,len(ipointss[0]),len(ipointss[1]),len(ipointss[2]),len(ipointss[3]) if (count >= 100): break # print "ipointss",ipointss return icurvesm, icurvesn, ipointss
row = len(ipointssmn) bRingRow = bRing pointss = [] for ps in ipointssmn: pointss += ps if len(curves) == 4: curve01 = sortedCurves[0] curve12 = sortedCurves[1] curve23 = sortedCurves[2] curve30 = sortedCurves[3] if len(curves) == 3: curve01 = sortedCurves[0] curve12 = sortedCurves[1] curve23 = rs.CurveEndPoint(curves[1]) curve30 = sortedCurves[2] if (rs.IsSurface(surface)): if bRing: icurvesn.append(curve12) icurves45 = ConnectPointss(surface, map(list, zip(*ipointssmn)), 1, bRing, step) icurves135 = ConnectPointss(surface, map(list, zip(*ipointssmn)), -1, bRing, step) if bRing: ipointssnm2 = map(list, zip(*ipointssmn)) ipointssnm2.append(ipointssnm2[0]) ipointssmn2 = map(list, zip(*ipointssnm2)) pointss2 = [] for ps in ipointssmn2: pointss2 += ps
import rhinoscriptsyntax as rs # !-RunPythonScript "objectBottomFaceArea.py" # rs.EnableRedraw(False) faces = [] bndry = [] obj = rs.GetObject("Select polysurface to explode", rs.filter.polysurface, preselect=True) if rs.IsPolysurface(obj): faces = rs.ExplodePolysurfaces(obj) for face in faces: if rs.IsSurface(face): domainU = rs.SurfaceDomain(face, 0) domainV = rs.SurfaceDomain(face, 1) u = domainU[1] / 2.0 v = domainV[1] / 2.0 point = rs.EvaluateSurface(face, u, v) param = rs.SurfaceClosestPoint(face, point) normal = rs.SurfaceNormal(face, param) # print normal if normal.Z == -1: bndry.append(face) for bnd in bndry: area = rs.SurfaceArea(bnd)[0] areapy = area / 3.3058 print area, areapy txt = rs.ClipboardText(area)
def _filterOutNonSurfaces(self, _srfcs): return [s for s in _srfcs if rs.IsSurface(s)]
def AreaTag(obj, decPlaces): try: rhsrf = rs.coercesurface(obj) if rs.IsCurve(obj): if rs.IsCurvePlanar(obj) == False: return [0, False] if rs.IsCurveClosed(obj) == False: return [0, False] #get area if rs.UnitSystem() == 8: if rs.IsCurve(obj): area = rs.CurveArea(obj)[0]*0.0069444444444444 else: area = rs.Area(obj)*0.0069444444444444 areaText = utils.RoundNumber(area, decPlaces) + " SF" else: print "WARNING: Your units are not in inches" area = rs.CurveArea(obj)[0] areaText = area + ' ' + rs.UnitSystemName(False, True, True) #add annotation style dimStyle = sc.doc.DimStyles.FindName('PCPA_12') ########################################################################### #CURVES if rs.IsCurve(obj): if utils.IsRectangle(obj)[0]: #RECTANGLES srf = rs.AddPlanarSrf(obj) plane = HorizPlaneFromSurface(srf) rs.DeleteObject(srf) else: #OTHER CURVES srf = rs.AddPlanarSrf(obj) plane = HorizPlaneFromSurface(srf) rs.DeleteObject(srf) ########################################################################### #HATCHES elif rs.IsHatch(obj): rhobj = rs.coercegeometry(obj) boundaryCrvs = [] crvs = rhobj.Get3dCurves(False) for crv in crvs: boundaryCrvs.append(crv) for crv in rhobj.Get3dCurves(True): boundaryCrvs.append(crv) srf = sc.doc.Objects.AddBrep(rc.Geometry.Brep.CreatePlanarBreps(boundaryCrvs)[0]) plane = HorizPlaneFromSurface(srf) rs.DeleteObject(srf) ########################################################################### #SURFACES elif rs.IsSurface(obj): plane = HorizPlaneFromSurface(obj) ########################################################################### #OTHER/ERROR else: pts = rs.BoundingBox(obj) centerPoint = (pts[0] + pts[6]) / 2 if dimStyle is not None: textHeight = dimStyle.TextHeight areaTag = rs.AddText(areaText, plane, height = textHeight, justification = 131074) else: areaTag = rs.AddText(areaText, plane, height = 1, justification = 131074) #Change layers hostLayer = layers.AddLayerByNumber(8103, False) rs.ObjectLayer(areaTag, layers.GetLayerNameByNumber(8103)) return [area, True, areaTag] except: return [0, False]