def draw(pts): rs.EnableRedraw(0) sleep(0.05) RhinoApp.Wait() for i in range(4): for j in range(4): if recs[i][j]: rs.DeleteObject(recs[i][j]) if tags[i][j]: rs.DeleteObject(tags[i][j]) if pts[i][j]: recs[i][j] = rs.AddRectangle( rs.PlaneFromNormal((i + 0.1, j + 0.1, 0), (0, 0, 1)), 0.8, 0.8) tags[i][j] = rs.AddText(pts[i][j], (i + 0.5, j + 0.5, 0), 0.2 + (0.1 / len(str(pts[i][j]))), 'Arial', 0, 131074) if pts[i][j] <= 4: rs.ObjectColor(tags[i][j], (245, 245, 220)) rs.ObjectColor(recs[i][j], (245, 245, 220)) if 8 <= pts[i][j] <= 16: rs.ObjectColor(tags[i][j], (245, 97, 0)) rs.ObjectColor(recs[i][j], (245, 97, 0)) if 32 <= pts[i][j] <= 64: rs.ObjectColor(tags[i][j], (245, 7, 0)) rs.ObjectColor(recs[i][j], (245, 9, 0)) if pts[i][j] > 64: rs.ObjectColor(tags[i][j], (245, 197, 44)) rs.ObjectColor(recs[i][j], (245, 197, 44)) rs.EnableRedraw(1)
def Build_Key(Point, colors, tol): """ Build key for tolerance shading. Create color coded text objects and planes. """ low2 = "-" + str(tol[2]) + '"' + " and lower" low1 = "-" + str(tol[2]) + '"' + " to -" + str(tol[1]) + '"' low0 = "-" + str(tol[1]) + " to -" + str(tol[0]) + '"' good = "-" + str(tol[0]) + " to +" + str(tol[0]) + '"' high0 = "+" + str(tol[0]) + " to +" + str(tol[1]) + '"' high1 = "+" + str(tol[1]) + " to +" + str(tol[2]) + '"' high2 = "+" + str(tol[2]) + " and higher" stringList = [high2, high1, high0, good, low0, low1, low2] objs = [] for i in range(len(stringList)): pt = rs.coerce3dpoint([0, 0, 1.5 * i + 3]) plane = rs.PlaneFromNormal(pt + Point, [0, -1, 0], [1, 0, 0]) txt = rs.AddText(stringList[i], plane) srf = rs.AddPlaneSurface(plane, 1, 1) rs.MoveObject(srf, [-2, 0, 0]) stringColor = "Tol_" + colors[i].ToString().split("[")[1].rstrip("]") mt.OrganizeLayer(stringColor, Objects=[srf, txt], Render=colors[i], Color=colors[i])
def set_up_no_selection(): g.Grammar.clear_all() f.Frame.new() r.Rule.add_first() line = rs.AddLine((0, 0, 0), (10, 10, 0)) lpoint = rs.AddTextDot('textdot', (10, 10, 0)) text = rs.AddText('text', (5, 5, 0), 2)
def addNumberTag(sortedPts, objs): for i, pt in enumerate(sortedPts): numTag = rs.AddText(str(i+1), pt, justification = 131074) objLay = rs.ObjectLayer(objs[i]) parentLayer = rs.ParentLayer(objLay) hostLayer = rs.AddLayer("ANNO_NUM", (128,128,128), parent = parentLayer) rs.ObjectLayer(numTag, hostLayer)
def new(cls, layer, position): """Receives: layer str. The name of the layer position point3d. The position of the arrow Creates an arrow-name group with the name <name>-labeled-arrow. Inserts it at the arrow position. Returns: group_out str. The name of the new group, if successful. None otherwise. """ group = '%s-labeled-arrow' % layer arrow_instance = a.Arrow.new_instance(layer, position) text_position = rs.PointAdd(position, s.Settings.arrow_label_offset_from_arrow) rs.CurrentLayer(layer) arrow_text = rs.AddText(layer, text_position, height=2, justification=2) rs.CurrentLayer(s.Settings.default_layer_name) group_out = rs.AddGroup(group) n_objects_added = rs.AddObjectsToGroup([arrow_instance, arrow_text], group) if n_objects_added: return_value = group_out else: return_value = None return return_value
def areaTag(pline): #get area area = rs.CurveArea(pline)[0] area = str((int(area * 100)) / 100) + "m2" print area #move area tag below name tag location offset = [0, -2.5, 0] #add text tag objID = pline text = '%<area("' + str(objID) + '")>%m2' pt = rs.AddPoint(rs.CurveAreaCentroid(pline)[0]) rs.MoveObject(pt, offset) areaTag = rs.AddText(text, pt, 1, justification=131074) rs.DeleteObject(pt) parentLayer = rs.ParentLayer(rs.ObjectLayer(pline)) hostLayer = rs.AddLayer("ANNO_AREA", (128, 128, 128), parent=parentLayer) rs.ObjectLayer(areaTag, hostLayer) te = rs.coercerhinoobject(areaTag, True, True) te.Geometry.TextFormula = text te.CommitChanges() sc.doc.Views.Redraw() return None
def unroll(self): x = 0 for i in range(len(self.srfList)): g = rs.AddGroup() s, p = rs.UnrollSurface(self.srfList[i], False, self.unrollList[i]) s = rs.JoinSurfaces(s, True) p = rs.MoveObjects(p, [x, self.name * 10, 0]) s = rs.MoveObject(s, [x, self.name * 10, 0]) b = rs.DuplicateSurfaceBorder(s, 1) rs.ObjectLayer(b, "cut") rs.AddObjectsToGroup(b, g) rs.AddObjectsToGroup(p, g) bb = rs.BoundingBox(s) x += fabs(bb[0].X - bb[1].X) + 1 t = rs.AddText( str(self.name) + "-" + str(i), util.averagePt(rs.CurvePoints(b)), 0.3) t = util.makeEngravingFont(t) rs.AddObjectsToGroup(t, g) rs.DeleteObjects(s)
def new(cls, label, point): """Draws a new labeled point (Rhino text object). Receives: label str point Point3d or [num, num, num] or (num, num, num) Both arguments are validated upstream, but we're checking again. Returns: guid the ID of the labeled point, if successful None otherwise """ method_name = 'new' try: if not (type(label) == str and (type(point) == list or type(point) == tuple or rs.IsPoint(point))): raise TypeError if not (cn.ComponentName._is_well_formed(label)): raise ValueError except TypeError: message = "The arguments must be a string and a point (or triple)" print("%s.%s:\n %s" % (cls.__name__, method_name, message)) return_value = None except ValueError: message = "The label must not contain spaces or #s" print("%s.%s:\n %s" % (cls.__name__, method_name, message)) return_value = None else: guid = rs.AddText(label, point, cls.text_height) return_value = guid finally: return return_value
def set_up_bad_type_preselection(): g.Grammar.clear_all() f.Frame.new() r.Rule.add_first() line = rs.AddLine((0, 0, 0), (20, 20, 0)) text = rs.AddText('label', (10, 10, 0), 2) rs.SelectObject(line)
def AddBlockName(obj): name = rs.BlockInstanceName(obj) pt = rs.BlockInstanceInsertPoint(obj) bb = rs.BoundingBox(obj) text = rs.AddText(name, (bb[0] + bb[6]) / 2) rs.SetUserText(text, 'tag', 'label') group = rs.AddGroup() rs.AddObjectsToGroup([obj, text], group)
def docText2Text(pt, section, entry): string = section + "\\" + entry text = entry + ': %<documenttext("'+ str(string) +'")>%' tag = rs.AddText(text, pt, 1, justification = 1) te = rs.coercerhinoobject(tag, True, True) te.Geometry.TextFormula = text te.CommitChanges() sc.doc.Views.Redraw()
def viewportclock(): now = datetime.datetime.now() textobject_id = rs.AddText(now, (0, 0, 0), 20) if textobject_id is None: return while True: rs.Sleep(1000) now = datetime.datetime.now() rs.TextObjectText(textobject_id, now)
def addSrf(srf): points = [] for indx in srf.indxList: points.append(ptsList[indx]) if (srf.state == 1): rs.AddText(str(indx), ptsList[indx], 0.2) points.append(points[0]) if (srf.state == 1): rs.AddPolyline(points)
def set_up_good_arg(): g.Grammar.clear_all() f.Frame.new() r.Rule.add_first() line = rs.AddLine((0, 0, 0), (10, 10, 0)) lpoint = rs.AddTextDot('textdot', (10, 10, 0)) text = rs.AddText('text', (5, 5, 0), 2) message = "Select the rule name tag" rule_name_tag = rs.GetObject(message) rs.SelectObject(rule_name_tag)
def _write_rule_name(self, name, position): """Receives: name str. The name of the rule position Point3d Writes the rule name at the given position """ height = 2 font = 'Arial' font_style = 0 justified_center = 2 rs.AddText(name, position, height, font, font_style, justified_center)
def draw_grid_info(_origin_pt, _x_span, _y_span, _z_span, layer): text = "X{0}Y{1}Z{2}".format(_x_span, _y_span, _z_span) place_point = [_origin_pt[0], _origin_pt[1] - 10, _origin_pt[2]] text_height = x_span / 10 font = "Arial" font_style = 0 # 0: normal 1: bold 2: italic 3: bold and italic justification = 2 text_id = rs.AddText(text, place_point, text_height, font, font_style, justification) rs.ObjectLayer(text_id, layer)
def draw_lpoint(): prompt_for_label = 'Enter the label' text = rs.GetString(prompt_for_label) prompt_for_point = 'Select the point' point = rs.GetPoint(prompt_for_point) height = 2 lpoint = rs.AddText(text, point, height) radius = 0.5 sphere = rs.AddSphere(point, radius) group = rs.AddGroup() rs.AddObjectsToGroup([lpoint, sphere], group)
def draw_info(self): text = "w: {0} d: {1} h: {2}".format(self.width, self.depth, self.height) place_point = [self.origin[0], self.origin[1] - 100, self.origin[2]] text_height = 50 font = "Arial" font_style = 0 # 0: normal 1: bold 2: italic 3: bold and italic justification = None rs.AddText(text, place_point, text_height, font, font_style, justification)
def checkFont(): global font # dummy text object to test if this font is available obj = rs.AddText('font test', [0, 0, 0], 1.0, "Alte DIN 1451 Mittelschrift", 0, 0) if not obj == None: font = "Alte DIN 1451 Mittelschrift" rs.DeleteObject(obj) else: # default to generic font font = "Arial"
def addLevelMarks(func): rs.EnableRedraw(False) leftAlign = True geometry = [] currentLevels = setLevels.getFloorLevels() for level in currentLevels: if level is None: print "Levels have not been set." return levelNames = rs.GetDocumentData("Levels") size = 10 i = 0 stPts = [] for level in currentLevels: vec1 = [size*.2,size*.1,0] ptA = [0, level, 0] ptB = [size*.5, level, 0] stPts.append(ptA) geometry.append(rs.AddLine(ptA, ptB)) geometry.append(rs.AddText(levelNames[i] + ": +" + str(level), rs.VectorAdd(ptA, vec1), size*.1)) #Triangle Marking triPts = [[0,0,0], [size*.05, size*.07,0], [-size*.05, size*.07,0], [0,0,0]] newPts = [] triPt = rs.VectorAdd(ptA, [size*.1, 0,0]) for j in range(0, 4): newPts.append(rs.VectorAdd(triPt, triPts[j])) tri = rs.AddPolyline(newPts) geometry.append(rs.CloseCurve(tri)) i=i+1 #Dimensions for i in range(0, len(currentLevels)-1): pt1 = [0,currentLevels[i], 0] pt2 = [0,currentLevels[i+1], 0] pt3 = [size*-.15,currentLevels[i+1], 0] geometry.append(rs.AddAlignedDimension(pt1, pt2, pt3)) firstPt = [0,currentLevels[0], 0] lastPt = [0,currentLevels[-1], 0] dimOffset = [size*-.3,currentLevels[-1], 0] geometry.append(rs.AddAlignedDimension(firstPt, lastPt, dimOffset)) rs.AddLayer("80_LAYOUT", visible = True) annoLayer = rs.AddLayer("ANNO", parent = "80_LAYOUT") for geo in geometry: rs.ObjectLayer(geo, annoLayer) rs.AddBlock(geometry, [0,0,0], "Level Marks", True) if (func == 0): block = rs.InsertBlock("Level Marks", [0,0,0]) rs.ObjectLayer(block, "ANNO") rs.EnableRedraw(True) return
def AnnotateCurveEndPoints(): print "annotateCurveEndPoints" #Annotates the endpoints of curve objects. If the curve is closed then only the starting point is annotated. # get the curve object objectId = rs.GetObject("Select curve", rs.filter.curve) if objectId is None: return # Add the first annotation point = rs.CurveStartPoint(objectId) rs.AddPoint(point) #textDot is out of scale #rs.AddTextDot(point, point) txtString = meters(point) rs.AddText(txtString, point, 1000 ) print (point.X + point.Y + point.Z) # Add the second annotation if not rs.IsCurveClosed(objectId): point = rs.CurveEndPoint(objectId) rs.AddPoint(point) txtString = meters(point) rs.AddText(txtString, point, 1000 )
def copyAndMover(self, first, mid, last, points, text): plane = rs.PlaneFromPoints(points[0], points[1], points[2]) uv1 = rs.PlaneClosestPoint(plane, points[1], False) uv2 = rs.PlaneClosestPoint(plane, points[2], False) distHor = abs(uv1[0] - uv2[0]) distVert = abs(uv1[1] - uv2[1]) key = 'len{0}{1}'.format(distHor, distVert) key = re.sub(r'\.', '', key) if key in self.partsHash: self.partsHash[key].append(text) else: self.partsHash[key] = [] self.partsHash[key].append(text) ypos = len(self.partsHash.keys()) + len(self.partsHash.keys()) rs.AddText(key, [0, ypos, 0], 0.3) newPoints = [ rs.AddPoint(0, ypos, 0), rs.AddPoint(self.FLAT_LENGTH, ypos, 0), rs.AddPoint(self.FLAT_LENGTH + distHor, ypos + distVert, 0), rs.AddPoint((self.FLAT_LENGTH * 2) + distHor, ypos + distVert, 0) ] first = rs.OrientObject(first, points, newPoints, 1) mid = rs.OrientObject(mid, points, newPoints, 1) last = rs.OrientObject(last, points, newPoints, 1) first_fillet = rs.AddFilletCurve(first, mid, 0.09375) fillet_points = rs.CurveFilletPoints(first, mid, 0.09375) first_circle = rs.AddCircle(fillet_points[2], 0.09375) first_cp = rs.CurveClosestPoint(first, fillet_points[0]) first_domain = rs.CurveDomain(first) first = rs.TrimCurve(first, (first_domain[0], first_cp), True) second_cp = rs.CurveClosestPoint(mid, fillet_points[1]) second_domain = rs.CurveDomain(mid) mid = rs.TrimCurve(mid, (second_cp, second_domain[1]), True) second_fillet = rs.AddFilletCurve(mid, last, 0.09375) fillet_points = rs.CurveFilletPoints(mid, last, 0.09375) second_circle = rs.AddCircle(fillet_points[2], 0.09375) first_cp = rs.CurveClosestPoint(mid, fillet_points[0]) first_domain = rs.CurveDomain(mid) mid = rs.TrimCurve(mid, (first_domain[0], first_cp), True) second_cp = rs.CurveClosestPoint(last, fillet_points[1]) second_domain = rs.CurveDomain(last) last = rs.TrimCurve(last, (second_cp, second_domain[1]), True) curve = rs.JoinCurves( [first, first_fillet, mid, second_fillet, last]) rs.AddCircle([0, ypos - 0.125 - 0.09375, 0], 0.09375) rs.AddCircle([(self.FLAT_LENGTH * 2) + distHor, ypos + distVert + 0.125 + 0.09375, 0], 0.09375)
def draw(self): for i in range(self.uNum + 1): for j in range(self.vNum + 1): pt = self.getPt(i, j) rs.AddPoint(pt) rs.AddText(str(i) + ',' + str(j), pt, height=0.2) # # return self #eof #eoc
def drawDivisionLine(emblem, color=True): objs = [] # line r = 24 for i in range(int(emblem.division)): p = [r, 0, 0] if (emblem.division % 4 == 0): angle = i * 360.0 / emblem.division + 360.0 / emblem.division / 2.0 else: angle = i * 360.0 / emblem.division p = rs.VectorRotate(p, angle, [0, 0, 1]) obj = rs.AddLine([0, 0, 0], p) if (color): layer = "line%s" % (i % int(emblem.division / 2.0)) else: layer = "lineGray" rs.ObjectLayer(obj, layer) objs.append(obj) # circle obj = rs.AddCircle([0, 0, 0], r) if (color): layer = "lineBlack" else: layer = "lineGray" rs.ObjectLayer(obj, layer) objs.append(obj) # text planeOri = rs.ViewCPlane() for i in range(int(emblem.division / 2.0)): if (emblem.division % 4 == 0): angle = i * 360.0 / emblem.division + 360.0 / emblem.division / 2.0 else: angle = i * 360.0 / emblem.division p = [r, 0, 0] txt = "%d" % (angle) height = 1.2 pt = [0, height / 2.0, 0] font_style = 0 justification = 2 + 65536 obj = rs.AddText(txt, pt, height, font, font_style, justification) rs.RotateObject(obj, [0, 0, 0], -90.0, [0, 0, 1], False) rs.MoveObject(obj, [r, 0, 0]) rs.RotateObject(obj, [0, 0, 0], angle, [0, 0, 1], False) rs.ObjectLayer(obj, "textLine") objs.append(obj) rs.ViewCPlane(None, planeOri) #return return objs
def ptsOnSrf (): surfaceId = rs.GetObject("pick surface", 8, True, True) uVal = rs.GetInteger("pick u/row count",4, 1, 20) vVal = rs.GetInteger("pick v/col count",4, 1, 20) uDomain = rs.SurfaceDomain(surfaceId, 0) vDomain = rs.SurfaceDomain(surfaceId, 1) uStep = (uDomain[1] - uDomain[0])/ uVal vStep = (vDomain[1] - vDomain[0])/ vVal count = 0 for i in rs.frange(uDomain[0], uDomain[1], uStep): for j in rs.frange(vDomain[0], vDomain[1], vStep): point = rs.EvaluateSurface(surfaceId, i, j) newPt = rs.AddPoint(point) count += 1 rs.AddText(count,newPt, .25)
def nameTag(obj): roomName = rs.ObjectName(obj) try: text = str(roomName) pt0 = rs.BoundingBox(obj)[0] pt2 = rs.BoundingBox(obj)[2] pt = rs.PointDivide(rs.PointAdd(pt0, pt2), 2) areaTag = rs.AddText(text, pt, 1, justification=131074) except: print "Object has no name" return parentLayer = rs.ParentLayer(rs.ObjectLayer(obj)) hostLayer = rs.AddLayer("ANNO_NAME", (128, 128, 128), parent=parentLayer) rs.ObjectLayer(areaTag, hostLayer) return None
def label_and_len_lines(self): # f = open('{0}/{1}.txt'.format(dir_path, self.outFile), 'w') # dists = [] for i in range(0, len(self.all_lines)): curr_len = rs.CurveLength(self.all_lines[i]) # rs.AddPipe(self.all_lines[i], 0, 0.09375, 0, 1) if math.fabs(curr_len - self.FLAT_LENGTH) > 0.000001: # dists.append('%.3f' % curr_len) mp = rs.CurveMidPoint(self.all_lines[i]) text = 'line{0}'.format(i) rs.AddText(text, mp, 0.3) start = rs.AddLine(rs.CurveStartPoint(self.all_lines[i - 1]), rs.CurveEndPoint(self.all_lines[i - 1])) mid = rs.AddLine(rs.CurveStartPoint(self.all_lines[i]), rs.CurveEndPoint(self.all_lines[i])) end = rs.AddLine(rs.CurveStartPoint(self.all_lines[i + 1]), rs.CurveEndPoint(self.all_lines[i + 1])) self.createPipe(start, mid, end, text)
def drawCell(cellIndx): cellFaces = [] center = [] for i in range(len(ownerList)): if ownerList[i] == cellIndx: cellFaces.append(facesList[i]) for i in range(len(nbrList)): if nbrList[i] == cellIndx: cellFaces.append(facesList[i]) for face in cellFaces: points = [] for indx in face: points.append(ptsList[indx]) rs.AddText(str(indx), ptsList[indx], 0.2) points.append(points[0]) rs.AddPolyline(points)
def addBox(node): box = [] lower = node.indxList[0] upper = node.indxList[6] center = [] for i in range(3): center.append((ptsList[lower][i] + ptsList[upper][i]) / 2) for indx in node.indxList: box.append(ptsList[indx]) boxBody = rs.AddBox(box) rs.AddText(node.nid, center, 0.05) if (node.state == 1): rs.ObjectColor(boxBody, [255, 0, 0]) elif (node.state == 3): rs.ObjectColor(boxBody, [0, 255, 0]) elif (node.state == 4): rs.ObjectColor(boxBody, [0, 0, 0])
def setDetailNamesToScale(addNames=True): """ sets the name of the detail to its scale, so that you can use this property for page scale text and optianally add text with the scale of each detail to the lower left corner version 1.1 www.studiogijs.nl ---- changes: version 1.1 : fixed bug with adding text to wrong pages version 1.01 : removed typo """ pageviews = sc.doc.Views.GetPageViews() for pageview in pageviews: #get all details details = pageview.GetDetailViews() for detail in details: print detail #skip perspective details if detail.DetailGeometry.IsParallelProjection: ratio = detail.DetailGeometry.PageToModelRatio if ratio >= 1: text = str(int(ratio)) + ":1" else: text = "1:" + str(int(1 / ratio)) rs.ObjectName(detail.Id, text) if addNames: pt = [0, 0, 0] pt[0] = detail.Geometry.GetBoundingBox( Rhino.Geometry.Plane.WorldXY).Min.X + 3 pt[1] = detail.Geometry.GetBoundingBox( Rhino.Geometry.Plane.WorldXY).Min.Y + 3 text = "detail (scale " + text + ")" sc.doc.Views.ActiveView = pageview rs.AddText(text, pt, height=2.0, font='Courier new', justification=65537) #bottom left