def TextObjectText(object_id, text=None): """Returns or modifies the text string of a text object. Parameters: object_id = the identifier of a text object text [opt] = a new text string Returns: if text is not specified, the current string value if successful if text is specified, the previous string value if successful None if not successful, or on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select text") if rs.IsText(obj): rs.TextObjectText(obj, "Rhino") See Also: AddText IsText TextObjectFont TextObjectHeight TextObjectPlane TextObjectPoint TextObjectStyle """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() rc = annotation.Text if text: if not isinstance(text, str): text = str(text) annotation.Text = text id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def PointCloudHidePoints(object_id, hidden=[]): """Returns or modifies the hidden points of a point cloud object Parameters: object_id: the point cloud object's identifier hidden: list of hidden values if you want to hide certain points Returns: List of point cloud hidden states """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsHiddenFlags: rc = [item.Hidden for item in pc] if hidden is None: pc.ClearHiddenFlags() elif len(hidden) == pc.Count: for i in range(pc.Count): pc[i].Hidden = hidden[i] if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def TextObjectPoint(object_id, point=None): """Returns or modifies the location of a text object Parameters: object_id = the identifier of a text object point[opt] = the new text object location Returns: if point is not specified, the 3D point identifying the current location if point is specified, the 3D point identifying the previous location None if not successful, or on Error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select text") if rs.IsText(obj): rs.TextObjectPoint( obj, [0,0,0] ) See Also: AddText IsText TextObjectFont TextObjectHeight TextObjectPlane TextObjectStyle TextObjectText """ text = rhutil.coercegeometry(object_id, True) if not isinstance(text, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() plane = text.Plane rc = plane.Origin if point: plane.Origin = rhutil.coerce3dpoint(point, True) text.Plane = plane id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, text) scriptcontext.doc.Views.Redraw() return rc
def TextObjectHeight(object_id, height=None): """Returns or modifies the height of a text object Parameters: object_id = the identifier of a text object height[opt] = the new text height. Returns: if height is not specified, the current text height if height is specified, the previous text height None if not successful, or on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select text") if rs.IsText(obj): rs.TextObjectHeight( obj, 1.0 ) See Also: AddText IsText TextObjectFont TextObjectPlane TextObjectPoint TextObjectStyle TextObjectText """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() rc = annotation.TextHeight if height: annotation.TextHeight = height id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def TextObjectPlane(object_id, plane=None): """Returns or modifies the plane used by a text object Parameters: object_id = the identifier of a text object plane[opt] = the new text object plane Returns: if a plane is not specified, the current plane if successful if a plane is specified, the previous plane if successful None if not successful, or on Error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select text") if rs.IsText(obj): plane = rs.ViewCPlane("Top") rs.TextObjectPlane( obj, plane ) See Also: AddText IsText TextObjectFont TextObjectHeight TextObjectPoint TextObjectStyle TextObjectText """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() rc = annotation.Plane if plane: annotation.Plane = rhutil.coerceplane(plane, True) id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def TextDotText(object_id, text=None): """Returns or modifies the text on a text dot object Parameters: object_id =tThe identifier of a text dot object text [opt] = a new string for the dot Returns: If text is not specified, the current text dot text If text is specified, the previous text dot text None if not successful, or on error Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select text dot") if rs.IsTextDot(id): rs.TextDotText( id, "Rhino") See Also: AddTextDot IsTextDot TextDotPoint """ textdot = rhutil.coercegeometry(object_id, True) if isinstance(textdot, Rhino.Geometry.TextDot): rc = textdot.Text if text is not None: if not isinstance(text, str): text = str(text) textdot.Text = text id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, textdot) scriptcontext.doc.Views.Redraw() return rc
def TextObjectFont(object_id, font=None): """Returns of modifies the font used by a text object Parameters: object_id = the identifier of a text object font [opt] = the new font face name Returns: if a font is not specified, the current font face name if a font is specified, the previous font face name None if not successful, or on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select text") if rs.IsText(obj): rs.TextObjectFont(obj, "Arial") See Also: AddText IsText TextObjectHeight TextObjectPlane TextObjectPoint TextObjectStyle TextObjectText """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() fontdata = scriptcontext.doc.Fonts[annotation.FontIndex] if fontdata is None: return scriptcontext.errorhandler() rc = fontdata.FaceName if font: index = scriptcontext.doc.Fonts.FindOrCreate( font, fontdata.Bold, fontdata.Italic ) annotation.FontIndex = index id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def TextDotPoint(object_id, point=None): """Returns or modifies the location, or insertion point, on a text dot object Parameters: object_id = identifier of a text dot object point[opt] = A new 3D point location. Returns: If point is not specified, the current 3-D text dot location If point is specified, the previous 3-D text dot location None if not successful, or on error Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select text dot") if rs.IsTextDot(id): point = rs.TestDotPoint(id) rs.AddPoint( point ) rs.TextDotPoint(id, [0,0,0]) See Also: AddTextDot IsTextDot TextDotText """ textdot = rhutil.coercegeometry(object_id, True) if isinstance(textdot, Rhino.Geometry.TextDot): rc = textdot.Point if point: textdot.Point = rhutil.coerce3dpoint(point, True) id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, textdot) scriptcontext.doc.Views.Redraw() return rc
def TextDotHeight(object_id, height=None): """Returns or modified the font height of a text dot Parameters: object_id = identifier of a text dot object height[opt] = new font height Returns: If height is not specified, the current text dot height If height is specified, the previous text dot height None on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select text dot") if rs.IsTextDot(obj): rs.TextDotHeight(obj, 10.0) See Also: AddTextDot IsTextDot TextDotFont TextDotPoint TextDotText """ textdot = rhutil.coercegeometry(object_id, True) if isinstance(textdot, Rhino.Geometry.TextDot): rc = textdot.FontHeight if height and height>0: textdot.FontHeight = height id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, textdot) scriptcontext.doc.Views.Redraw() return rc
def PointCoordinates(object_id, point=None): """Returns or modifies the X, Y, and Z coordinates of a point object Parameters: object_id = The identifier of a point object point[opt] = A new 3D point location. Returns: If point is not specified, the current 3-D point location If point is specified, the previous 3-D point location Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select point", rs.filter.point) point = rs.PointCoordinates(id) See Also: AddPoint IsPoint """ point_geometry = rhutil.coercegeometry(object_id, True) if isinstance(point_geometry, Rhino.Geometry.Point): rc = point_geometry.Location if point: point = rhutil.coerce3dpoint(point, True) id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, point) scriptcontext.doc.Views.Redraw() return rc
def PointCloudPointColors(object_id, colors=[]): """Returns or modifies the point colors of a point cloud object Parameters: object_id: the point cloud object's identifier colors: list of color values if you want to adjust colors Returns: List of point cloud colors """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsColors: rc = [item.Color for item in pc] if colors is None: pc.ClearColors() elif len(colors) == pc.Count: for i in range(pc.Count): pc[i].Color = rhutil.coercecolor(colors[i]) if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def __objectbbox(object, xform): geom = rhutil.coercegeometry(object, False) if not geom: pt = rhutil.coerce3dpoint(object, True) return Rhino.Geometry.BoundingBox(pt,pt) if xform: return geom.GetBoundingBox(xform) return geom.GetBoundingBox(True)
def TextObjectStyle(object_id, style=None): """Returns or modifies the font style of a text object Parameters: object_id = the identifier of a text object style [opt] = the font style. Can be any of the following flags 0 = Normal 1 = Bold 2 = Italic Returns: if style is not specified, the current font style if style is specified, the previous font style None if not successful, or on Error """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() fontdata = scriptcontext.doc.Fonts[annotation.FontIndex] if fontdata is None: return scriptcontext.errorhandler() rc = 0 if fontdata.Bold: rc += 1 if fontdata.Italic: rc += 2 if style is not None and style!=rc: index = scriptcontext.doc.Fonts.FindOrCreate( fontdata.FaceName, (style&1)==1, (style&2)==2 ) annotation.FontIndex = index id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def PointCloudPoints(object_id): """Returns the points of a point cloud object Parameters: object_id: the point cloud object's identifier Returns: list of points if successful """ pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): return pc.GetPoints()
def IsPointCloud(object_id): """Verifies an object is a point cloud object. Parameters: object_id: the object's identifier Returns: True if the object with a given id is a point cloud """ pc = rhutil.coercegeometry(object_id) return isinstance(pc, Rhino.Geometry.PointCloud)
def IsClippingPlane(object_id): """Verifies that an object is a clipping plane object Parameters: object_id: the object's identifier Returns: True if the object with a given id is a clipping plane """ cp = rhutil.coercegeometry(object_id) return isinstance(cp, Rhino.Geometry.ClippingPlaneSurface)
def PointCloudHasPointColors(object_id): """Verifies that a point cloud has point colors Parameters: object_id: the point cloud object's identifier Returns: True if cloud has point colors, otherwise False """ pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): return pc.ContainsColors
def PointCloudHasHiddenPoints(object_id): """Verifies that a point cloud has hidden points Parameters: object_id: the point cloud object's identifier Returns: True if cloud has hidden points, otherwise False """ pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): return pc.HiddenPointCount>0
def IsTextDot(object_id): """Verifies an object is a text dot object. Parameters: object_id: the object's identifier Returns: True if the object with a given id is a text dot object """ td = rhutil.coercegeometry(object_id) return isinstance(td, Rhino.Geometry.TextDot)
def PointCloudCount(object_id): """Returns the point count of a point cloud object Parameters: object_id: the point cloud object's identifier Returns: number of points if successful None on error """ pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): return pc.PointCount return scriptcontext.errorhandler()
def PointClosestObject(point, object_ids): """Finds the object that is closest to a test point Parameters: point = point to test object_id = identifiers of one or more objects Returns: (closest object_id, point on object) on success None on failure """ object_ids = rhutil.coerceguidlist(object_ids) point = rhutil.coerce3dpoint(point, True) closest = None for id in object_ids: geom = rhutil.coercegeometry(id, True) point_geometry = geom if isinstance(point_geometry, Rhino.Geometry.Point): distance = point.DistanceTo( point_geometry.Location ) if closest is None or distance<closest[0]: closest = distance, id, point_geometry.Location continue point_cloud = geom if isinstance(point_cloud, Rhino.Geometry.PointCloud): index = point_cloud.ClosestPoint(point) if index>=0: distance = point.DistanceTo( point_cloud[index].Location ) if closest is None or distance<closest[0]: closest = distance, id, point_cloud[index].Location continue curve = geom if isinstance(curve, Rhino.Geometry.Curve): rc, t = curve.ClosestPoint(point) if rc: distance = point.DistanceTo( curve.PointAt(t) ) if closest is None or distance<closest[0]: closest = distance, id, curve.PointAt(t) continue brep = geom if isinstance(brep, Rhino.Geometry.Brep): brep_closest = brep.ClosestPoint(point) distance = point.DistanceTo( brep_closest ) if closest is None or distance<closest[0]: closest = distance, id, brep_closest continue mesh = geom if isinstance(mesh, Rhino.Geometry.Mesh): mesh_closest = mesh.ClosestPoint(point) distance = point.DistanceTo( mesh_closest ) if closest is None or distance<closest[0]: closest = distance, id, mesh_closest continue if not closest: return scriptcontext.errorhandler() return closest[1], closest[2]
def PointCloudCount(object_id): """Returns the point count of a point cloud object Parameters: object_id: the point cloud object's identifier Returns: number of points if successful Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select point cloud", rs.filter.pointcloud) print "Point count:", rs.PointCloudCount(id) See Also: AddPointCloud IsPointCloud PointCloudPoints """ pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): return pc.Count
def PointCoordinates(object_id, point=None): """Returns or modifies the X, Y, and Z coordinates of a point object Parameters: object_id = The identifier of a point object point[opt] = A new 3D point location. Returns: If point is not specified, the current 3-D point location If point is specified, the previous 3-D point location """ point_geometry = rhutil.coercegeometry(object_id, True) if isinstance(point_geometry, Rhino.Geometry.Point): rc = point_geometry.Location if point: point = rhutil.coerce3dpoint(point, True) id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, point) scriptcontext.doc.Views.Redraw() return rc
def IsTextDot(object_id): """Verifies an object is a text dot object. Parameters: object_id: the object's identifier Returns: True if the object with a given id is a text dot object Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select a text dot object") if rs.IsTextDot(id): print "The object is a text dot object." else: print "The object is not a text dot object." See Also: AddTextDot """ td = rhutil.coercegeometry(object_id) return isinstance(td, Rhino.Geometry.TextDot)
def IsClippingPlane(object_id): """Verifies that an object is a clipping plane object Parameters: object_id: the object's identifier Returns: True if the object with a given id is a clipping plane Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select a clipping plane") if rs.IsClippingPlane(id): print "The object is a clipping plane." else: print "The object is not a clipping plane." See Also: AddClippingPlane """ cp = rhutil.coercegeometry(object_id) return isinstance(cp, Rhino.Geometry.ClippingPlaneSurface)
def IsPoint(object_id): """Verifies an object is a point object. Parameters: object_id: the object's identifier Returns: True if the object with a given id is a point Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select a point") if rs.IsPoint(id): print "The object is a point." else: print "The object is not a point." See Also: AddPoint PointCoordinates """ p = rhutil.coercegeometry(object_id) return isinstance(p, Rhino.Geometry.Point)
def TextDotPoint(object_id, point=None): """Returns or modifies the location, or insertion point, on a text dot object Parameters: object_id = identifier of a text dot object point[opt] = A new 3D point location. Returns: If point is not specified, the current 3-D text dot location If point is specified, the previous 3-D text dot location None if not successful, or on error """ textdot = rhutil.coercegeometry(object_id, True) if isinstance(textdot, Rhino.Geometry.TextDot): rc = textdot.Point if point: textdot.Point = rhutil.coerce3dpoint(point, True) id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, textdot) scriptcontext.doc.Views.Redraw() return rc
def TextDotFont(object_id, fontface=None): """Returns or modified the font of a text dot Parameters: object_id = identifier of a text dot object fontface[opt] = new font face name Returns: If font is not specified, the current text dot font If font is specified, the previous text dot font None on error """ textdot = rhutil.coercegeometry(object_id, True) if isinstance(textdot, Rhino.Geometry.TextDot): rc = textdot.FontFace if fontface: textdot.FontFace = fontface id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, textdot) scriptcontext.doc.Views.Redraw() return rc
def TextDotHeight(object_id, height=None): """Returns or modified the font height of a text dot Parameters: object_id = identifier of a text dot object height[opt] = new font height Returns: If height is not specified, the current text dot height If height is specified, the previous text dot height None on error """ textdot = rhutil.coercegeometry(object_id, True) if isinstance(textdot, Rhino.Geometry.TextDot): rc = textdot.FontHeight if height and height > 0: textdot.FontHeight = height id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, textdot) scriptcontext.doc.Views.Redraw() return rc
def TextObjectPlane(object_id, plane=None): """Returns or modifies the plane used by a text object Parameters: object_id = the identifier of a text object plane[opt] = the new text object plane Returns: if a plane is not specified, the current plane if successful if a plane is specified, the previous plane if successful None if not successful, or on Error """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() rc = annotation.Plane if plane: annotation.Plane = rhutil.coerceplane(plane, True) id = rhutil.coerceid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def PointCloudPointColors(object_id, colors=[]): """Returns or modifies the point colors of a point cloud object Parameters: object_id (guid): the point cloud object's identifier colors ([color, ...]) list of color values if you want to adjust colors Returns: list(color, ...): List of point cloud colors Example: import rhinoscriptsyntax as rs import random def RandomColor(): red = random.randint(0,255) green = random.randint(0,255) blue = random.randint(0,255) return rs.coercecolor((red,green,blue)) obj = rs.GetObject("Select point cloud", rs.filter.pointcloud) if obj: colors = [RandomColor() for i in range(rs.PointCloudCount(obj))] rs.PointCloudColors(obj, colors) See Also: PointCloudHasHiddenPoints PointCloudHasPointColors PointCloudHidePoints """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsColors: rc = [item.Color for item in pc] if colors is None: pc.ClearColors() elif len(colors) == pc.Count: for i in range(pc.Count): pc[i].Color = rhutil.coercecolor(colors[i]) if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def TextDotText(object_id, text=None): """Returns or modifies the text on a text dot object Parameters: object_id =tThe identifier of a text dot object text [opt] = a new string for the dot Returns: If text is not specified, the current text dot text If text is specified, the previous text dot text None if not successful, or on error """ textdot = rhutil.coercegeometry(object_id, True) if isinstance(textdot, Rhino.Geometry.TextDot): rc = textdot.Text if text is not None: if not isinstance(text, str): text = str(text) textdot.Text = text id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, textdot) scriptcontext.doc.Views.Redraw() return rc return scriptcontext.errorhandler()
def TextObjectText(object_id, text=None): """Returns or modifies the text string of a text object. Parameters: object_id = the identifier of a text object text [opt] = a new text string Returns: if text is not specified, the current string value if successful if text is specified, the previous string value if successful None if not successful, or on error """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() rc = annotation.Text if text: if not isinstance(text, str): text = str(text) annotation.Text = text id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def PointCloudHasHiddenPoints(object_id): """Verifies that a point cloud has hidden points Parameters: object_id (guid): the point cloud object's identifier Returns: bool: True if cloud has hidden points, otherwise False Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select a point cloud", rs.filter.pointcloud) if rs.PointCloudHasHiddenPoints(obj): print "The point cloud has hidden points." else: print "The point cloud has no hidden points." See Also: PointCloudHasPointColors PointCloudHidePoints PointCloudPointColors """ pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): return pc.HiddenPointCount > 0
def TextObjectText(object_id, text=None): """Returns or modifies the text string of a text object. Parameters: object_id (guid): the identifier of a text object text (str, optional): a new text string Returns: str: if text is not specified, the current string value if successful str: if text is specified, the previous string value if successful None: if not successful, or on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select text") if rs.IsText(obj): rs.TextObjectText(obj, "Rhino") See Also: AddText IsText TextObjectFont TextObjectHeight TextObjectPlane TextObjectPoint TextObjectStyle """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() rc = annotation.Text if text: if not isinstance(text, str): text = str(text) isBold = annotation.IsAllBold() isItalic = annotation.IsAllItalic() isUnderlined = annotation.IsAllUnderlined() annotation.Text = text if isBold: annotation.SetBold(True) if isItalic: annotation.SetItalic(True) if isUnderlined: annotation.SetUnderline(True) id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def PointCloudHidePoints(object_id, hidden=[]): """Returns or modifies the hidden points of a point cloud object Parameters: object_id: the point cloud object's identifier hidden: list of hidden values if you want to hide certain points Returns: List of point cloud hidden states """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsHiddenFlags: rc = [item.Hidden for item in pc] if hidden is None: pc.ClearHiddenFlags() elif len(hidden)==pc.Count: for i in range(pc.Count): pc[i].Hidden = hidden[i] if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def PointCloudPointColors(object_id, colors=[]): """Returns or modifies the point colors of a point cloud object Parameters: object_id: the point cloud object's identifier colors: list of color values if you want to adjust colors Returns: List of point cloud colors """ rhobj = rhutil.coercerhinoobject(object_id) if rhobj: pc = rhobj.Geometry else: pc = rhutil.coercegeometry(object_id, True) if isinstance(pc, Rhino.Geometry.PointCloud): rc = None if pc.ContainsColors: rc = [item.Color for item in pc] if colors is None: pc.ClearColors() elif len(colors)==pc.Count: for i in range(pc.Count): pc[i].Color = rhutil.coercecolor(colors[i]) if rhobj: rhobj.CommitChanges() scriptcontext.doc.Views.Redraw() return rc
def TextObjectPoint(object_id, point=None): """Returns or modifies the location of a text object Parameters: object_id = the identifier of a text object point[opt] = the new text object location Returns: if point is not specified, the 3D point identifying the current location if point is specified, the 3D point identifying the previous location None if not successful, or on Error """ text = rhutil.coercegeometry(object_id, True) if not isinstance(text, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() plane = text.Plane rc = plane.Origin if point: plane.Origin = rhutil.coerce3dpoint(point, True) text.Plane = plane id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, text) scriptcontext.doc.Views.Redraw() return rc
def TextObjectFont(object_id, font=None): """Returns of modifies the font used by a text object Parameters: object_id = the identifier of a text object font [opt] = the new font face name Returns: if a font is not specified, the current font face name if a font is specified, the previous font face name None if not successful, or on error """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() fontdata = scriptcontext.doc.Fonts[annotation.FontIndex] if fontdata is None: return scriptcontext.errorhandler() rc = fontdata.FaceName if font: index = scriptcontext.doc.Fonts.FindOrCreate( font, fontdata.Bold, fontdata.Italic ) annotation.FontIndex = index id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def TextObjectFont(object_id, font=None): """Returns of modifies the font used by a text object Parameters: object_id = the identifier of a text object font [opt] = the new font face name Returns: if a font is not specified, the current font face name if a font is specified, the previous font face name None if not successful, or on error Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select text") if rs.IsText(obj): rs.TextObjectFont(obj, "Arial") See Also: AddText IsText TextObjectHeight TextObjectPlane TextObjectPoint TextObjectStyle TextObjectText """ annotation = rhutil.coercegeometry(object_id, True) if not isinstance(annotation, Rhino.Geometry.TextEntity): return scriptcontext.errorhandler() fontdata = scriptcontext.doc.Fonts[annotation.FontIndex] if fontdata is None: return scriptcontext.errorhandler() rc = fontdata.FaceName if font: index = scriptcontext.doc.Fonts.FindOrCreate(font, fontdata.Bold, fontdata.Italic) annotation.FontIndex = index id = rhutil.coerceguid(object_id, True) scriptcontext.doc.Objects.Replace(id, annotation) scriptcontext.doc.Views.Redraw() return rc
def PointClosestObject(point, object_ids): """Finds the object that is closest to a test point Parameters: point = point to test object_id = identifiers of one or more objects Returns: (closest object_id, point on object) on success None on failure Example: import rhinoscriptsyntax as rs objs = rs.GetObjects("Select target objects for closest point", 63) if objs: point = rs.GetPoint("Test point") if point: results = rs.PointClosestObject(point, objs) if results: print "Object id:", results[0] rs.AddPoint( results[1] ) See Also: CurveClosestObject """ object_ids = rhutil.coerceguidlist(object_ids) point = rhutil.coerce3dpoint(point, True) closest = None for id in object_ids: geom = rhutil.coercegeometry(id, True) point_geometry = geom if isinstance(point_geometry, Rhino.Geometry.Point): distance = point.DistanceTo(point_geometry.Location) if closest is None or distance < closest[0]: closest = distance, id, point_geometry.Location continue point_cloud = geom if isinstance(point_cloud, Rhino.Geometry.PointCloud): index = point_cloud.ClosestPoint(point) if index >= 0: distance = point.DistanceTo(point_cloud[index].Location) if closest is None or distance < closest[0]: closest = distance, id, point_cloud[index].Location continue curve = geom if isinstance(curve, Rhino.Geometry.Curve): rc, t = curve.ClosestPoint(point) if rc: distance = point.DistanceTo(curve.PointAt(t)) if closest is None or distance < closest[0]: closest = distance, id, curve.PointAt(t) continue brep = geom if isinstance(brep, Rhino.Geometry.Brep): brep_closest = brep.ClosestPoint(point) distance = point.DistanceTo(brep_closest) if closest is None or distance < closest[0]: closest = distance, id, brep_closest continue mesh = geom if isinstance(mesh, Rhino.Geometry.Mesh): mesh_closest = mesh.ClosestPoint(point) distance = point.DistanceTo(mesh_closest) if closest is None or distance < closest[0]: closest = distance, id, mesh_closest continue if closest: return closest[1], closest[2]
def __coercelight(id, raise_if_missing=False): light = rhutil.coercegeometry(id) if isinstance(light, Rhino.Geometry.Light): return light if raise_if_missing: raise ValueError("unable to retrieve light from %s"%id)
def __objectbbox(object, xform): geom = rhutil.coercegeometry(object, True) if xform: return geom.GetBoundingBox(xform) return geom.GetBoundingBox(True)