예제 #1
0
def generate_part_images(structure):
    global view_aspect
    w_l = conf['part_img_width']
    h_l = int(w_l / view_aspect)

    for iSub in xrange(len(structure)):
        subsystem = structure.keys()[iSub]
        v = structure[subsystem]
        utils.show_only(subsystem)
        utils.hide_children(subsystem)
        for iStep in xrange(len(v)):
            step = v.keys()[iStep]
            vv = v[step]
            stepnumeral = str(iSub + 1) + '.' + str(iStep + 1)
            rs.LayerVisible(step, True)
            for partkind, vvv in vv.items():
                rs.HideObjects(vvv)
            for partkind, vvv in vv.items():
                if len(vvv) >= 1:
                    part = vvv[0]
                    rs.ShowObject(part)
                    # create images
                    rs.RestoreNamedView(conf['persp_view'])
                    rs.ZoomExtents()
                    create_view_image(
                        conf['part_img_persp'] % (stepnumeral, partkind), w_l,
                        h_l)
                    rs.RestoreNamedView(conf['top_view'])
                    rs.ZoomExtents()
                    create_view_image(
                        conf['part_img_top'] % (stepnumeral, partkind), w_l,
                        h_l)
                    rs.RestoreNamedView(conf['front_view'])
                    rs.ZoomExtents()
                    create_view_image(
                        conf['part_img_front'] % (stepnumeral, partkind), w_l,
                        h_l)
                    rs.RestoreNamedView(conf['right_view'])
                    rs.ZoomExtents()
                    create_view_image(
                        conf['part_img_right'] % (stepnumeral, partkind), w_l,
                        h_l)
                    #
                    rs.HideObject(part)
            for partkind, vvv in vv.items():
                rs.ShowObject(vvv)
            rs.LayerVisible(step, False)
        # utils.show_children(subsystem)
        utils.show_step_children(subsystem)
    utils.show_blocks()
    utils.show_subsystems()
    rs.ZoomExtents()
예제 #2
0
def delete_objects(guids, purge=None, redraw=True):
    """Delete multiple Rhino objects.

    Parameters
    ----------
    guids : list of GUID
    purge : None or bool, optional
        If None, the value of the global purge setting (:obj:`compas_rhino.PURGE_ON_DELETE`) will be used.
        If True, purge the objects from history after deleting.
        If False, delete but don't purge.
        Default is None.
    redraw : bool, optional
        If True, redrawing will be enabled and enacted.
        If False, redrawing will be disabled.
        Default is True.
    """
    if purge is None:
        purge = compas_rhino.PURGE_ON_DELETE
    if purge and purge_object:
        purge_objects(guids, redraw=redraw)
    else:
        rs.EnableRedraw(False)
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
        if redraw:
            rs.EnableRedraw(True)
            sc.doc.Views.Redraw()
예제 #3
0
def purge_objects(guids):
    for guid in guids:
        if rs.IsObjectHidden(guid):
            rs.ShowObject(guid)
        o = find_object(guid)
        purge_object(o.RuntimeSerialNumber)
    sc.doc.Views.Redraw()
예제 #4
0
def purge_objects(guids, redraw=True):
    """Purge objects from memory.

    Parameters
    ----------
    guids : list[System.Guid]
        Object identifiers.
    redraw : bool, optional
        If True, redrawing will be enabled and enacted.
        If False, redrawing will be disabled.

    Returns
    -------
    None

    """
    if not purge_object:
        raise RuntimeError('Cannot purge outside Rhino script context')
    rs.EnableRedraw(False)
    for guid in guids:
        if rs.IsObject(guid):
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
            o = find_object(guid)
            purge_object(o.RuntimeSerialNumber)
    if redraw:
        rs.EnableRedraw(True)
        sc.doc.Views.Redraw()
예제 #5
0
def delete_objects(guids, purge=True):
    if purge:
        purge_objects(guids)
    else:
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
예제 #6
0
def GetPointDynamicDrawFuncHide(sender, args):

    obj_all = rs.VisibleObjects()
    rs.HideObjects(obj_all)

    cursPos = rs.GetCursorPos()
    viewSize = rs.ViewSize()
    stepSize = int(viewSize[1] / _NUM_LAYER)

    obj_Layer1 = 'Layer: 000001 Wall1'
    obj_Layer2 = 'Layer: 000002 Wall1'
    settings = Rhino.DocObjects.ObjectEnumeratorSettings()
    settings.HiddenObjects = True

    settings.NameFilter = obj_Layer1
    ids_L1 = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)]

    settings.NameFilter = obj_Layer2
    ids_L2 = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)]

    z_L1 = rs.BoundingBox(ids_L1[0])[0][2]
    z_L2 = rs.BoundingBox(ids_L2[0])[0][2]

    zVal = viewSize[1] - cursPos[3][1]

    z_level = int(zVal / stepSize)

    segmentList = ['Wall',
                   'DenseInfill',
                   'SparseInfill',
                   'Brim',
                   'Skirt',
                   'Support']

    zero_str = '000000'

    settings = ObjectEnumeratorSettings()
    settings.HiddenObjects = True

    for segment in segmentList:
        i = 0
        while 1:
            i += 1
            obj_LayerZ = str('Layer: ' + zero_str[:-len(str(z_level))] + str(z_level) + ' ' + segment + str(i))
            try:
                settings.NameFilter = obj_LayerZ
                ids_LZ = [rhobj.Id for rhobj in scriptcontext.doc.Objects.GetObjectList(settings)]
                if len(ids_LZ) == 0:
                    break
                # rs.SelectObject(ids_LZ)
                rs.ShowObject(ids_LZ)

            except:
                print 'not found'

    args.Display.DrawDot(args.CurrentPoint, 'Layer ' + str(z_level) + ' - Distance ' + str(z_L2 - z_L1) + ' mm')
    Rhino.Display.RhinoView.Redraw(scriptcontext.doc.Views.ActiveView)
    Rhino.RhinoApp.Wait()
예제 #7
0
def purge_objects(guids):
    if not purge_object:
        raise RuntimeError('Cannot purge outside Rhino script context')
    for guid in guids:
        if rs.IsObjectHidden(guid):
            rs.ShowObject(guid)
        o = find_object(guid)
        purge_object(o.RuntimeSerialNumber)
    sc.doc.Views.Redraw()
예제 #8
0
def purge_objects(guids):
    rs.EnableRedraw(False)
    if not purge_object:
        raise RuntimeError('Cannot purge outside Rhino context.')
    for guid in guids:
        if rs.IsObject(guid):
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
            o = find_object(guid)
            purge_object(o.RuntimeSerialNumber)
예제 #9
0
def delete_objects(guids, purge=None):
    if purge is None:
        purge = compas_rhino.PURGE_ON_DELETE

    if purge and purge_object:
        purge_objects(guids)
    else:
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
예제 #10
0
def ShowSpecial():
    ids = None
    if sc.sticky.has_key('HIDE_SPECIAL'):
        ids = sc.sticky['HIDE_SPECIAL']
    if ids:
        rs.EnableRedraw(False)
        for id in ids:
            rs.ShowObject(id)
        rs.EnableRedraw(True)

    if sc.sticky.has_key('HIDE_SPECIAL'):
        sc.sticky.pop('HIDE_SPECIAL')
예제 #11
0
def main():
    to_delete = []

    rs.ProjectOsnaps(False)

    positive_object = rs.GetObject("select positive object", 16)
    negative_object = rs.GetObject("select negative object", 16)
    rs.HideObject(negative_object)

    polysurface, face = GetSubSurface("select tenon surface")
    to_delete.append(face)

    normal = rs.VectorUnitize(rs.SurfaceNormal(face, (0.5, 0.5)))
    plane = rs.PlaneFromNormal(rs.EvaluateSurface(face, 0.5, 0.5), normal)
    rs.ViewCPlane(plane=plane)
    rs.ProjectOsnaps(True)

    tenon_rects = rs.GetObjects(message="select tenon curves", filter=4)

    tenon_faces = []
    for rect in tenon_rects:
        tenon_faces.append(rs.AddPlanarSrf(rect)[0])

    rs.ShowObject(negative_object)

    rs.ProjectOsnaps(False)
    height_pt = rs.GetPoint("enter height point")

    # compule a vector normal to plane of the desired height
    extrude_vec_a = rs.EvaluateSurface(face, 0.5, 0.5)
    dist = rs.DistanceToPlane(plane, height_pt)
    extrude_vec_b = [dist * el for el in normal]
    extrude_vec_b = rs.VectorAdd(extrude_vec_a, extrude_vec_b)
    extrude_curve = rs.AddCurve((extrude_vec_a, extrude_vec_b))
    to_delete.append(extrude_curve)

    tenons = []
    for tenon_face in tenon_faces:
        tenon = rs.ExtrudeSurface(tenon_face, extrude_curve)
        tenons.append(tenon)

    rs.BooleanUnion([positive_object] + tenons, delete_input=False)
    rs.BooleanDifference([negative_object], tenons, delete_input=False)

    to_delete.append(positive_object)
    to_delete.append(negative_object)

    rs.DeleteObjects(to_delete)
    rs.DeleteObjects(tenon_faces)
    rs.DeleteObjects(tenons)
예제 #12
0
def delete_objects(guids, purge=None):
    if purge is None:
        purge = compas_rhino.PURGE_ON_DELETE

    if purge and purge_object:
        purge_objects(guids)
    else:
        rs.EnableRedraw(False)
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
        rs.EnableRedraw(True)
        sc.doc.Views.Redraw()
예제 #13
0
def purge_objects(guids):
    """Purge objects from memory.

    Parameters
    ----------
    guids : list of GUID
    """
    if not purge_object:
        raise RuntimeError('Cannot purge outside Rhino script context')
    rs.EnableRedraw(False)
    for guid in guids:
        if rs.IsObject(guid):
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
            o = find_object(guid)
            purge_object(o.RuntimeSerialNumber)
    rs.EnableRedraw(True)
    sc.doc.Views.Redraw()
예제 #14
0
def getSurfaces():
    surface = rs.ObjectsByType(8)
    hidobj = rs.HiddenObjects()
    if hidobj:
        for obj in hidobj:
            rs.ShowObject(obj)
    outDic = {'mod': None, 'ref': None}
    for srf in surface:
        print rs.ObjectName(srf)
        if rs.ObjectName(srf) == "ref":
            #rs.HideObject(srf)
            outDic['ref'] = srf
        elif rs.ObjectName(srf) == "mod":
            outDic['mod'] = srf
        else:
            rs.DeleteObject(srf)
    for obj in hidobj:
        rs.HideObject(obj)
    return outDic
예제 #15
0
def init():
    dicSur = getSurfaces()
    print dicSur
    if dicSur['mod']:
        rs.DeleteObject(dicSur['mod'])
    if dicSur['ref']:
        surface = dicSur['ref']
    else:
        raise RuntimeError, "No surface"
    vec = readTrfFyl()
    points = rs.SurfacePoints(surface)
    seldic = {k: points[k] for k in vec.keys()}
    trTic = moveDic(seldic, vec)
    srf = transformSrf(surface, trTic)
    msrf = trimSurface(srf)
    rs.HideObject(surface)
    genOffFile()
    rs.DeleteObject(msrf)
    rs.ShowObject(surface)
예제 #16
0
def delete_objects(guids, purge=False):
    """Delete objects from the Rhino model space.

    Parameters
    ----------
    guids : list
        A list of object IDs.
    purge : bool, optional
        If ``True``, the objects are permanently deleted
        and cannot be restored through, for example, using *undo*.
        If ``False`` (default), the objects are deleted from the model space
        but can still be restored using Rhino's *undo* function.

    """
    rs.EnableRedraw(False)
    if purge and purge_object:
        purge_objects(guids)
    else:
        for guid in guids:
            if rs.IsObjectHidden(guid):
                rs.ShowObject(guid)
        rs.DeleteObjects(guids)
예제 #17
0
    hatch_scale = rs.HatchScale(hatch)
    
    # Make hatch solid so we able to explode it and get surface instead
    if hatch_pattern != "Solid":
        rs.HatchPattern(hatch, "Solid")
    dup_border_surface = []
    dup_border_surface.append(rs.ExplodeHatch(hatch)[0])
    rs.SurfaceIsocurveDensity(dup_border_surface, 100)
    selected_objects.append(dup_border_surface)
    reduced_selected_objects = reduce(operator.add, selected_objects)
    rs.SelectObjects(reduced_selected_objects)
    rs.HideObject(hatch)
    rs.Command("_Trim")
    trimmed_surface = rs.LastCreatedObjects()
    
    new_borders = []
    if trimmed_surface:
        for surface in trimmed_surface:
            new_borders.append(rs.DuplicateSurfaceBorder(surface))
            selected_objects.append(new_borders)
        # Keep trimming lines but everything else will be deleted further
        selected_objects.remove(trim_lines)
        new_hatches = rs.AddHatches(new_borders, hatch_pattern, hatch_scale, hatch_rotation)
        rs.MatchObjectAttributes(new_hatches, hatch)
        rs.ShowObject(new_hatches)
       rs.DeleteObjects(trimmed_surface)
    else:
        print("No trimmed surfaces was created.")
else:
    print("No hatches was selected.")
예제 #18
0
def main():
    global inner_curves, outer_curves, curve_coords

    # save for later
    orig_hidden_objects = rs.HiddenObjects()

    # we put reference points in the dogbone-ref layer, so create it if it doesn't exist
    rs.AddLayer("dogbone-ref")

    panel, face = getsubsurface.GetSubSurface("select dogbone face")

    diameter = rs.GetReal("enter cutter diameter", number=0.25)
    diameter = diameter * 1.1

    rs.EnableRedraw(False)

    # compute the plane
    normal = rs.VectorUnitize(rs.SurfaceNormal(face, (0.5, 0.5)))
    plane = rs.PlaneFromNormal(rs.EvaluateSurface(face, 0.5, 0.5), normal)

    rs.ViewCPlane(plane=plane)
    rs.ProjectOsnaps(True)

    outer_curves = rs.DuplicateSurfaceBorder(face, 1)
    inner_curves = rs.DuplicateSurfaceBorder(face, 2)

    # make a dict mapping each curve to the coords in that curve
    curve_coords = dict()
    for curve in outer_curves + inner_curves:
        coords = rs.CurvePoints(curve)[:-1]
        curve_coords[curve] = coords

    # make a dict mapping each curve to the z component of its cross product at each index
    curve_cross_zs = dict()
    for curve, coords in curve_coords.items():
        proj_coords = [rs.SurfaceClosestPoint(face, coord) for coord in coords]
        cross_zs = []
        for idx in range(len(proj_coords)):
            triplet = [
                proj_coords[(idx + 1) % len(proj_coords)], proj_coords[idx],
                proj_coords[(idx - 1) % len(proj_coords)]
            ]

            v0 = (triplet[1][0] - triplet[0][0], triplet[1][1] - triplet[0][1],
                  0)
            v1 = (triplet[2][0] - triplet[1][0], triplet[2][1] - triplet[1][1],
                  0)
            cross_z = rs.VectorCrossProduct(v0, v1)[2]
            cross_zs.append(cross_z)
        curve_cross_zs[curve] = cross_zs

    points = []
    bones = []
    temp_points = []
    rs.EnableRedraw(True)
    while True:
        coord = rs.GetPoint("select corner")
        if coord is None:
            break
        try:
            curve, idx = get_curve_and_idx_for_coord(coord)
            point = rs.AddPoint(coord)
            rs.ObjectColor(point, (255, 0, 0))
            temp_points.append(point)
            bones.append((curve, idx))
        except ValueError:
            print "invalid curve point"
            continue
    rs.EnableRedraw(False)
    rs.DeleteObjects(temp_points)

    # try to automatically identify dogbone points if user selected none
    if len(bones) == 0:
        for curve, coords in curve_coords.items():
            proj_coords = [
                rs.SurfaceClosestPoint(face, coord) for coord in coords
            ]
            for idx in range(len(proj_coords)):
                triplet = [
                    proj_coords[(idx + 1) % len(proj_coords)],
                    proj_coords[idx], proj_coords[(idx - 1) % len(proj_coords)]
                ]
                if curve_cross_zs[curve][idx] > 0:
                    bones.append((curve, idx))

    # make the bones
    extrusions = []
    for bone in bones:
        curve, idx = bone

        coords = curve_coords[curve]

        point = rs.AddPoint(coords[idx])
        rs.ObjectLayer(point, "dogbone-ref")

        triplet = [
            coords[(idx + 1) % len(coords)],
            coords[idx],
            coords[(idx - 1) % len(coords)],
        ]

        angle = rs.Angle2(
            (triplet[1], triplet[0]),
            (triplet[1], triplet[2]),
        )
        angle = angle[0]

        # This is a hacky method to determine the handedness of the curve
        # the cross product SHOULD have worked here, but for some reason
        # it did not.
        v0 = triplet[2][0] - triplet[1][0], triplet[2][1] - triplet[1][1], 0
        v1 = triplet[1][0] - triplet[0][0], triplet[1][1] - triplet[0][1], 0
        _angle = math.degrees(
            math.atan2(v0[1], v0[0]) - math.atan2(v1[1], v1[0]))
        while _angle > 180:
            _angle -= 360
        while _angle < -180:
            _angle += 360
        if math.copysign(1, angle) != math.copysign(1, _angle):
            angle -= 180

        point = rs.VectorAdd(
            triplet[1],
            rs.VectorRotate(
                0.5 * diameter *
                rs.VectorUnitize(rs.VectorSubtract(triplet[2], triplet[1])),
                angle / 2, (0, 0, 1)))

        circle = rs.AddCircle((point.X, point.Y, -10), diameter / 2.0)
        circle_srf = rs.AddPlanarSrf(circle)
        p0 = (point.X, point.Y, -10)
        p1 = (point.X, point.Y, 10)
        line = rs.AddLine(p0, p1)

        extrusion = rs.ExtrudeSurface(circle_srf, line)
        extrusions.append(extrusion)
        rs.DeleteObjects([circle, circle_srf, line])

    rs.BooleanDifference([panel], extrusions, delete_input=True)

    rs.DeleteObject(panel)
    rs.DeleteObjects(extrusions)
    rs.DeleteObjects(points)
    rs.DeleteObjects(inner_curves)
    rs.DeleteObjects(outer_curves)
    rs.DeleteObject(face)
    rs.ShowObject(rs.AllObjects())
    rs.HideObjects(orig_hidden_objects)

    rs.EnableRedraw(True)
예제 #19
0
 def show(self):
     """Show the Rhino object."""
     return rs.ShowObject(self.guid)
예제 #20
0
 def show(self):
     return rs.ShowObject(self.guid)
예제 #21
0



from objects_to_mesh import mesh_to_mesh
import rhinoscriptsyntax as rs  


if __name__ == '__main__':
    
    rhino_mesh = rs.GetObject("Select Object",32)
    
    rhino_mesh_dup = rs.CopyObject(rhino_mesh)
    rs.HideObject(rhino_mesh_dup)
    
    trg_len = rs.GetReal("Target Edges Length",0.3)
    
    
    rs.MeshQuadsToTriangles(rhino_mesh)
    
    rhino_mesh = mesh_to_mesh(rhino_mesh,trg_len,vis=5)
    
    rs.SelectObject(rhino_mesh)
    for i in range(3):
        rs.Command("-Smooth Factor=1  CoordinateSystem=World  X=Yes  Y=Yes  Z=Yes  FixBoundaries=Yes ",False)
    
    
    rs.ShowObject(rhino_mesh_dup)
    
    
    #mesh_to_mesh(mesh,trg_len,vis=10)
예제 #22
0
def CutModel(objs, srf):
    try:
        if rs.ObjectType(srf) == 1073741824:
            extrusionSurface = rs.coercesurface(srf)
            rhSrf = extrusionSurface.ToBrep().Faces[0]
        else:
            rhSrf = rs.coercesurface(srf)
        plane = rhSrf.TryGetPlane()[1]
        if rhSrf.OrientationIsReversed:
            plane.Flip()
        groupMain = rs.AddGroup('MainObjects')
        groupCut = rs.AddGroup('SectionSurfaces')
        groupVisible = rs.AddGroup('VisibleObjects')

        rs.HideObject(objs)

        for obj in objs:
            #BLOCKS
            if rs.IsBlockInstance(obj):
                blockObjs = utils.GetAllBlockObjectsInPosition(obj)
                for eachBlockObj in blockObjs:
                    rhobj = rs.coercegeometry(eachBlockObj)
                    splitResults = CutObjectWithPlane(rhobj, plane)
                    if splitResults[0] is not None:
                        for eachObj in splitResults[0]:
                            utils.SafeMatchObjectAttributes(
                                eachObj, eachBlockObj)
                            #rs.MatchObjectAttributes(eachObj, eachBlockObj)
                            rs.ShowObject(eachObj)
                            rs.AddObjectToGroup(eachObj, groupMain)
                        for eachObj in splitResults[1]:
                            utils.SafeMatchObjectAttributes(
                                eachObj, eachBlockObj)
                            #rs.MatchObjectAttributes(eachObj, eachBlockObj)
                            rs.ShowObject(eachObj)
                            rs.AddObjectToGroup(eachObj, groupMain)
                        for eachObj in splitResults[3]:
                            rs.ObjectColor(eachObj, (255, 0, 0))
                            rs.ObjectName(eachObj, 'Section Cut Surface')
                            rs.AddObjectToGroup(eachObj, groupCut)
                    rs.DeleteObject(eachBlockObj)

            #GEOMETRY
            else:
                rhobj = rs.coercegeometry(obj)
                splitResults = CutObjectWithPlane(rhobj, plane)
                if splitResults[0] is not None:
                    for eachObj in splitResults[0]:
                        utils.SafeMatchObjectAttributes(eachObj, eachBlockObj)
                        #rs.MatchObjectAttributes(eachObj, obj)
                        rs.ShowObject(eachObj)
                        rs.AddObjectToGroup(eachObj, groupMain)
                    for eachObj in splitResults[1]:
                        utils.SafeMatchObjectAttributes(eachObj, eachBlockObj)
                        #rs.MatchObjectAttributes(eachObj, obj)
                        rs.ShowObject(eachObj)
                        rs.AddObjectToGroup(eachObj, groupMain)
                    for eachObj in splitResults[3]:
                        rs.ObjectColor(eachObj, (255, 0, 0))
                        rs.ObjectName(eachObj, 'Section Cut Surface')
                        rs.AddObjectToGroup(eachObj, groupCut)
        return True
    except:
        print "Cut Model failed"
        return False