import rhinoscriptsyntax as rs import math #from sets import Set as set rs.DeleteObjects(rs.AllObjects()) rs.EnableRedraw(False) filename = rs.OpenFileName("Open CSV file", ".csv|", None, None, None) file = open(filename, 'r') rows = file.readlines() file.close() del rows[0] neighborhoods = [] for row in rows: row = row.strip() ptInfo = row.split(',') neighborhood = ptInfo[0] neighborhoods.append(neighborhood) #print (neighborhoods) neis_ = set() for name in neighborhoods: neis_.add(name) neis = list(neis_) listOfFourAttributes = [] for row in rows: for i in neis:
def get_objects(name=None, color=None, layer=None, type=None): """Get identifiers of Rhino objects, potentially filtered by name, color, layer, or type. Parameters ---------- name : str, optional color : tuple or list, optional RGB color components in integer format (0-255). layer : str, optional type : Rhino.DocObjects.ObjectType, optional The object type. Returns ------- list The GUIDs of the objects matching the filter parameters. Examples -------- .. code-block:: python import compas_rhino guids_all = compas_rhino.get_objects() guids_compas = compas_rhino.get_objects(name='COMPAS.*') guids_red = compas_rhino.get_objects(color=(255, 0, 0)) guids_points = compas_rhino.get_objects(type=compas_rhino.rs.filter.point) guids_redpoints = compas_rhino.get_objects(color=(255, 0, 0), type=compas_rhino.rs.filter.point) .. code-block:: python guids_all = set(compas_rhino.get_objects()) guids_compas = set(compas_rhino.get_objects(name='COMPAS.*')) guids_red = set(compas_rhino.get_objects(color=(255, 0, 0))) guids_points = set(compas_rhino.get_objects(type=compas_rhino.rs.filter.point)) guids_redpoints = set(compas_rhino.get_objects(color=(255, 0, 0), type=compas_rhino.rs.filter.point)) print guids_compas.issubset(guids_all) print guids_all.issubset(guids_compas) # True, False print guids_red.issubset(guids_all) print guids_points.issubset(guids_all) print guids_redpoints.issubset(guids_all) # True, True, True print guids_redpoints.issubset(guids_points) print guids_redpoints.issubset(guids_red) print guids_points.issubset(guids_red) # True, True, False """ guids = rs.AllObjects() if name: guids = list(set(guids) & set(rs.ObjectsByName(name))) if color: guids = list(set(guids) & set(rs.ObjectsByColor(color))) if layer: guids = list(set(guids) & set(rs.ObjectsByLayer(layer))) if type: guids = list(set(guids) & set(rs.ObjectsByType(type))) return guids
import rhinoturtle import celestial import math def createSphereDecorator(body): radius = math.log(body.radius) / 100 sphere = rs.AddSphere(body.position, radius) rs.ObjectColor(sphere, body.color) return rhinoturtle.Decorator(sphere) def createLabelDecorator(body): text = rs.AddTextDot(body.name, body.position + Vector3d.ZAxis * 0.25) rs.ObjectColor(text, body.color) return rhinoturtle.Decorator(text) # Clear the board rs.DeleteObjects(rs.AllObjects(select=True)) solarSystem = celestial.System.fromJSON('./solar-system.json') for body in solarSystem.bodies: body.decorate(createSphereDecorator(body)) body.decorate(createLabelDecorator(body)) for i in range(730): solarSystem.advance(1) rs.Sleep(10)
import rhinoscriptsyntax as rs #delete all existing objects rs.ShowObjects(rs.HiddenObjects()) rs.DeleteObjects(rs.AllObjects('select')) #variables flowerRadius = 10 #radius of the flower centerRadius = 2 #radius of the center of the flower petalCount = 15 flowerCenter = (0, 0, 0) petalWidth = 10 #width of the petals petals = [] #store petal curves here #print out the variables textToPrint = 'flowerRadius = %d\ncenterRadius = %d\npetalCount = %d\npetalWidth = %d' % ( flowerRadius, centerRadius, petalCount, petalWidth) rs.AddText(textToPrint, ((flowerRadius + 1), 2, 0), height=1.0) #draw outer circle outerCircle = rs.AddCircle(flowerCenter, flowerRadius) #divide to get the point of each petal points = rs.AddPoints(rs.DivideCurve(outerCircle, petalCount)) #draw each petal for i in range(len(points)): #draw line from center to point of the petal centerLine = rs.AddLine(points[i], flowerCenter) #find the midpoint
import rhinoscriptsyntax as rs allObjs = rs.AllObjects() rs.DeleteObjects(allObjs) class Turtle: def __init__(self, pos = [0,0,0], heading = [1,0,0]): self.heading = heading self.point = rs.AddPoint(pos) pointPos = rs.PointCoordinates(self.point) self.direction = rs.VectorCreate(heading,pointPos) self.lines = [] def forward(self,magnitude): print (self.direction) movement = rs.VectorScale(self.direction,magnitude) prevPos = rs.PointCoordinates(self.point) rs.MoveObject(self.point,movement) currentPos = rs.PointCoordinates(self.point) rs.AddLine(prevPos,currentPos) def left(self,angle): self.direction = rs.VectorRotate(self.direction, angle, [0,0,1]) print(self.direction) def right(self,angle): self.direction = rs.VectorRotate(self.direction, -angle, [0,0,1]) print(self.direction)
def all_shapes(): return [shape_from_ref(r) for r in rh.AllObjects()]
all(is_in_circle(c, r) for r in points): result = c if result is not None: return result # This optimization is not mathematically proven # Try all unique triples for i in range(len(points)): p = points[i] for j in range(i + 1, len(points)): q = points[j] for k in range(j + 1, len(points)): r = points[k] c = make_circumcircle(p, q, r) if c is not None and (result is None or c[2] < result[2]) and \ all(is_in_circle(c, s) for s in points): result = c if result is None: raise AssertionError() return result if __name__ == "__main__": pts = rs.AllObjects() ptsList = rs.coerce3dpointlist(pts) ptCoords = [] for pt in ptsList: ptCoords.append([pt.X, pt.Y]) results = _smallest_enclosing_circle_naive(ptCoords) rs.AddCircle((results[0], results[1], 0), results[2])
def rescale(): # get current state and scale from DocumentData, if present or from user, if not print("Current Scale: 1:", rs.GetDocumentData("ScaleModel", "scale")) print("Current State: ", rs.GetDocumentData("ScaleModel", "state")) if rs.GetDocumentData("ScaleModel", "scale") and rs.GetDocumentData( "ScaleModel", "state"): scale = float(rs.GetDocumentData("ScaleModel", "scale")) oldechelle = scale state = rs.GetDocumentData("ScaleModel", "state") oldetat = state else: state = "" state = rs.ListBox(items=("Full-Scale", "Model Scale"), message="Currently at what scale ?", title="Scale Model", default=state) if state is None: # cancelled return oldetat = state if state == "Model Scale": scale = 250. scale = rs.GetReal("Current Scale 1:", scale, 0) oldechelle = scale if scale is None: # cancelled return else: if state == "Full-Scale": scale = 1. previous_params = (str(scale), state) # get desired state and scale state = rs.ListBox(("Full-Scale", "Model Scale"), "Currently %s. Choose new state" % (state), "Rescale", state) if state == None: # cancelled return if state == "Model Scale": if not scale: scale = 250. scale = rs.GetReal("New Scale 1:", scale, 0) if scale == None: return rs.SetDocumentData("ScaleModel", "scale", str(scale)) rs.SetDocumentData("ScaleModel", "state", state) # scale geometry and dimensions dimstyles = rs.DimStyleNames() rs.EnableRedraw(False) if not oldetat == state: if state == "Full-Scale": rs.ScaleObjects(rs.AllObjects(), [0, 0, 0], [(scale), (scale), (scale)]) for dimstyle in dimstyles: rs.Command('_-ScaleDimstyle "' + dimstyle + '" ' + str(scale)) else: rs.ScaleObjects(rs.AllObjects(), [0, 0, 0], [(1 / scale), (1 / scale), (1 / scale)]) for dimstyle in dimstyles: rs.Command('_-ScaleDimstyle "' + dimstyle + '" ' + str(1 / scale)) else: if state == "Model Scale": rs.ScaleObjects(rs.AllObjects(), [0, 0, 0], \ [(oldechelle / scale), (oldechelle / scale), (oldechelle / scale)]) for dimstyle in dimstyles: rs.Command('_-ScaleDimstyle "' + dimstyle + '" ' + str(oldechelle / scale)) sc.doc.AddCustomUndoEvent("Undo ScaleModel", __undo_usertext, previous_params) print("New Scale: 1:", rs.GetDocumentData("ScaleModel", "scale")) print("New State: ", rs.GetDocumentData("ScaleModel", "state")) rs.EnableRedraw(True) rs.ZoomExtents(all=True)
import rhinoscriptsyntax as rs all = rs.AllObjects() rs.DeleteObjects(all) plane = rs.WorldYZPlane() j = 0 for i in range(20): plane = rs.RotatePlane(plane, j, [-1, 1, 1]) j = j + 10 rs.AddRectangle(plane, 25.0, 25.0) plane = rs.WorldZXPlane() for i in range(20): plane = rs.RotatePlane(plane, j, [1, -1, 1]) j = j + 10 rs.AddRectangle(plane, 25.0, 25.0) plane = rs.WorldXYPlane() for i in range(20): plane = rs.RotatePlane(plane, j, [1, 1, -1]) j = j + 10 rs.AddRectangle(plane, 25.0, 25.0)
def remove_objects(): rs.DeleteObjects(rs.AllObjects())