def AddRectangularLight(origin, width_point, height_point): """Adds a new rectangular light object to the document Parameters: origin = 3d origin point of the light width_point = 3d width and direction point of the light height_point = 3d height and direction point of the light Returns: identifier of the new object if successful """ origin = rhutil.coerce3dpoint(origin, True) ptx = rhutil.coerce3dpoint(width_point, True) pty = rhutil.coerce3dpoint(height_point, True) length = pty-origin width = ptx-origin normal = Rhino.Geometry.Vector3d.CrossProduct(width, length) normal.Unitize() light = Rhino.Geometry.Light() light.LightStyle = Rhino.Geometry.LightStyle.WorldRectangular light.Location = origin light.Width = width light.Length = length light.Direction = normal index = scriptcontext.doc.Lights.Add(light) if index<0: raise Exception("unable to add light to LightTable") rc = scriptcontext.doc.Lights[index].Id scriptcontext.doc.Views.Redraw() return rc
def AddSpotLight(origin, radius, apex_point): """Adds a new spot light object to the document Parameters: origin = 3d origin point of the light radius = radius of the cone apex_point = 3d apex point of the light Returns: identifier of the new object Example: import rhinoscriptsyntax as rs radius = 5.0 origin = rs.GetPoint("Base of cone") if origin: apex = rs.GetPoint("End of cone", origin) if apex: rs.AddSpotLight(origin, radius, apex) See Also: IsSpotLight SpotLightHardness SpotLightShadowIntensity """ origin = rhutil.coerce3dpoint(origin, True) apex_point = rhutil.coerce3dpoint(apex_point, True) if radius<0: radius=1.0 light = Rhino.Geometry.Light() light.LightStyle = Rhino.Geometry.LightStyle.WorldSpot light.Location = apex_point light.Direction = origin-apex_point light.SpotAngleRadians = math.atan(radius / (light.Direction.Length)) light.HotSpot = 0.50 index = scriptcontext.doc.Lights.Add(light) if index<0: raise Exception("unable to add light to LightTable") rc = scriptcontext.doc.Lights[index].Id scriptcontext.doc.Views.Redraw() return rc
def WindowPick(corner1, corner2, view=None, select=False, in_window=True): """Picks objects using either a window or crossing selection Parameters: corner1, corner2 = corners of selection window view[opt] = view to perform the selection in select[opt] = select picked objects in_window[opt] = if False, then a crossing window selection is performed Returns: list of object ids on success Example: import rhinoscriptsyntax as rs rs.WindowPick((0,0,0), (0,0,0), None, True) See Also: """ viewport = __viewhelper(view).MainViewport screen1 = Rhino.Geometry.Point2d(rhutil.coerce3dpoint(corner1, True)) screen2 = Rhino.Geometry.Point2d(rhutil.coerce3dpoint(corner2, True)) xf = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World, Rhino.DocObjects.CoordinateSystem.Screen) screen1.Transform(xf) screen2.Transform(xf) objects = None filter = Rhino.DocObjects.ObjectType.AnyObject if in_window: objects = scriptcontext.doc.Objects.FindByWindowRegion(viewport, screen1, screen2, True, filter) else: objects = scriptcontext.doc.Objects.FindByCrossingWindowRegion(viewport, screen1, screen2, True, filter) if objects: rc = [] for rhobj in objects: rc.append(rhobj.Id) if select: rhobj.Select(True) if select: scriptcontext.doc.Views.Redraw() return rc
def AddAlignedDimension(start_point, end_point, point_on_dimension_line, style=None): """Adds an aligned dimension object to the document. An aligned dimension is a linear dimension lined up with two points Parameters: start_point: first point of dimension end_point: second point of dimension point_on_dimension_line: location point of dimension line style[opt]: name of dimension style Returns: identifier of new dimension on success None on error """ start = rhutil.coerce3dpoint(start_point, True) end = rhutil.coerce3dpoint(end_point, True) onpoint = rhutil.coerce3dpoint(point_on_dimension_line, True) plane = Rhino.Geometry.Plane(start, end, onpoint) success, s, t = plane.ClosestParameter(start) start = Rhino.Geometry.Point2d(s,t) success, s, t = plane.ClosestParameter(end) end = Rhino.Geometry.Point2d(s,t) success, s, t = plane.ClosestParameter(onpoint) onpoint = Rhino.Geometry.Point2d(s,t) ldim = Rhino.Geometry.LinearDimension(plane, start, end, onpoint) if not ldim: return scriptcontext.errorhandler() ldim.Aligned = True rc = scriptcontext.doc.Objects.AddLinearDimension(ldim) if rc==System.Guid.Empty: raise Exception("unable to add dimension to document") scriptcontext.doc.Views.Redraw() return rc
def AddDirectionalLight(start_point, end_point): """Adds a new directional light object to the document Parameters: start_point: starting point of the light end_point: ending point and direction of the light Returns: identifier of the new object if successful Example: import rhinoscriptsyntax as rs end = rs.GetPoint("End of light vector direction") if end: start = rs.GetPoint("Start of light vector direction", end) if start: rs.AddDirectionalLight( start, end ) See Also: IsDirectionalLight """ start = rhutil.coerce3dpoint(start_point, True) end = rhutil.coerce3dpoint(end_point, True) light = Rhino.Geometry.Light() light.LightStyle = Rhino.Geometry.LightStyle.WorldDirectional light.Location = start light.Direction = end-start index = scriptcontext.doc.Lights.Add(light) if index<0: raise Exception("unable to add light to LightTable") rc = scriptcontext.doc.Lights[index].Id scriptcontext.doc.Views.Redraw() return rc
def GetAngle(point=None, reference_point=None, default_angle_degrees=0, message=None): """Pause for user input of an angle Parameters: point(opt) = starting, or base point reference_point(opt) = if specified, the reference angle is calculated from it and the base point default_angle_degrees(opt) = a default angle value specified message(opt) = a prompt to display Returns: angle in degree if successful, None on error Example: import rhinoscriptsyntax as rs point = rs.GetPoint("Base point") if point: reference = rs.GetPoint("Reference point", point) if reference: angle = rs.GetAngle(point, reference) if angle!=None: print "Angle:", angle See Also: GetDistance """ point = rhutil.coerce3dpoint(point) if not point: point = Rhino.Geometry.Point3d.Unset reference_point = rhutil.coerce3dpoint(reference_point) if not reference_point: reference_point = Rhino.Geometry.Point3d.Unset default_angle = math.radians(default_angle_degrees) rc, angle = Rhino.Input.RhinoGet.GetAngle(message, point, reference_point, default_angle) if rc==Rhino.Commands.Result.Success: return math.degrees(angle)
def ShearObjects(object_ids, origin, reference_point, angle_degrees, copy=False): """Shears one or more objects Parameters: object_ids: The identifiers objects to shear origin, reference_point: origin/reference point of the shear transformation Returns: List of identifiers of the sheared objects if successful """ origin = rhutil.coerce3dpoint(origin, True) reference_point = rhutil.coerce3dpoint(reference_point, True) if (origin-reference_point).IsTiny(): return None plane = scriptcontext.doc.Views.ActiveView.MainViewport.ConstructionPlane() frame = Rhino.Geometry.Plane(plane) frame.Origin = origin frame.ZAxis = plane.Normal yaxis = reference_point-origin yaxis.Unitize() frame.YAxis = yaxis xaxis = Rhino.Geometry.Vector3d.CrossProduct(frame.ZAxis, frame.YAxis) xaxis.Unitize() frame.XAxis = xaxis world_plane = Rhino.Geometry.Plane.WorldXY cob = Rhino.Geometry.Transform.ChangeBasis(world_plane, frame) shear2d = Rhino.Geometry.Transform.Identity shear2d[0,1] = math.tan(math.radians(angle_degrees)) cobinv = Rhino.Geometry.Transform.ChangeBasis(frame, world_plane) xf = cobinv * shear2d * cob rc = TransformObjects(object_ids, xf, copy) return rc
def PointCompare(point1, point2, tolerance=None): """Compares two 3D points Parameters: point1, point2 = the points to compare tolerance [opt] = tolerance to use for comparison. If omitted, Rhino's internal zero tolerance is used Returns: True or False Example: import rhinoscriptsyntax as rs point1 = (1,1,1) point2 = (2,2,2) print rs.PointCompare(point1, point2) See Also: PointAdd PointDivide PointScale PointSubtract PointTransform """ point1 = rhutil.coerce3dpoint(point1, True) point2 = rhutil.coerce3dpoint(point2, True) if tolerance is None: tolerance = Rhino.RhinoMath.ZeroTolerance vector = point2-point1 return vector.IsTiny(tolerance)
def XformScale(scale, point=None): """Creates a scale transformation Parameters: scale = single number, list of 3 numbers, Point3d, or Vector3d point[opt] = center of scale. If omitted, world origin is used Returns: The 4x4 transformation matrix on success None on error Example: import rhinoscriptsyntax as rs objs = rs.GetObjects("Select objects to scale") if objs: xform = rs.XformScale( (3.0,1.0,1.0) ) rs.TransformObjects( objs, xform, True) See Also: XformMirror XformPlanarProjection XformRotation XformShear XformTranslation """ factor = rhutil.coerce3dpoint(scale) if factor is None: if type(scale) is int or type(scale) is float: factor = (scale,scale,scale) if factor is None: return scriptcontext.errorhandler() if point: point = rhutil.coerce3dpoint(point, True) else: point = Rhino.Geometry.Point3d.Origin plane = Rhino.Geometry.Plane(point, Rhino.Geometry.Vector3d.ZAxis); xf = Rhino.Geometry.Transform.Scale(plane, factor[0], factor[1], factor[2]) return xf
def VectorCreate(to_point, from_point): """Creates a vector from two 3D points Parameters: to_point, from_point = the points defining the vector Returns: the resulting vector if successful """ to_point = rhutil.coerce3dpoint(to_point, True) from_point = rhutil.coerce3dpoint(from_point, True) return to_point-from_point
def PointAdd(point1, point2): """Adds a 3D point or a 3D vector to a 3D point Parameters: point1, point2 = the points to add Returns: the resulting 3D point if successful """ point1 = rhutil.coerce3dpoint(point1, True) point2 = rhutil.coerce3dpoint(point2, True) return point1+point2
def PointSubtract(point1, point2): """Subtracts a 3D point or a 3D vector from a 3D point Parameters: point1, point2 = the points to subtract Returns: the resulting 3D point if successful """ point1 = rhutil.coerce3dpoint(point1, True) point2 = rhutil.coerce3dpoint(point2, True) v = point1-point2 return Rhino.Geometry.Point3d(v)
def PlaneFromPoints(origin, x, y): """Creates a plane from three non-colinear points Parameters: origin = origin point of the plane x, y = points on the plane's x and y axes """ origin = rhutil.coerce3dpoint(origin, True) x = rhutil.coerce3dpoint(x, True) y = rhutil.coerce3dpoint(y, True) plane = Rhino.Geometry.Plane(origin, x, y) if plane.IsValid: return plane
def PointCompare(point1, point2, tolerance=None): """Compares two 3D points Parameters: point1, point2 = the points to compare tolerance [opt] = tolerance to use for comparison. If omitted, Rhino's internal zero tolerance is used Returns: True or False """ point1 = rhutil.coerce3dpoint(point1, True) point2 = rhutil.coerce3dpoint(point2, True) if tolerance is None: tolerance = Rhino.RhinoMath.ZeroTolerance vector = point2-point1 return vector.IsTiny(tolerance)
def AddLinearDimension(start_point, end_point, point_on_dimension_line): """Adds a linear dimension to the document Returns: identifier of the new object on success None on error """ start = rhutil.coerce3dpoint(start_point, True) end = rhutil.coerce3dpoint(end_point, True) onpoint = rhutil.coerce3dpoint(point_on_dimension_line, True) ldim = Rhino.Geometry.LinearDimension.FromPoints(start, end, onpoint) if not ldim: return scriptcontext.errorhandler() rc = scriptcontext.doc.Objects.AddLinearDimension(ldim) if rc==System.Guid.Empty: raise Exception("unable to add dimension to document") 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 PlaneFromNormal(origin, normal, xaxis=None): """Creates a plane from an origin point and a normal direction vector. Parameters: origin (point): A 3D point identifying the origin of the plane. normal (vector): A 3D vector identifying the normal direction of the plane. xaxis (vector, optional): optional vector defining the plane's x-axis Returns: plane: The plane if successful. Example: import rhinoscriptsyntax as rs origin = rs.GetPoint("CPlane origin") if origin: direction = rs.GetPoint("CPlane direction") if direction: normal = direction - origin normal = rs.VectorUnitize(normal) rs.ViewCPlane( None, rs.PlaneFromNormal(origin, normal) ) See Also: MovePlane PlaneFromFrame PlaneFromPoints RotatePlane """ origin = rhutil.coerce3dpoint(origin, True) normal = rhutil.coerce3dvector(normal, True) rc = Rhino.Geometry.Plane(origin, normal) if xaxis: xaxis = rhutil.coerce3dvector(xaxis, True) xaxis = Rhino.Geometry.Vector3d(xaxis)#prevent original xaxis parameter from being unitized too xaxis.Unitize() yaxis = Rhino.Geometry.Vector3d.CrossProduct(rc.Normal, xaxis) rc = Rhino.Geometry.Plane(origin, xaxis, yaxis) return rc
def PlaneClosestPoint(plane, point, return_point=True): """Returns the point on a plane that is closest to a test point. Parameters: plane (plane): The plane point (point): The 3-D point to test. return_point (bool, optional): If omitted or True, then the point on the plane that is closest to the test point is returned. If False, then the parameter of the point on the plane that is closest to the test point is returned. Returns: point: If return_point is omitted or True, then the 3-D point point: If return_point is False, then an array containing the U,V parameters of the point None: if not successful, or on error. Example: import rhinoscriptsyntax as rs point = rs.GetPoint("Point to test") if point: plane = rs.ViewCPlane() if plane: print rs.PlaneClosestPoint(plane, point) See Also: DistanceToPlane EvaluatePlane """ plane = rhutil.coerceplane(plane, True) point = rhutil.coerce3dpoint(point, True) if return_point: return plane.ClosestPoint(point) else: rc, s, t = plane.ClosestParameter(point) if rc: return s, t
def IsPointOnMesh(object_id, point): """Verifies a point is on a mesh Parameters: object_id (guid): identifier of a mesh object point (point): test point Returns: bool: True if successful, otherwise False. None: on error. Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select a mesh") if rs.IsMesh(obj): point = rs.GetPointOnMesh(strObject, "Pick a test point") if point: if rs.IsPointOnMesh(obj, point): print "The point is on the mesh" else: print "The point is not on the mesh" See Also: IsMesh MeshClosestPoint """ mesh = rhutil.coercemesh(object_id, True) point = rhutil.coerce3dpoint(point, True) max_distance = Rhino.RhinoMath.SqrtEpsilon face, pt = mesh.ClosestPoint(point, max_distance) return face >= 0
def MeshClosestPoint(object_id, point, maximum_distance=None): """Returns the point on a mesh that is closest to a test point Parameters: object_id = identifier of a mesh object point = point to test maximum_distance[opt] = upper bound used for closest point calculation. If you are only interested in finding a point Q on the mesh when point.DistanceTo(Q) < maximum_distance, then set maximum_distance to that value Returns: Tuple containing the results of the calculation where element[0] = the 3-D point on the mesh element[1] = the index of the mesh face on which the 3-D point lies None on error Example: import rhinocriptsyntax as rs obj = rs.GetObject("Select mesh", rs.filter.mesh) point = rs.GetPoint("Pick test point") intersect = rs.MeshClosestPoint(obj, point) if intersect: rs.AddPoint(intersect) See Also: MeshFaceCount MeshFaces """ mesh = rhutil.coercemesh(object_id, True) point = rhutil.coerce3dpoint(point, True) tolerance=maximum_distance if maximum_distance else 0.0 face, closest_point = mesh.ClosestPoint(point, tolerance) if face<0: return scriptcontext.errorhandler() return closest_point, face
def GetRectangle(mode=0, base_point=None, prompt1=None, prompt2=None, prompt3=None): """Pauses for user input of a rectangle Parameters: mode[opt] = The rectangle selection mode. The modes are as follows 0 = All modes 1 = Corner - a rectangle is created by picking two corner points 2 = 3Point - a rectangle is created by picking three points 3 = Vertical - a vertical rectangle is created by picking three points 4 = Center - a rectangle is created by picking a center point and a corner point base_point[opt] = a 3d base point prompt1, prompt2, prompt3 = optional prompts Returns: a tuple of four 3d points that define the corners of the rectangle None on error """ mode = System.Enum.ToObject( Rhino.Input.GetBoxMode, mode ) base_point = rhutil.coerce3dpoint(base_point) if( base_point==None ): base_point = Rhino.Geometry.Point3d.Unset prompts = ["", "", ""] if prompt1: prompts[0] = prompt1 if prompt2: prompts[1] = prompt2 if prompt3: prompts[2] = prompt3 rc, corners = Rhino.Input.RhinoGet.GetRectangle(mode, base_point, prompts) if rc==Rhino.Commands.Result.Success: return corners return None
def GetBox(mode=0, base_point=None, prompt1=None, prompt2=None, prompt3=None): """Pauses for user input of a box Parameters: mode (number): The box selection mode. 0 = All modes 1 = Corner. The base rectangle is created by picking two corner points 2 = 3-Point. The base rectangle is created by picking three points 3 = Vertical. The base vertical rectangle is created by picking three points. 4 = Center. The base rectangle is created by picking a center point and a corner point base_point (point, optional): optional 3D base point prompt1, prompt2, prompt3 (str, optional): optional prompts to set Returns: list(point, ...): list of eight Point3d that define the corners of the box on success None: is not successful, or on error Example: import rhinoscriptsyntax as rs box = rs.GetBox() if box: for i, pt in enumerate(box): rs.AddTextDot( i, pt ) See Also: GetRectangle """ base_point = rhutil.coerce3dpoint(base_point) if base_point is None: base_point = Rhino.Geometry.Point3d.Unset rc, box = Rhino.Input.RhinoGet.GetBox(mode, base_point, prompt1, prompt2, prompt3) if rc==Rhino.Commands.Result.Success: return tuple(box.GetCorners())
def PopupMenu(items, modes=None, point=None, view=None): """Display a context-style popup menu. The popup menu can appear almost anywhere, and can be dismissed by clicking the left or right mouse buttons Parameters: items ([str, ...]): list of strings representing the menu items. An empty string or None will create a separator modes ([number, ...]): List of numbers identifying the display modes. If omitted, all modes are enabled. 0 = menu item is enabled 1 = menu item is disabled 2 = menu item is checked 3 = menu item is disabled and checked point (point, optional): a 3D point where the menu item will appear. If omitted, the menu will appear at the current cursor position view (str, optional): if point is specified, the view in which the point is computed. If omitted, the active view is used Returns: number: index of the menu item picked or -1 if no menu item was picked Example: import rhinoscriptsyntax as rs items = "Line", "", "Circle", "Arc" modes = 2,0,0,0 rs.PopupMenu(items, modes) See Also: """ screen_point = System.Windows.Forms.Cursor.Position if point: point = rhutil.coerce3dpoint(point) view = __viewhelper(view) viewport = view.ActiveViewport point2d = viewport.WorldToClient(point) screen_point = viewport.ClientToScreen(point2d) return Rhino.UI.Dialogs.ShowContextMenu(items, screen_point, modes);
def GetLine(mode=0, point=None, message1=None, message2=None, message3=None): """Prompts the user to pick points that define a line Parameters: mode[opt] = line definition mode. See help file for details point[opt] = optional starting point message1, message2, message3 = optional prompts Returns: Tuple of two points on success None on error Example: import rhinoscriptsyntax as rs line = rs.GetLine() if line: rs.AddLine( line[0], line[1] ) See Also: GetBox GetPoint GetRectangle """ gl = Rhino.Input.Custom.GetLine() if mode == 0: gl.EnableAllVariations(True) else: gl.GetLineMode = System.Enum.ToObject(Rhino.Input.Custom.GetLineMode, mode - 1) if point: point = rhutil.coerce3dpoint(point) gl.SetFirstPoint(point) if message1: gl.FirstPointPrompt = message1 if message2: gl.MidPointPrompt = message2 if message3: gl.SecondPointPrompt = message3 rc, line = gl.Get() if rc == Rhino.Commands.Result.Success: return line.From, line.To
def PopupMenu(items, modes=None, point=None, view=None): """Displays a user defined, context-style popup menu. The popup menu can appear almost anywhere, and it can be dismissed by either clicking the left or right mouse buttons Parameters: items = list of strings representing the menu items. An empty string or None will create a separator modes[opt] = List of numbers identifying the display modes. If omitted, all modes are enabled. 0 = menu item is enabled 1 = menu item is disabled 2 = menu item is checked 3 = menu item is disabled and checked point[opt] = a 3D point where the menu item will appear. If omitted, the menu will appear at the current cursor position view[opt] = if point is specified, the view in which the point is computed. If omitted, the active view is used Returns: index of the menu item picked or -1 if no menu item was picked """ screen_point = System.Windows.Forms.Cursor.Position if point: point = rhutil.coerce3dpoint(point) view = __viewhelper(view) viewport = view.ActiveViewport point2d = viewport.WorldToClient(point) screen_point = viewport.ClientToScreen(point2d) return Rhino.UI.Dialogs.ShowContextMenu(items, screen_point, modes)
def GetRectangle(mode=0, base_point=None, prompt1=None, prompt2=None, prompt3=None): """Pauses for user input of a rectangle Parameters: mode[opt] = The rectangle selection mode. The modes are as follows 0 = All modes 1 = Corner - a rectangle is created by picking two corner points 2 = 3Point - a rectangle is created by picking three points 3 = Vertical - a vertical rectangle is created by picking three points 4 = Center - a rectangle is created by picking a center point and a corner point base_point[opt] = a 3d base point prompt1, prompt2, prompt3 = optional prompts Returns: a tuple of four 3d points that define the corners of the rectangle None on error """ mode = System.Enum.ToObject(Rhino.Input.GetBoxMode, mode) base_point = rhutil.coerce3dpoint(base_point) if (base_point == None): base_point = Rhino.Geometry.Point3d.Unset prompts = ["", "", ""] if prompt1: prompts[0] = prompt1 if prompt2: prompts[1] = prompt2 if prompt3: prompts[2] = prompt3 rc, corners = Rhino.Input.RhinoGet.GetRectangle(mode, base_point, prompts) if rc == Rhino.Commands.Result.Success: return corners return None
def GetPoint(message=None, base_point=None, distance=None, in_plane=False): """Pauses for user input of a point. Parameters: message [opt] = A prompt or message. base_point [opt] = list of 3 numbers or Point3d identifying a starting, or base point distance [opt] = constraining distance. If distance is specified, basePoint must also be sepcified. in_plane [opt] = constrains the point selections to the active construction plane. Returns: point on success None if no point picked or user canceled """ gp = Rhino.Input.Custom.GetPoint() if message: gp.SetCommandPrompt(message) base_point = rhutil.coerce3dpoint(base_point) if base_point: gp.DrawLineFromPoint(base_point, True) gp.EnableDrawLineFromPoint(True) if distance: gp.ConstrainDistanceFromBasePoint(distance) if in_plane: gp.ConstrainToConstructionPlane(True) gp.Get() if gp.CommandResult() != Rhino.Commands.Result.Success: return scriptcontext.errorhandler() pt = gp.Point() gp.Dispose() return pt
def XformMirror(mirror_plane_point, mirror_plane_normal): """Creates a mirror transformation matrix Parameters: mirror_plane_point (point): point on the mirror plane mirror_plane_normal (vector): a 3D vector that is normal to the mirror plane Returns: transform: mirror Transform matrix Example: import rhinoscriptsyntax as rs objs = rs.GetObjects("Select objects to mirror") if objs: plane = rs.ViewCPlane() xform = rs.XformMirror(plane.Origin, plane.Normal) rs.TransformObjects( objs, xform, True ) See Also: XformPlanarProjection XformRotation1 XformRotation2 XformRotation3 XformRotation4 XformScale XformShear XformTranslation """ point = rhutil.coerce3dpoint(mirror_plane_point, True) normal = rhutil.coerce3dvector(mirror_plane_normal, True) return Rhino.Geometry.Transform.Mirror(point, normal)
def GetRectangle(mode=0, base_point=None, prompt1=None, prompt2=None, prompt3=None): """Pauses for user input of a rectangle Parameters: mode (number, optional): The rectangle selection mode. The modes are as follows 0 = All modes 1 = Corner - a rectangle is created by picking two corner points 2 = 3Point - a rectangle is created by picking three points 3 = Vertical - a vertical rectangle is created by picking three points 4 = Center - a rectangle is created by picking a center point and a corner point base_point (point, optional): a 3d base point prompt1, prompt2, prompt3 (str, optional): optional prompts Returns: tuple(point, point, point, point): four 3d points that define the corners of the rectangle None: on error Example: import rhinoscriptsyntax as rs rect = rs.GetRectangle() if rect: for i, corner in enumerate(rect): rs.AddTextDot( i, corner ) See Also: GetPoint GetPoints """ mode = System.Enum.ToObject( Rhino.Input.GetBoxMode, mode ) base_point = rhutil.coerce3dpoint(base_point) if( base_point==None ): base_point = Rhino.Geometry.Point3d.Unset prompts = ["", "", ""] if prompt1: prompts[0] = prompt1 if prompt2: prompts[1] = prompt2 if prompt3: prompts[2] = prompt3 rc, corners = Rhino.Input.RhinoGet.GetRectangle(mode, base_point, prompts) if rc==Rhino.Commands.Result.Success: return corners return None
def PointArrayClosestPoint(points, test_point): """Finds the point in a list of 3D points that is closest to a test point Parameters: points = list of points test_point = the point to compare against Returns: index of the element in the point list that is closest to the test point Example: import rhinoscriptsyntax as rs cloud= rs.GetObject("Select point cloud") if cloud: point = rs.GetPoint("Point to test") if point: cloud = rs.PointCloudPoints(cloud) index = rs.PointArrayClosestPoint(cloud, point) if index is not None: point_id = rs.AddPoint(cloud[index]) rs.SelectObject( point_id ) See Also: CurveClosestPoint SurfaceClosestPoint """ points = rhutil.coerce3dpointlist(points, True) test_point = rhutil.coerce3dpoint(test_point, True) index = Rhino.Collections.Point3dList.ClosestIndexInList(points, test_point) if index>=0: return index
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 LightLocation(object_id, location=None): """Returns or changes the location of a light object Parameters: object_id (guid): the light object's identifier location (point, optional): the light's new location Returns: point: if location is not specified, the current location point: if location is specified, the previous location Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select a light", rs.filter.light) if id: rs.AddPoint( rs.LightLocation(id) ) See Also: IsLight LightDirection """ light = __coercelight(object_id, True) rc = light.Location if location: location = rhutil.coerce3dpoint(location, True) if location!=rc: light.Location = location id = rhutil.coerceguid(object_id, True) if not scriptcontext.doc.Lights.Modify(id, light): return scriptcontext.errorhandler() 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 ProjectPointToMesh(points, mesh_ids, direction): """Projects one or more points onto one or more meshes Parameters: points = one or more 3D points mesh_ids = identifiers of one or more meshes direction = direction vector to project the points Returns: list of projected points on success Example: import rhinoscriptsyntax as rs mesh = rs.GetObject("Select mesh to project onto", rs.filter.mesh) objects = rs.GetObjects("Select points to project", rs.filter.point) points = [rs.PointCoordinates(obj) for obj in objects] # project down... results = rs.ProjectPointToMesh(points, mesh, (0,0,-1)) rs.AddPoints( results ) See Also: ProjectCurveToMesh ProjectCurveToSurface ProjectPointToSurface """ pts = rhutil.coerce3dpointlist(points, False) if pts is None: pts = [rhutil.coerce3dpoint(points, True)] direction = rhutil.coerce3dvector(direction, True) id = rhutil.coerceguid(mesh_ids, False) if id: mesh_ids = [id] meshes = [rhutil.coercemesh(id, True) for id in mesh_ids] tolerance = scriptcontext.doc.ModelAbsoluteTolerance rc = Rhino.Geometry.Intersect.Intersection.ProjectPointsToMeshes(meshes, pts, direction, tolerance) return rc
def MeshClosestPoint(object_id, point, maximum_distance=None): """Returns the point on a mesh that is closest to a test point Parameters: object_id (guid): identifier of a mesh object point (point): point to test maximum_distance (number, optional): upper bound used for closest point calculation. If you are only interested in finding a point Q on the mesh when point.DistanceTo(Q) < maximum_distance, then set maximum_distance to that value Returns: tuple(point, number): containing the results of the calculation where [0] = the 3-D point on the mesh [1] = the index of the mesh face on which the 3-D point lies None: on error Example: import rhinocriptsyntax as rs obj = rs.GetObject("Select mesh", rs.filter.mesh) point = rs.GetPoint("Pick test point") intersect = rs.MeshClosestPoint(obj, point) if intersect: rs.AddPoint(intersect) See Also: MeshFaceCount MeshFaces """ mesh = rhutil.coercemesh(object_id, True) point = rhutil.coerce3dpoint(point, True) tolerance = maximum_distance if maximum_distance else 0.0 face, closest_point = mesh.ClosestPoint(point, tolerance) if face < 0: return scriptcontext.errorhandler() return closest_point, face
def PointArrayClosestPoint(points, test_point): """Finds the point in a list of 3D points that is closest to a test point Parameters: points ([point, ...]): list of points test_point (point): the point to compare against Returns: number: index of the element in the point list that is closest to the test point Example: import rhinoscriptsyntax as rs cloud= rs.GetObject("Select point cloud") if cloud: point = rs.GetPoint("Point to test") if point: cloud = rs.PointCloudPoints(cloud) index = rs.PointArrayClosestPoint(cloud, point) if index is not None: point_id = rs.AddPoint(cloud[index]) rs.SelectObject( point_id ) See Also: CurveClosestPoint SurfaceClosestPoint """ points = rhutil.coerce3dpointlist(points, True) test_point = rhutil.coerce3dpoint(test_point, True) index = Rhino.Collections.Point3dList.ClosestIndexInList( points, test_point) if index >= 0: return index
def PlaneFromFrame(origin, x_axis, y_axis): """Construct a plane from a point, and two vectors in the plane. Parameters: origin (point): A 3D point identifying the origin of the plane. x_axis (vector): A non-zero 3D vector in the plane that determines the X axis direction. y_axis (vector): A non-zero 3D vector not parallel to x_axis that is used to determine the Y axis direction. Note, y_axis does not have to be perpendicular to x_axis. Returns: plane: The plane if successful. Example: import rhinoscriptsyntax as rs origin = rs.GetPoint("CPlane origin") if origin: xaxis = (1,0,0) yaxis = (0,0,1) plane = rs.PlaneFromFrame( origin, xaxis, yaxis ) rs.ViewCPlane(None, plane) See Also: MovePlane PlaneFromNormal PlaneFromPoints RotatePlane """ origin = rhutil.coerce3dpoint(origin, True) x_axis = rhutil.coerce3dvector(x_axis, True) y_axis = rhutil.coerce3dvector(y_axis, True) return Rhino.Geometry.Plane(origin, x_axis, y_axis)
def ProjectPointToSurface(points, surface_ids, direction): """Projects one or more points onto one or more surfaces or polysurfaces Parameters: points ([point, ...]): one or more 3D points surface_ids ([guid, ...]): identifiers of one or more surfaces/polysurfaces direction (vector): direction vector to project the points Returns: list(point, ...): projected points on success Example: import rhinoscriptsyntax as rs surface = rs.GetObject("Select surface to project onto", rs.filter.surface) objects = rs.GetObjects("Select points to project", rs.filter.point) points = [rs.PointCoordinates(obj) for obj in objects] results = rs.ProjectPointToSurface(points, surface, (0,0,-1)) rs.AddPoints(results) See Also: ProjectCurveToMesh ProjectCurveToSurface ProjectPointToMesh """ pts = rhutil.coerce3dpointlist(points) if pts is None: pts = [rhutil.coerce3dpoint(points, True)] direction = rhutil.coerce3dvector(direction, True) id = rhutil.coerceguid(surface_ids, False) if id: surface_ids = [id] breps = [rhutil.coercebrep(id, True) for id in surface_ids] tolerance = scriptcontext.doc.ModelAbsoluteTolerance return Rhino.Geometry.Intersect.Intersection.ProjectPointsToBreps( breps, pts, direction, tolerance)
def ProjectPointToSurface(points, surface_ids, direction): """Projects one or more points onto one or more surfaces or polysurfaces Parameters: points = one or more 3D points surface_ids = identifiers of one or more surfaces/polysurfaces direction = direction vector to project the points Returns: list of projected points on success Example: import rhinoscriptsyntax as rs surface = rs.GetObject("Select surface to project onto", rs.filter.surface) objects = rs.GetObjects("Select points to project", rs.filter.point) points = [rs.PointCoordinates(obj) for obj in objects] results = rs.ProjectPointToSurface(points, surface, (0,0,-1)) rs.AddPoints(results) See Also: ProjectCurveToMesh ProjectCurveToSurface ProjectPointToMesh """ pts = rhutil.coerce3dpointlist(points) if pts is None: pts = [rhutil.coerce3dpoint(points, True)] direction = rhutil.coerce3dvector(direction, True) id = rhutil.coerceguid(surface_ids, False) if id: surface_ids = [id] breps = [rhutil.coercebrep(id, True) for id in surface_ids] tolerance = scriptcontext.doc.ModelAbsoluteTolerance return Rhino.Geometry.Intersect.Intersection.ProjectPointsToBreps(breps, pts, direction, tolerance)
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 ProjectPointToMesh(points, mesh_ids, direction): """Projects one or more points onto one or more meshes Parameters: points ([point, ...]): one or more 3D points mesh_ids ([guid, ...]): identifiers of one or more meshes direction (vector): direction vector to project the points Returns: list(point, ...): projected points on success Example: import rhinoscriptsyntax as rs mesh = rs.GetObject("Select mesh to project onto", rs.filter.mesh) objects = rs.GetObjects("Select points to project", rs.filter.point) points = [rs.PointCoordinates(obj) for obj in objects] # project down... results = rs.ProjectPointToMesh(points, mesh, (0,0,-1)) rs.AddPoints( results ) See Also: ProjectCurveToMesh ProjectCurveToSurface ProjectPointToSurface """ pts = rhutil.coerce3dpointlist(points, False) if pts is None: pts = [rhutil.coerce3dpoint(points, True)] direction = rhutil.coerce3dvector(direction, True) id = rhutil.coerceguid(mesh_ids, False) if id: mesh_ids = [id] meshes = [rhutil.coercemesh(id, True) for id in mesh_ids] tolerance = scriptcontext.doc.ModelAbsoluteTolerance rc = Rhino.Geometry.Intersect.Intersection.ProjectPointsToMeshes( meshes, pts, direction, tolerance) return rc
def PlaneClosestPoint(plane, point, return_point=True): """Returns the point on a plane that is closest to a test point. Parameters: plane = The plane point = The 3-D point to test. return_point [opt] = If omitted or True, then the point on the plane that is closest to the test point is returned. If False, then the parameter of the point on the plane that is closest to the test point is returned. Returns: If return_point is omitted or True, then the 3-D point If return_point is False, then an array containing the U,V parameters of the point None if not successful, or on error. Example: import rhinoscriptsyntax as rs point = rs.GetPoint("Point to test") if point: plane = rs.ViewCPlane() if plane: print rs.PlaneClosestPoint(plane, point) See Also: DistanceToPlane EvaluatePlane """ plane = rhutil.coerceplane(plane, True) point = rhutil.coerce3dpoint(point, True) if return_point: return plane.ClosestPoint(point) else: rc, s, t = plane.ClosestParameter(point) if rc: return s, t
def LightLocation(object_id, location=None): """Returns or changes the location of a light object Parameters: object_id = the light object's identifier location[opt] = the light's new location Returns: if location is not specified, the current location if location is specified, the previous location Example: import rhinoscriptsyntax as rs id = rs.GetObject("Select a light", rs.filter.light) if id: rs.AddPoint( rs.LightLocation(id) ) See Also: IsLight LightDirection """ light = __coercelight(object_id, True) rc = light.Location if location: location = rhutil.coerce3dpoint(location, True) if location!=rc: light.Location = location id = rhutil.coerceguid(object_id, True) if not scriptcontext.doc.Lights.Modify(id, light): return scriptcontext.errorhandler() scriptcontext.doc.Views.Redraw() return rc
def PlaneFromNormal(origin, normal, xaxis=None): """Creates a plane from an origin point and a normal direction vector. Parameters: origin = A 3D point identifying the origin of the plane. normal = A 3D vector identifying the normal direction of the plane. xaxis[opt] = optional vector defining the plane's x-axis Returns: The plane if successful. Example: import rhinoscriptsyntax as rs origin = rs.GetPoint("CPlane origin") if origin: direction = rs.GetPoint("CPlane direction") if direction: normal = direction - origin normal = rs.VectorUnitize(normal) rs.ViewCPlane( None, rs.PlaneFromNormal(origin, normal) ) See Also: MovePlane PlaneFromFrame PlaneFromPoints RotatePlane """ origin = rhutil.coerce3dpoint(origin, True) normal = rhutil.coerce3dvector(normal, True) rc = Rhino.Geometry.Plane(origin, normal) if xaxis: xaxis = rhutil.coerce3dvector(xaxis, True) xaxis = Rhino.Geometry.Vector3d(xaxis)#prevent original xaxis parameter from being unitized too xaxis.Unitize() yaxis = Rhino.Geometry.Vector3d.CrossProduct(rc.Normal, xaxis) rc = Rhino.Geometry.Plane(origin, xaxis, yaxis) return rc
def RotateObjects(object_ids, center_point, rotation_angle, axis=None, copy=False): """Rotates multiple objects Parameters: object_ids: Identifiers of objects to rotate center_point: the center of rotation rotation_angle: in degrees axis[opt] = axis of rotation, If omitted, the Z axis of the active construction plane is used as the rotation axis copy[opt] = copy the object Returns: List of identifiers of the rotated objects if successful """ center_point = rhutil.coerce3dpoint(center_point, True) if not axis: axis = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane( ).Normal axis = rhutil.coerce3dvector(axis, True) rotation_angle = Rhino.RhinoMath.ToRadians(rotation_angle) xf = Rhino.Geometry.Transform.Rotation(rotation_angle, axis, center_point) rc = TransformObjects(object_ids, xf, copy) return rc
def InsertBlock(block_name, insertion_point, scale=(1, 1, 1), angle_degrees=0, rotation_normal=(0, 0, 1)): """Inserts a block whose definition already exists in the document Parameters: block_name = name of an existing block definition insertion_point = insertion point for the block scale [opt] = x,y,z scale factors angle_degrees [opt] = rotation angle in degrees rotation_normal [opt] = the axis of rotation. Returns: id for the block that was added to the doc """ insertion_point = rhutil.coerce3dpoint(insertion_point, True) rotation_normal = rhutil.coerce3dvector(rotation_normal, True) angle_radians = math.radians(angle_degrees) trans = Rhino.Geometry.Transform move = trans.Translation(insertion_point[0], insertion_point[1], insertion_point[2]) scale = trans.Scale(Rhino.Geometry.Plane.WorldXY, scale[0], scale[1], scale[2]) rotate = trans.Rotation(angle_radians, rotation_normal, Rhino.Geometry.Point3d.Origin) xform = move * scale * rotate return InsertBlock2(block_name, xform)
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 LineIsFartherThan(line, distance, point_or_line): """Determines if the shortest distance from a line to a point or another line is greater than a specified distance Parameters: line = List of 6 numbers, 2 Point3d, or Line. distance = the distance point_or_line = the test point or the test line Returns: True if the shortest distance from the line to the other project is greater than distance, False otherwise, and None on error Example: import rhinoscriptsyntax as rs testPoint = (10,5,0) print rs.LineIsFartherThan(line, 3, testPoint) See Also: LineClosestPoint LineMaxDistanceTo LineMinDistanceTo LinePlane LineTransform """ line = rhutil.coerceline(line, True) test = rhutil.coerceline(point_or_line) if not test: test = rhutil.coerce3dpoint(point_or_line, True) minDist = line.MinimumDistanceTo(test) return minDist>distance
def GetPoint(message=None, base_point=None, distance=None, in_plane=False): """Pauses for user input of a point. Parameters: message [opt] = A prompt or message. base_point [opt] = list of 3 numbers or Point3d identifying a starting, or base point distance [opt] = constraining distance. If distance is specified, basePoint must also be sepcified. in_plane [opt] = constrains the point selections to the active construction plane. Returns: point on success None if no point picked or user canceled """ gp = Rhino.Input.Custom.GetPoint() if message: gp.SetCommandPrompt(message) base_point = rhutil.coerce3dpoint(base_point) if base_point: gp.DrawLineFromPoint(base_point,True) gp.EnableDrawLineFromPoint(True) if distance: gp.ConstrainDistanceFromBasePoint(distance) if in_plane: gp.ConstrainToConstructionPlane(True) gp.Get() if gp.CommandResult()!=Rhino.Commands.Result.Success: return scriptcontext.errorhandler() pt = gp.Point() gp.Dispose() return pt
def GetLine(mode=0, point=None, message1=None, message2=None, message3=None): """Prompts the user to pick points that define a line Parameters: mode[opt] = line definition mode. See help file for details point[opt] = optional starting point message1, message2, message3 = optional prompts Returns: Tuple of two points on success None on error """ gl = Rhino.Input.Custom.GetLine() if mode == 0: gl.EnableAllVariations(True) else: gl.GetLineMode = System.Enum.ToObject(Rhino.Input.Custom.GetLineMode, mode - 1) if point: point = rhutil.coerce3dpoint(point) gl.SetFirstPoint(point) if message1: gl.FirstPointPrompt = message1 if message2: gl.MidPointPrompt = message2 if message3: gl.SecondPointPromp = message3 rc, line = gl.Get() if rc == Rhino.Commands.Result.Success: return line.From, line.To
def PopupMenu(items, modes=None, point=None, view=None): """Displays a user defined, context-style popup menu. The popup menu can appear almost anywhere, and it can be dismissed by either clicking the left or right mouse buttons Parameters: items = list of strings representing the menu items. An empty string or None will create a separator modes[opt] = List of numbers identifying the display modes. If omitted, all modes are enabled. 0 = menu item is enabled 1 = menu item is disabled 2 = menu item is checked 3 = menu item is disabled and checked point[opt] = a 3D point where the menu item will appear. If omitted, the menu will appear at the current cursor position view[opt] = if point is specified, the view in which the point is computed. If omitted, the active view is used Returns: index of the menu item picked or -1 if no menu item was picked """ screen_point = System.Windows.Forms.Cursor.Position if point: point = rhutil.coerce3dpoint(point) view = __viewhelper(view) viewport = view.ActiveViewport point2d = viewport.WorldToClient(point) screen_point = viewport.ClientToScreen(point2d) return Rhino.UI.Dialogs.ShowContextMenu(items, screen_point, modes);
def IsPointOnMesh(object_id, point): """Verifies a point is on a mesh Parameters: object_id = identifier of a mesh object point = test point Returns: True if successful, otherwise False. None on error. Example: import rhinoscriptsyntax as rs obj = rs.GetObject("Select a mesh") if rs.IsMesh(obj): point = rs.GetPointOnMesh(strObject, "Pick a test point") if point: if rs.IsPointOnMesh(obj, point): print "The point is on the mesh" else: print "The point is not on the mesh" See Also: IsMesh MeshClosestPoint """ mesh = rhutil.coercemesh(object_id, True) point = rhutil.coerce3dpoint(point, True) max_distance = Rhino.RhinoMath.SqrtEpsilon face, pt = mesh.ClosestPoint(point, max_distance) return face>=0
def PlaneFromFrame(origin, x_axis, y_axis): """Construct a plane from a point, and two vectors in the plane. Parameters: origin = A 3D point identifying the origin of the plane. x_axis = A non-zero 3D vector in the plane that determines the X axis direction. y_axis = A non-zero 3D vector not parallel to x_axis that is used to determine the Y axis direction. Note, y_axis does not have to be perpendicular to x_axis. Returns: The plane if successful. Example: import rhinoscriptsyntax as rs origin = rs.GetPoint("CPlane origin") if origin: xaxis = (1,0,0) yaxis = (0,0,1) plane = rs.PlaneFromFrame( origin, xaxis, yaxis ) rs.ViewCPlane(None, plane) See Also: MovePlane PlaneFromNormal PlaneFromPoints RotatePlane """ origin = rhutil.coerce3dpoint(origin, True) x_axis = rhutil.coerce3dvector(x_axis, True) y_axis = rhutil.coerce3dvector(y_axis, True) return Rhino.Geometry.Plane(origin, x_axis, y_axis)
def XformWorldToScreen(point, view=None, screen_coordinates=False): """Transforms a point from world coordinates to either client-area coordinates of the specified view or screen coordinates. The resulting coordinates are represented as a 2D point Parameters: point = 3D point in world coordinates view[opt] = title or identifier of a view. If omitted, the active view is used screen_coordinates[opt] = if False, the function returns the results as client-area coordinates. If True, the result is in screen-area coordinates Returns: 2D point on success None on error Example: import rhinoscriptsyntax as rs point = (0.0, 0.0, 0.0) view = rs.CurrentView() point2d = rs.XformWorldToScreen(point, view) print point2d See Also: XformScreenToWorld """ point = rhutil.coerce3dpoint(point, True) view = rhview.__viewhelper(view) viewport = view.MainViewport xform = viewport.GetTransform(Rhino.DocObjects.CoordinateSystem.World, Rhino.DocObjects.CoordinateSystem.Screen) point = xform * point point = Rhino.Geometry.Point2d(point.X, point.Y) if screen_coordinates: screen = view.ScreenRectangle point.X = point.X + screen.Left point.Y = point.Y + screen.Top return point
def AddLinearDimension(start_point, end_point, point_on_dimension_line): """Adds a linear dimension to the document Returns: identifier of the new object on success None on error """ start = rhutil.coerce3dpoint(start_point, True) end = rhutil.coerce3dpoint(end_point, True) onpoint = rhutil.coerce3dpoint(point_on_dimension_line, True) ldim = Rhino.Geometry.LinearDimension.FromPoints(start, end, onpoint) if not ldim: return scriptcontext.errorhandler() rc = scriptcontext.doc.Objects.AddLinearDimension(ldim) if rc == System.Guid.Empty: raise Exception("unable to add dimension to document") scriptcontext.doc.Views.Redraw() return rc
def LineSphereIntersection(line, sphere_center, sphere_radius): """Calculates the intersection of a line and a sphere Parameters: line = the line sphere_center = the center point of the sphere sphere_radius = the radius of the sphere Returns: list of intersection points if successful, otherwise None Example: import rhinoscriptsyntax as rs radius = 10 line = (-10,0,0), (10,0,10) points = rs.LineSphereIntersection(line, (0,0,0), radius) if points: for point in points:rs.AddPoint(point) See Also: LineCylinderIntersection LineLineIntersection LinePlaneIntersection """ line = rhutil.coerceline(line, True) sphere_center = rhutil.coerce3dpoint(sphere_center, True) sphere = Rhino.Geometry.Sphere(sphere_center, sphere_radius) rc, pt1, pt2 = Rhino.Geometry.Intersect.Intersection.LineSphere(line, sphere) if rc==Rhino.Geometry.Intersect.LineSphereIntersection.None: return [] if rc==Rhino.Geometry.Intersect.LineSphereIntersection.Single: return [pt1] return [pt1, pt2]
def AddText(text, point_or_plane, height=1.0, font="Arial", font_style=0, justification=None): """Adds a text string to the document Parameters: text (str): the text to display point_or_plane (point|plane): a 3-D point or the plane on which the text will lie. The origin of the plane will be the origin point of the text height (number, optional): the text height font (str, optional): the text font font_style (number, optional): any of the following flags 0 = normal 1 = bold 2 = italic 3 = bold and italic justification (number, optional): text justification. Values may be added to create combinations. 1 = Left 2 = Center (horizontal) 4 = Right 65536 = Bottom 131072 = Middle (vertical) 262144 = Top Returns: guid: identifier for the object that was added to the doc on success None: on failure Example: import rhinoscriptsyntax as rs point = rs.GetPoint("Pick point") if point: rs.AddText("Hello Rhino!", point) See Also: IsText """ if not text: raise ValueError("text invalid") if not isinstance(text, str): text = str(text) point = rhutil.coerce3dpoint(point_or_plane) plane = None if not point: plane = rhutil.coerceplane(point_or_plane, True) if not plane: plane = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane( ) plane.Origin = point bold = (1 == font_style or 3 == font_style) italic = (2 == font_style or 3 == font_style) id = None if justification is None: id = scriptcontext.doc.Objects.AddText(text, plane, height, font, bold, italic) else: just = System.Enum.ToObject(Rhino.Geometry.TextJustification, justification) id = scriptcontext.doc.Objects.AddText(text, plane, height, font, bold, italic, just) if id == System.Guid.Empty: raise ValueError("unable to add text to document") scriptcontext.doc.Views.Redraw() return id
def LineMinDistanceTo(line, point_or_line): """Finds the shortest distance between a line as a finite chord, and a point or another line """ line = rhutil.coerceline(line, True) test = rhutil.coerceline(point_or_line) if test is None: test = rhutil.coerce3dpoint(point_or_line, True) return line.MinimumDistanceTo(test)
def AddLinearLight(start_point, end_point, width=None): """Adds a new linear light object to the document Parameters: start_point (point): starting point of the light end_point (point): ending point and direction of the light width (number): width of the light Returns: guid: identifier of the new object if successful None: on error Example: import rhinoscriptsyntax as rs start = rs.GetPoint("Light origin") if start: end = rs.GetPoint("Light length and direction", start) if end: rs.AddLinearLight(start, end) See Also: IsLinearLight """ start = rhutil.coerce3dpoint(start_point, True) end = rhutil.coerce3dpoint(end_point, True) if width is None: radius=0.5 units = scriptcontext.doc.ModelUnitSystem if units!=Rhino.UnitSystem.None: scale = Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Inches, units) radius *= scale width = radius light = Rhino.Geometry.Light() light.LightStyle = Rhino.Geometry.LightStyle.WorldLinear light.Location = start v = end-start light.Direction = v light.Length = light.Direction light.Width = -light.Width plane = Rhino.Geometry.Plane(light.Location, light.Direction) xaxis = plane.XAxis xaxis.Unitize() plane.XAxis = xaxis light.Width = xaxis * min(width, v.Length/20) #light.Location = start - light.Direction index = scriptcontext.doc.Lights.Add(light) if index<0: raise Exception("unable to add light to LightTable") rc = scriptcontext.doc.Lights[index].Id scriptcontext.doc.Views.Redraw() return rc