def xdraw_faces(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.1, flex=1.0, pull=1.0): """Draw polygonal faces as Breps. """ rg_breps = [] for f in iter(faces): points = f['points'] corners = [Point3d(*point) for point in points] pcurve = PolylineCurve(corners) geo = List[GeometryBase](1) geo.Add(pcurve) p = len(points) if p == 4: brep = Brep.CreateFromCornerPoints(Point3d(*points[0]), Point3d(*points[1]), Point3d(*points[2]), TOL) elif p == 5: brep = Brep.CreateFromCornerPoints(Point3d(*points[0]), Point3d(*points[1]), Point3d(*points[2]), Point3d(*points[3]), TOL) else: brep = Brep.CreatePatch(geo, u, v, TOL) if not brep: continue rg_breps.append(brep) return rg_breps
def xdraw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.1, flex=1.0, pull=1.0, **kwargs): """Draw polygonal faces as Breps, and optionally set individual name, color, and layer properties. """ guids = [] for f in iter(faces): points = f['points'] name = f.get('name', '') color = f.get('color') layer = f.get('layer') corners = [Point3d(*point) for point in points] pcurve = PolylineCurve(corners) geo = List[GeometryBase](1) geo.Add(pcurve) p = len(points) if p == 4: brep = Brep.CreateFromCornerPoints(Point3d(*points[0]), Point3d(*points[1]), Point3d(*points[2]), TOL) elif p == 5: brep = Brep.CreateFromCornerPoints(Point3d(*points[0]), Point3d(*points[1]), Point3d(*points[2]), Point3d(*points[3]), TOL) else: brep = Brep.CreatePatch(geo, u, v, TOL) if not brep: continue guid = add_brep(brep) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids
def __init__(self, srf, U, V, TrimAware=True, Phase=()): self.TrimAware = TrimAware self.isSurface = isinstance(srf, Surface) self.isBrepFace = isinstance(srf, BrepFace) self.Surface = srf if self.isBrepFace else Brep.TryConvertBrep( srf).Faces[0] self.Parameters = [] self.Points = Point3dList() self.Normals = [] self.inc = [] self.U = U self.V = V self.Curves = {CurveList() for char in 'UV'} # self.SubSurfaces = {Phase[0]: {Phase[1]: {}}} self.SubSurfaces = [] self.Phase = Phase # subSurfaces[patch.Phase] = {} # subSurfaces[patch.Phase][key] = {} quad = range(4) self.__conf__ = { 'quad': quad, 'combinations': zip(quad, (1, 2, 3, 0)), 'tolerance': doc.ModelAbsoluteTolerance }
def xdraw_pipes(pipes, cap=2, fit=1.0): abs_tol = TOL ang_tol = sc.doc.ModelAngleToleranceRadians for p in pipes: points = p['points'] radius = p['radius'] params = [0.0, 1.0] cap = ToObject(PipeCapMode, cap) if type(radius) in (int, float): radius = [radius] * 2 radius = [float(r) for r in radius] rail = Curve.CreateControlPointCurve([Point3d(*xyz) for xyz in points]) breps = Brep.CreatePipe(rail, params, radius, 1, cap, fit, abs_tol, ang_tol) for brep in breps: yield brep
def draw_pipes(pipes, cap=2, fit=1.0): """Draw pipes. Parameters ---------- pipes : list of dict The pipe definitions. Other Parameters ---------------- cap : {0, 1, 2}, optional fit : float, optional Returns ------- list of :class:`Rhino.Geometry.Brep` Notes ----- .. code-block:: python Schema({ 'points': lambda x: all(len(y) == 3 for y in x), 'radius': And(Or(int, float), lambda x: x > 0) }) """ abs_tol = TOL ang_tol = sc.doc.ModelAngleToleranceRadians for p in pipes: points = p['points'] radius = p['radius'] params = [0.0, 1.0] cap = ToObject(PipeCapMode, cap) if type(radius) in (int, float): radius = [radius] * 2 radius = [float(r) for r in radius] rail = Curve.CreateControlPointCurve([Point3d(*xyz) for xyz in points]) breps = Brep.CreatePipe(rail, params, radius, 1, cap, fit, abs_tol, ang_tol) for brep in breps: yield brep
def xdraw_pipes(pipes, cap=2, fit=1.0, **kwargs): guids = [] abs_tol = TOL ang_tol = sc.doc.ModelAngleToleranceRadians for p in pipes: points = p['points'] radius = p['radius'] name = p.get('name', '') color = p.get('color') layer = p.get('layer') params = [0.0, 1.0] cap = ToObject(PipeCapMode, cap) if type(radius) in (int, float): radius = [radius] * 2 radius = [float(r) for r in radius] rail = Curve.CreateControlPointCurve([Point3d(*xyz) for xyz in points]) breps = Brep.CreatePipe(rail, params, radius, 1, cap, fit, abs_tol, ang_tol) temp = [add_brep(brep) for brep in breps] for guid in temp: if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids
from __future__ import absolute_import
def draw_pipes(pipes, cap=2, fit=1.0, **kwargs): """Draw pipes and optionally set individual name, color, and layer properties. Parameters ---------- pipes : list of dict A list of pipe dictionaries. Other Parameters ---------------- cap : {0, 1, 2}, optional fit : float, optional Returns ------- list of GUID Notes ----- A pipe dict has the following schema: .. code-block:: python Schema({ 'points': And(list, lambda x: all(len(y) == 3 for y in x)), 'radius': And(Or(int, float), lambda x: x > 0.0), Optional('name', default=''): str, Optional('color', default=None): And(lambda x: len(x) == 3, all(0 <= y <= 255 for y in x)), Optional('layer', default=None): str, }) """ guids = [] abs_tol = TOL ang_tol = sc.doc.ModelAngleToleranceRadians for p in pipes: points = p['points'] radius = p['radius'] name = p.get('name', '') color = p.get('color') layer = p.get('layer') params = [0.0, 1.0] cap = ToObject(PipeCapMode, cap) if type(radius) in (int, float): radius = [radius] * 2 radius = [float(r) for r in radius] rail = Curve.CreateControlPointCurve([Point3d(*xyz) for xyz in points]) breps = Brep.CreatePipe(rail, params, radius, 1, cap, fit, abs_tol, ang_tol) temp = [add_brep(brep) for brep in breps] for guid in temp: if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids
def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.1, flex=1.0, pull=1.0, **kwargs): """Draw polygonal faces as Breps, and optionally set individual name, color, and layer properties. Parameters ---------- faces : list of dict A list of brep dictionaries. srf : GUID, optional A target surface. u : int, optional Default is 10. v : int, optional Default is 10. Other Parameters ---------------- trim : bool, optional tangency : bool, optional spacing : float, optional flex : float, optional pull : float, optional Returns ------- list of GUID Notes ----- A brep dict has the following schema: .. code-block:: python Schema({ 'points': And(list, lambda x: len(x) > 3 and all(len(point) == 3 for point in x), Optional('name', default=''): str, Optional('color', default=None): (lambda x: len(x) == 3 and all(0 <= y <= 255 for y in x)), Optional('layer', default=None): str, }) """ guids = [] for f in iter(faces): points = f['points'] name = f.get('name', '') color = f.get('color') layer = f.get('layer') corners = [Point3d(*point) for point in points] pcurve = PolylineCurve(corners) geo = List[GeometryBase](1) geo.Add(pcurve) p = len(points) if p == 4: brep = Brep.CreateFromCornerPoints(Point3d(*points[0]), Point3d(*points[1]), Point3d(*points[2]), TOL) elif p == 5: brep = Brep.CreateFromCornerPoints(Point3d(*points[0]), Point3d(*points[1]), Point3d(*points[2]), Point3d(*points[3]), TOL) else: brep = Brep.CreatePatch(geo, u, v, TOL) if not brep: continue guid = add_brep(brep) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids
def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.1, flex=1.0, pull=1.0, join=False, **kwargs): """Draw polygonal faces as Breps, and optionally set individual name, color, and layer properties. Parameters ---------- faces : list of dict A list of brep dictionaries. srf : GUID, optional A target surface. u : int, optional Default is 10. v : int, optional Default is 10. Other Parameters ---------------- trim : bool, optional tangency : bool, optional spacing : float, optional flex : float, optional pull : float, optional join : bool, optional Join the individual faces as polysurfaces. Default is False. Returns ------- list of GUID Notes ----- A brep dict has the following schema: .. code-block:: python Schema({ 'points': And(list, lambda x: len(x) > 3 and all(len(point) == 3 for point in x), Optional('name', default=''): str, Optional('color', default=None): (lambda x: len(x) == 3 and all(0 <= y <= 255 for y in x)), Optional('layer', default=None): str, }) Examples -------- Using a compas Mesh as an example: >>> from compas.datastructures import Mesh >>> from compas.geometry import Box, Frame >>> from compas_rhino.utilities import draw_breps >>> box = Box(Frame.worldXY(), 1.0, 2.0, 3.0) >>> mesh = Mesh.from_shape(box) Draw convert each mesh face to brep dict schema: >>> vertices = mesh.vertices_attributes('xyz') >>> breps = [{'points': mesh.face_coordinates(face)} for face in mesh.faces()] Draw brep faces as one joined brep. >>> guids = draw_breps(breps, join=True) """ breps = [] for f in iter(faces): points = f['points'] name = f.get('name', '') color = f.get('color') layer = f.get('layer') corners = [Point3d(*point) for point in points + points[:1]] pcurve = PolylineCurve(corners) geo = List[GeometryBase](1) geo.Add(pcurve) p = len(points) if p == 3: brep = Brep.CreateFromCornerPoints(Point3d(*points[0]), Point3d(*points[1]), Point3d(*points[2]), TOL) elif p == 4: brep = Brep.CreateFromCornerPoints(Point3d(*points[0]), Point3d(*points[1]), Point3d(*points[2]), Point3d(*points[3]), TOL) else: brep = Brep.CreatePatch(geo, u, v, TOL) if brep: breps.append(brep) if join: breps = Brep.JoinBreps(breps, TOL) guids = [] for brep in breps: guid = add_brep(brep) if not guid: continue obj = find_object(guid) if not obj: continue attr = obj.Attributes if color: attr.ObjectColor = FromArgb(*color) attr.ColorSource = ColorFromObject else: attr.ColorSource = ColorFromLayer if layer and find_layer_by_fullpath: index = find_layer_by_fullpath(layer, True) if index >= 0: attr.LayerIndex = index attr.Name = name attr.WireDensity = -1 obj.CommitChanges() guids.append(guid) return guids