Esempio n. 1
0
def draw_cylinders(cylinders, cap=False):
    """Draw cylinders.

    Parameters
    ----------
    cylinders : list of dict
        The cylinder definitions.

    Other Parameters
    ----------------
    cap : bool, optional
        Default is ``False``.

    Returns
    -------
    list of :class:`Rhino.Geometry.Cylinder`

    Notes
    -----
    .. code-block:: python

        Schema({
            'start': lambda x: len(x) == 3,
            'end': lambda x: len(x) == 3,
            'radius': And(Or(int, float), lambda x: x > 0)
        })

    """
    rg_cylinders = []
    for c in iter(cylinders):
        start = c['start']
        end = c['end']
        radius = c['radius']
        if radius < TOL:
            continue
        base = Point3d(*start)
        normal = Point3d(*end) - base
        height = normal.Length
        if height < TOL:
            continue
        plane = Plane(base, normal)
        circle = Circle(plane, radius)
        cylinder = Cylinder(circle, height)
        brep = cylinder.ToBrep(cap, cap)
        if not brep:
            continue
        rg_cylinders.append(brep)
    return rg_cylinders
Esempio n. 2
0
def xdraw_cylinders(cylinders, cap=False, **kwargs):
    guids = []
    for c in iter(cylinders):
        start = c['start']
        end = c['end']
        radius = c['radius']
        name = c.get('name', '')
        color = c.get('color')
        layer = c.get('layer')
        if radius < TOL:
            continue
        base = Point3d(*start)
        normal = Point3d(*end) - base
        height = normal.Length
        if height < TOL:
            continue
        plane = Plane(base, normal)
        circle = Circle(plane, radius)
        cylinder = Cylinder(circle, height)
        brep = cylinder.ToBrep(cap, cap)
        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
Esempio n. 3
0
    def get_rgcylinder(self):
        """:class:`Rhino.Geometry.Cylinder` representing bullet.

        Returns
        -------
        :class:`Rhino.Geometry.Cylinder`
        """
        from Rhino.Geometry import Cylinder

        return Cylinder(self.get_rgcircle(), self.get_compressed_height())
    def get_rgcylinder(self):
        """Get :class:`Rhino.Geometry.Cylinder` representation of element.

        Returns
        -------
        :class:`Rhino.Geometry.Cylinder`
        """
        from Rhino.Geometry import Cylinder

        return Cylinder(self.get_rgcircle(), self.get_compressed_height())
Esempio n. 5
0
def xdraw_cylinders(cylinders, cap=False):
    rg_cylinders = []
    for c in iter(cylinders):
        start = c['start']
        end = c['end']
        radius = c['radius']
        if radius < TOL:
            continue
        base = Point3d(*start)
        normal = Point3d(*end) - base
        height = normal.Length
        if height < TOL:
            continue
        plane = Plane(base, normal)
        circle = Circle(plane, radius)
        cylinder = Cylinder(circle, height)
        brep = cylinder.ToBrep(cap, cap)
        if not brep:
            continue
        rg_cylinders.append(brep)
    return rg_cylinders
Esempio n. 6
0
 def DrawForeground(self, e):
     radius = self.slider.trackbar.Value
     circle = Circle(self.plane, radius)
     cylinder = Cylinder(circle, self.height)
     brep = cylinder.ToBrep(True, True)
     e.Display.DrawBrepShaded(brep, self.material)
Esempio n. 7
0
def draw_cylinders(cylinders, cap=False, **kwargs):
    """Draw cylinders and optionally set individual name, color, and layer properties.

    Parameters
    ----------
    cylinders : list of dict
        A list of cylinder dictionaries.
    cap : bool, optional

    Returns
    -------
    list of GUID

    Notes
    -----
    A cylinder dict has the following schema:

    .. code-block:: python

        Schema({
            'start': And(list, lambda x: len(x) == 3),
            'end': And(list, lambda x: len(x) == 3),
            'radius': And(Or(int, float), lambda x: x > 0.0),
            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 c in iter(cylinders):
        start = c['start']
        end = c['end']
        radius = c['radius']
        name = c.get('name', '')
        color = c.get('color')
        layer = c.get('layer')
        if radius < TOL:
            continue
        base = Point3d(*start)
        normal = Point3d(*end) - base
        height = normal.Length
        if height < TOL:
            continue
        plane = Plane(base, normal)
        circle = Circle(plane, radius)
        cylinder = Cylinder(circle, height)
        brep = cylinder.ToBrep(cap, cap)
        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