def srfPlane(obj): tempplane = trp.getSrfFrame(obj) plane = rs.CreatePlane( tempplane.Origin, rs.VectorCrossProduct(tempplane.ZAxis, rs.WorldXYPlane().ZAxis), tempplane.ZAxis) return plane
def cPlaneLvl(): userstr = rs.GetDocumentUserText("levels") objdict = ast.literal_eval(userstr) for i in objdict: lvlname = i["level"] elevation = float(i["elevation"]) newplane = rs.CreatePlane((0, 0, elevation)) rs.ViewCPlane(None, newplane) rs.AddNamedCPlane(lvlname)
def planClips(lvl): viewname = lvl["level"] + "_view" tempview = rs.AddNamedView("tempview", "Top") view = rs.AddNamedView(viewname, tempview) elevation = float(lvl["elevation"]) lvlPlane = rs.CreatePlane((0, 0, elevation)) cutPlane = rs.PlaneFromNormal((0, 0, elevation + cutHeight), (0, 0, -1)) planes = [lvlPlane, cutPlane] clips = [rs.AddClippingPlane(x, 1000, 1000, view) for x in planes] group = rs.AddGroup() rs.AddObjectsToGroup(clips, group) rs.DeleteNamedView(tempview)
def _findWindowPlane(self, _srfcs): """ Takes in a set of surfaces, returns a list of their Centroids in 'order' Assess the surface normal of the group of surfaces and attempts to figuere out the 'order' of the srfcs when viewed from 'outside' (according to the surface normal) and orders the centroids from left--->right """ setXs = [] setYs = [] setZs = [] Centroids = [] for srfc in _srfcs: windowBrep = rs.coercebrep(srfc) surfaceList = windowBrep.Surfaces for eachSurface in surfaceList: srfcCentroid = rs.SurfaceAreaCentroid(eachSurface)[0] b, u, v = eachSurface.ClosestPoint(srfcCentroid) srfcNormal = eachSurface.NormalAt(u, v) setXs.append(srfcNormal.X) setYs.append(srfcNormal.Y) setZs.append(srfcNormal.Z) Centroids.append(srfcCentroid) # Find the average Normal Vector of the set px = sum(setXs) / len(setXs) py = sum(setYs) / len(setYs) pz = sum(setZs) / len(setZs) avgNormalVec = Rhino.Geometry.Point3d(px, py, pz) # Find a line through all the points and its midpoint fitLine = rs.LineFitFromPoints(Centroids) # Find the Midpoint of the Line midX = (fitLine.From.X + fitLine.To.X) / 2 midY = (fitLine.From.Y + fitLine.To.Y) / 2 midZ = (fitLine.From.Z + fitLine.To.Z) / 2 lineMidpoint = Rhino.Geometry.Point3d(midX, midY, midZ) # Rotate new Plane to match the window avg newAvgWindowPlane = rs.CreatePlane(lineMidpoint, avgNormalVec, [0, 0, 1]) finalPlane = rs.RotatePlane(newAvgWindowPlane, 90, [0, 0, 1]) # Plot the window Centroids onto the selection Set Plane centroidsReMaped = [] for eachCent in Centroids: centroidsReMaped.append(finalPlane.RemapToPlaneSpace(eachCent)) # Return a list of the new Centroids remapped onto the Set's Plane return centroidsReMaped
import rhinoscriptsyntax as rs import scriptcontext as sc #import Rhino as rc import ast #import json #sc.doc = rc.RhinoDoc.ActiveDoc objdict = sc.sticky["planplanes"] if sticky else ast.literal_eval( rs.GetDocumentUserText("planplanes")) keys = ['level', 'point'] def func(key): val = [d[key] for d in objdict] return val level, point = map(func, keys) x, y, z = map(lambda x: [d[x] for d in point], ['X', 'Y', 'Z']) plane = map(lambda x: rs.CreatePlane(x), zip(x, y, z))
# Project points to bottom surface btm_surface = [bottom_surface] # Create a list with one single element bottom_pts = rs.ProjectPointToSurface(rndm_cull_points, btm_surface, (0,0,-1)) # Project points to top surface top_surface = [top_surface] # Create a list with one single element top_pts = rs.ProjectPointToSurface(rndm_cull_points, top_surface, (0,0,1)) # Planes on the bottom bottom_planes = [] for i in bottom_pts: view = rs.CurrentView() planes = rs.CreatePlane(i, (1,0,0), (0,1,0)) bottom_planes.append(planes) # Rotate planes on ZAxis rotated_planes = [] for i in bottom_planes: plane = rs.ViewCPlane() rndm_angle = random.randrange(-5, 5) rotated_z = rs.RotatePlane(i, rndm_angle, planes.ZAxis) # Tilt control tilt = random.randrange(-5, 5) * max_tilt rotated_x = rs.RotatePlane(rotated_z, tilt, planes.XAxis) rotated_planes.append(rotated_x)
def getOrderedGeom(_geomList): """ Takes in a list of geometry (brep) and 'orders' it left->right. Used to order window surfaces or similar for naming 0...1...2...etc... Make sure the surface normals are all pointing 'out' for this to work properly. """ setXs = [] setYs = [] setZs = [] Centroids = [] CentroidsX = [] #Go through all the selected window geometry, get the information needed for i in range(len(_geomList)): # Get the surface normal for each window windowBrep = rs.coercebrep(_geomList[i]) surfaceList = windowBrep.Surfaces for eachSurface in surfaceList: srfcCentroid = rs.SurfaceAreaCentroid(eachSurface)[0] b, u, v = eachSurface.ClosestPoint(srfcCentroid) srfcNormal = eachSurface.NormalAt(u, v) setXs.append(srfcNormal.X) setYs.append(srfcNormal.Y) setZs.append(srfcNormal.Z) Centroids.append(srfcCentroid) CentroidsX.append(srfcCentroid.X) # Find the average Normal Vector of the set px = sum(setXs) / len(setXs) py = sum(setYs) / len(setYs) pz = sum(setZs) / len(setZs) avgNormalVec = Rhino.Geometry.Point3d(px, py, pz) # Find a line through all the points and its midpoint #print Centroids fitLine = rs.LineFitFromPoints(Centroids) newLine = Rhino.Geometry.Line(fitLine.From, fitLine.To) # Find the Midpoint of the Line #rs.CurveMidPoint(newLine) #Not working.... midX = (fitLine.From.X + fitLine.To.X) / 2 midY = (fitLine.From.Y + fitLine.To.Y) / 2 midZ = (fitLine.From.Z + fitLine.To.Z) / 2 lineMidpoint = Rhino.Geometry.Point3d(midX, midY, midZ) # New Plane newAvgWindowPlane = rs.CreatePlane(lineMidpoint, avgNormalVec, [0, 0, 1]) # Rotate new Plane to match the window finalPlane = rs.RotatePlane(newAvgWindowPlane, 90, [0, 0, 1]) # Plot the window Centroids onto the selection Set Plane centroidsReMaped = [] for eachCent in Centroids: centroidsReMaped.append(finalPlane.RemapToPlaneSpace(eachCent)) # Sort the original geometry, now using the ordered centroids as key return [x for _, x in sorted(zip(centroidsReMaped, _geom))]
#Define empty Square list and parameters rectangleList = [] amountSquares = 5 initialSquareSize = 1 squaresOffset = 2 #Generate square of grid #iterate trough X axis for x in range(gridAmountX): #iterate trough Y axis for y in range(gridAmountY): tempRectangleList = [] #iterate for rectangle from each point for size in range(initialSquareSize,amountSquares*squaresOffset+initialSquareSize, squaresOffset): #Starting Point point = rs.CreatePoint(x*gridSizeX, y*gridSizeY, 0) #Just to viz pointList.append(point) #Correct the origin point for each rectangle (It's not domained, it starts from the 0,0) translation = rs.XformTranslation([-size/2, -size/2, 0]) correctedPoint = rs.TransformObject(point, translation, True) currentPlane = rs.CreatePlane(correctedPoint, (1,0,0), (0,1,0)) #Create all te rectangles from each point tempRectangleList.append(rs.AddRectangle(currentPlane, size, size)) #Appends each sets of rectangle to the tree rectangleList.append(tempRectangleList) #Converts the list of list to a GH Tree offsetRectangle = th.list_to_tree(rectangleList)