Esempio n. 1
0
def addNumberTag(sortedPts, objs):
    for i, pt in enumerate(sortedPts):
        numTag = rs.AddText(str(i+1), pt, justification = 131074)
        objLay = rs.ObjectLayer(objs[i])
        parentLayer = rs.ParentLayer(objLay)
        hostLayer = rs.AddLayer("ANNO_NUM", (128,128,128), parent = parentLayer)
        rs.ObjectLayer(numTag, hostLayer)
Esempio n. 2
0
def appendLayer(layers, obj):
    layer = rs.ObjectLayer(obj)
    try:
        layers.index(layer)
        pass
    except Exception as e:
        layers.append(rs.ObjectLayer(obj))
Esempio n. 3
0
def filterObjects(objs):
    new_list = []
    for obj in objs:
        if rs.LayerVisible( rs.ObjectLayer(obj) ):
            # only export visible layers
            if rs.IsCurve(obj):
                new_list.append(obj)

            elif rs.IsPoint(obj):
                # convert to circle
                layer = rs.ObjectLayer(obj)
                point=rs.coerce3dpoint(obj)

                circle = rs.AddCircle(rs.WorldXYPlane(),3)

                rs.ObjectLayer(circle, layer)
                rs.MoveObject(circle, [point.X, point.Y, point.Z])
                new_list.append(circle)
                rs.DeleteObject(obj)
                # rs.DeleteObject(point)

            else:
                # remove from obj list
                rs.DeleteObject(obj)
        else:
            # remove from obj list
            rs.DeleteObject(obj)

    return new_list
Esempio n. 4
0
def swapParentLayer(obj):
    layer = rs.ObjectLayer(obj)
    if "::" in layer:
        splitlayer = layer.split("::")
        currentParent = splitlayer[0]
        newlayer = layer.replace(currentParent, 'output mass 2')
        rs.ObjectLayer(obj, newlayer)
Esempio n. 5
0
def areaTag(pline):
    #get area
    area = rs.CurveArea(pline)[0]
    area = str((int(area * 100)) / 100) + "m2"
    print area

    #move area tag below name tag location
    offset = [0, -2.5, 0]

    #add text tag
    objID = pline
    text = '%<area("' + str(objID) + '")>%m2'

    pt = rs.AddPoint(rs.CurveAreaCentroid(pline)[0])
    rs.MoveObject(pt, offset)
    areaTag = rs.AddText(text, pt, 1, justification=131074)
    rs.DeleteObject(pt)

    parentLayer = rs.ParentLayer(rs.ObjectLayer(pline))
    hostLayer = rs.AddLayer("ANNO_AREA", (128, 128, 128), parent=parentLayer)
    rs.ObjectLayer(areaTag, hostLayer)

    te = rs.coercerhinoobject(areaTag, True, True)
    te.Geometry.TextFormula = text
    te.CommitChanges()
    sc.doc.Views.Redraw()
    return None
Esempio n. 6
0
def organize_annotations():
    """
    - puts all dimensions found in all pages on layer 'dim' and annotations on 'annotation'
    - creates layer called 'dim' + 'annotation' if it doesn't exist and changes its color to black
    version 1.0
    www.studiogijs.nl
    """

    #check if layer 'dim' exist, else create it
    if not rs.IsLayer("dim"): rs.AddLayer("dim")
    rs.LayerColor("dim", Col.Black)

    #check if layer 'annotation' exist, else create it
    if not rs.IsLayer("annotation"): rs.AddLayer("annotation")
    rs.LayerColor("annotation", Col.Black)

    objects = Rhino.RhinoDoc.ActiveDoc.Objects.FindByObjectType(
        Rhino.DocObjects.ObjectType.Annotation)

    for obj in objects:

        if type(obj) == Rhino.DocObjects.LeaderObject or type(
                obj) == Rhino.DocObjects.TextObject:
            rs.ObjectLayer(obj, "annotation")
        else:
            rs.ObjectLayer(obj, "dim")
Esempio n. 7
0
def checkCurvePosition(objs):
    layers = []
    for obj in objs:
        if rs.IsCurve(obj):
            if not isCurveOnCPlane(obj):
                # print "Curve {} not on Cplane".format(obj)
                rs.SelectObject(obj)
                layers.append(rs.ObjectLayer(obj))
        elif rs.IsPoint(obj):
            if not isPointOnCplane(obj):
                # print "Curve {} not on Cplane".format(obj)
                rs.SelectObject(obj)
                layers.append(rs.ObjectLayer(obj))
        else:
            print "object {} is not a curve or point".format(obj)

    # when an object is found on > 0 layers, prompt for proceed
    if len(layers) > 0:
        msg = "there were curves found on layers:\n"
        for layer in layers:
            msg = msg + "- " + layer + " \n"

        if rs.MessageBox(msg, 1) != 1:
            return False

    # else
    return True
Esempio n. 8
0
def plot_axes(xyz, e11, e22, e33, layer, sc=1):
    """ Plots a set of axes.

    Parameters
    ----------
    xyz : list
        Origin of the axes.
    e11 : list
        Normalised first axis component [x1, y1, z1].
    e22 : list
        Normalised second axis component [x2, y2, z2].
    e33 : list
        Normalised third axis component [x3, y3, z3].
    layer : str
        Layer to plot on.
    sc : float
         Size of the axis lines.

    Returns
    -------
    None

    """

    ex = rs.AddLine(xyz, add_vectors(xyz, scale_vector(e11, sc)))
    ey = rs.AddLine(xyz, add_vectors(xyz, scale_vector(e22, sc)))
    ez = rs.AddLine(xyz, add_vectors(xyz, scale_vector(e33, sc)))

    rs.ObjectColor(ex, [255, 0, 0])
    rs.ObjectColor(ey, [0, 255, 0])
    rs.ObjectColor(ez, [0, 0, 255])
    rs.ObjectLayer(ex, layer)
    rs.ObjectLayer(ey, layer)
    rs.ObjectLayer(ez, layer)
Esempio n. 9
0
def joinCurves(copies):

    # sortobjects per layer
    sorted_objects = {}
    for obj in copies:
        layer_name = rs.ObjectLayer(obj)

        if not (layer_name in sorted_objects):
            # add new list
            sorted_objects[layer_name] = []

        sorted_objects[layer_name].append(obj)

    # join curves per layer
    new_list = []
    for layer_name in sorted_objects:
        if len(sorted_objects[layer_name]) > 1:
            # list is at least 2 items
            list_result = rs.JoinCurves(sorted_objects[layer_name], True)
        else:
            list_result = sorted_objects[layer_name]

        for obj in list_result:
            rs.ObjectLayer(obj, layer_name)
            new_list.append(obj)

    return new_list
Esempio n. 10
0
def LightLocation(light, scale):
    if not rs.IsLight(light):
        return

    # Default light transform
    # NOTE: Point light direction is [0, 0, -1]
    position = rs.LightLocation(light)
    direction = rs.LightDirection(light)
    basis = BasisFromDirection(direction)

    # Modify transform according to light type
    lightType = "UnknownLight"
    if rs.IsPointLight(light):
        lightType = "PointLight"
        #clone = rs.AddPointLight(position)
    if rs.IsDirectionalLight(light):
        lightType = "DirectionalLight"
        #clone = rs.AddDirectionalLight(position, position + direction)
    if rs.IsSpotLight(light):
        lightType = "SpotLight"
        outer = rs.SpotLightRadius(light)
        inner = rs.SpotLightHardness(light) * outer
        # Encode spot parameters in basis lengths
        basis = [basis[0] * outer, basis[1] * inner, direction]
        #clone = rs.AddSpotLight(position + direction, outer, position)
        #rs.SpotLightHardness(clone, inner / outer)
    if rs.IsRectangularLight(light):
        # WARNING: Incomplete documentation for Rhino7 in RhinoScript reference:
        # https://developer.rhino3d.com/api/rhinoscript/light_methods/rectangularlightplane.htm
        lightType = "RectangularLight"
        quadVectors, quadLengths = rs.RectangularLightPlane(light)
        heightBasis = quadVectors[1] * quadLengths[0] / 2
        widthBasis = quadVectors[2] * quadLengths[1] / 2
        position = quadVectors[0] + heightBasis + widthBasis  # center
        direction = -quadVectors[3]  # negative of light direction
        # Encode quad dimensions in basis lengths
        basis = [widthBasis, heightBasis, direction]
        #corner = position - (widthBasis + heightBasis)
        #clone = rs.AddRectangularLight(corner, corner + widthBasis * 2, corner + heightBasis * 2)
    if rs.IsLinearLight(light):
        # Encode line segment in first basis
        lightType = "LinearLight"
        widthBasis = direction / 2
        position = position + widthBasis
        basis = [widthBasis, basis[1], -basis[0]]
        #clone = rs.AddLinearLight (position - widthBasis, position + widthBasis)

    # Create placeholder mesh
    # NOTE: light dimensions are not scaled
    placeholder = LocationMesh(position, basis)

    # NOTE: Lights have no corresponding exported block,
    # but the same notation will be used to configure lights in the exported model.
    # Unity import will render names unique with a _N suffix on the N copy
    # so block name is included as a prefix to facilitate matching
    # in the case that block instances names are not unique
    objectName = rs.ObjectName(light)
    rs.ObjectName(placeholder, lightType + "=" + objectName)
    rs.ObjectLayer(placeholder, rs.ObjectLayer(light))
    return placeholder
Esempio n. 11
0
def explodeTextObjects(objs):
    new_list = []

    for obj in objs:

        if rs.IsText(obj) and rs.LayerVisible(
                rs.ObjectLayer(obj)) and ("CNC" in rs.ObjectLayer(obj)):
            # only explode Text when
            # - layer visible
            # - CNC layer

            # polylines = convertTextToPolylines(ob)
            polylines = convertTextToPolylines2(obj)

            for polyline in polylines:
                new_list.append(polyline)

#            if ("CNC" in rs.ObjectLayer(obj)):
#                # rs.GetBoolean(text, "get", True)
#                # result = rs.TextObjectFont(obj, "Machine Tool Gothic")
#
#                # rs.MessageBox('test' + rs.TextObjectText(obj))
#                # polylines = rs.ExplodeText(obj, True)
#
#                polylines = convertTextToPolylines(obj)
#
#                for polyline in polylines:
#                    new_list.append(polyline)
#            else:
#                # add unexploded text
#                new_list.append(obj)
        else:
            new_list.append(obj)

    return new_list
Esempio n. 12
0
def BlockLocation(object, scale):
    # WARNING: The basis describes a transformation of the Rhino basis
    # with respect to the Rhino basis, which might not match the
    # import environment world basis.
    x = rs.BlockInstanceXform(object)
    p0 = [x.M00, x.M10, x.M20]  # X Basis direction
    p1 = [x.M01, x.M11, x.M21]  # Y Basis direction
    p2 = [x.M02, x.M12, x.M22]  # Z Basis direction
    p3 = [x.M03, x.M13, x.M23]  # Origin position
    # Rescale transform units
    for i in range(3):
        p0[i] /= scale
        p1[i] /= scale
        p2[i] /= scale
    # Construct basis tetrahedron
    placeholder = LocationMesh(p3, [p0, p1, p2])

    # Unity import will render names unique with a _N suffix on the N copy
    # so block name is included as a prefix to facilitate matching
    # in the case that block objects names are not unique
    block = rs.BlockInstanceName(object)
    block_name = SafeObjectName(block)
    object_name = rs.ObjectName(object)
    rs.ObjectName(placeholder, block_name + "=" + object_name)
    rs.ObjectLayer(placeholder, rs.ObjectLayer(object))
    return placeholder
def makePlan():
    """
    make2d from above.
    input: list of layers to make2d
    returns: None
    """
    objs = rs.ObjectsByGroup("Below")
    
    #Make2d
    rs.SelectObjects(objs)
    rs.Command("-_make2d _D _U _Enter")
    projLines = rs.GetObjects("", preselect = True)
    
    #Get make2d root layer
    make2dRootRaw = rs.ObjectLayer(projLines[0])
    make2dRoot = make2dRootRaw.split("::")[0]
    
    #Rename make2d layers
    root  = rs.AddLayer("60_PLANS")
    roofLay = rs.AddLayer("Roof", parent = root)
    for projLine in projLines:
        linesLayer = rs.ObjectLayer(projLine)
        linesColor = rs.ObjectColor(projLine)
        linesLayerName = rs.LayerName(linesLayer, fullpath = False)
        newLayers = rs.AddLayer(linesLayerName, parent = roofLay, color = linesColor)
        rs.ObjectLayer(projLine,newLayers)
        rs.ObjectColor(projLine, (200,200,200))
    
    #Delete make2d Layers
    rs.DeleteLayer(make2dRoot)
    return
Esempio n. 14
0
def convertTextToPolylines(obj):

    layer = rs.ObjectLayer(obj)
    polylines = rs.ExplodeText(obj, True)

    rs.ObjectLayer(polylines, layer)

    return polylines
Esempio n. 15
0
def swapParentLayer(obj, newparent):
    layer = rs.ObjectLayer(obj)
    if "::" in layer:
        splitlayer = layer.split("::")
        # currentParent = splitlayer[0]
        splitlayer[0] = newparent
        newlayer = "::".join(splitlayer)
        # newlayer = layer.replace(currentParent, newparent)
        rs.ObjectLayer(obj, newlayer)
Esempio n. 16
0
def addLevelMarks(func):
    rs.EnableRedraw(False)
    leftAlign = True
    geometry = []
    currentLevels = setLevels.getFloorLevels()
    for level in currentLevels:
        if level is None:
            print "Levels have not been set."
            return
    levelNames = rs.GetDocumentData("Levels")
    size = 10
    i = 0
    stPts = []
    for level in currentLevels:
        vec1 = [size*.2,size*.1,0]
        ptA = [0, level, 0]
        ptB = [size*.5, level, 0]
        stPts.append(ptA)
        geometry.append(rs.AddLine(ptA, ptB))
        geometry.append(rs.AddText(levelNames[i] + ": +" + str(level), rs.VectorAdd(ptA, vec1), size*.1))
                
        #Triangle Marking
        triPts = [[0,0,0], [size*.05, size*.07,0], [-size*.05, size*.07,0], [0,0,0]]
        newPts = []
        triPt = rs.VectorAdd(ptA, [size*.1, 0,0])
        for j in range(0, 4):
            newPts.append(rs.VectorAdd(triPt, triPts[j]))
        tri = rs.AddPolyline(newPts)
        geometry.append(rs.CloseCurve(tri))
        i=i+1
    
    #Dimensions
    for i in range(0, len(currentLevels)-1):
        pt1 = [0,currentLevels[i], 0]
        pt2 = [0,currentLevels[i+1], 0]
        pt3 = [size*-.15,currentLevels[i+1], 0]
        geometry.append(rs.AddAlignedDimension(pt1, pt2, pt3))
    firstPt = [0,currentLevels[0], 0]
    lastPt = [0,currentLevels[-1], 0]
    dimOffset = [size*-.3,currentLevels[-1], 0]
    geometry.append(rs.AddAlignedDimension(firstPt, lastPt, dimOffset))
    rs.AddLayer("80_LAYOUT", visible = True)
    annoLayer = rs.AddLayer("ANNO", parent = "80_LAYOUT")
    for geo in geometry:
        rs.ObjectLayer(geo, annoLayer)
    rs.AddBlock(geometry, [0,0,0], "Level Marks", True)
    if (func == 0):
        block = rs.InsertBlock("Level Marks", [0,0,0])
        rs.ObjectLayer(block, "ANNO")
    
    rs.EnableRedraw(True)
    return
Esempio n. 17
0
def main():
    path = rs.GetObject("Select Ramp Path", rs.filter.curve, True)
    if path is None: return

    if 'ramp-widthDefault' in sc.sticky:
        widthDefault = sc.sticky['ramp-widthDefault']
    else:
        widthDefault = 36
    if 'ramp-slopeDefault' in sc.sticky:
        slopeDefault = sc.sticky['ramp-slopeDefault']
    else:
        slopeDefault = 8.333

    width = rs.GetReal("Ramp Clear Width", widthDefault, minimum=36)
    if width is None: return
    slope = rs.GetReal("Ramp slope (e.g. 8.33%(1:12) is 8.33)", slopeDefault)
    if slope is None: return

    sc.sticky['ramp-widthDefault'] = width
    sc.sticky['ramp-slopeDefault'] = slope

    rs.EnableRedraw(False)
    rampGeoList = Ramp_HeightSlope(path, width, slope / 100)
    try:
        layers.AddLayerByNumber(402, False)
        layerName = layers.GetLayerNameByNumber(402)

        rs.ObjectLayer(rampGeoList[0], layerName)
        try:
            if rampGeoList[2] is not None:
                layers.AddLayerByNumber(106, False)
                layerName = layers.GetLayerNameByNumber(106)

                rs.ObjectLayer(rampGeoList[2], layerName)
        except:
            pass
        result = True
    except:
        result = False

    utils.SaveFunctionData('Architecture-ramp', [
        width, slope,
        str([(pt.X, pt.Y, pt.Z) for pt in rs.CurveEditPoints(path)]), result
    ])

    rs.EnableRedraw(True)

    print rampGeoList[1]

    utils.SaveToAnalytics('architecture-ramp')
def GetTriangulatedMeshes(layers_objects):
    #list to hold the list of layer object guids
    layers_objects_brep = []
    #for each layers list of lists
    for layer_objects in layers_objects:
        #create a new list to hold the layers list of guids represented as objrefs
        layer_objects_brep = []
        for layer_object in layer_objects:
            #convert the guid to a brep
            layer_brep = rs.coercebrep(layer_object)
            #if the obj ref for the object was returned
            if (layer_brep):
                #convert the brep into a mesh
                mesh = Rhino.Geometry.Mesh.CreateFromBrep(
                    layer_brep, smoothAndSlower)
                #if the mesh is not null
                if (mesh):
                    #create a new empty mesh objref
                    new_mesh = Rhino.Geometry.Mesh()
                    #for each face in the mesh list [of type array]
                    for m in mesh:
                        #add the mesh face to the new_mesh objref
                        new_mesh.Append(m)
                    #check if the new mesh contains any quad faces
                    #if(new_mesh and new_mesh.Faces.QuadCount > 0):
                    if (new_mesh):
                        #convert the facelist of the new_mesh objref
                        new_mesh_triangulated = new_mesh.Faces.ConvertQuadsToTriangles(
                        )
                        #if the new_mesh_triangulated was returned
                        if (new_mesh_triangulated):
                            #coerce the guid from the objref of the triangulate mesh [layer_object describes the guid that the objref was generated from]
                            id = rhutil.coerceguid(layer_object, True)
                            #add the guid of the triangulated mesh to the active document
                            added_mesh = scriptcontext.doc.Objects.AddMesh(
                                new_mesh)
                            #move the mesh to the layer of its source guid that generated the objref
                            rs.ObjectLayer(added_mesh,
                                           rs.ObjectLayer(layer_object))
                            #add the guid of the triangulated mesh to the layer_objects list
                            layer_objects_brep.append(added_mesh)
        #compare the length of the layer_objects_brep and the length of the layer_objects
        if (len(layer_objects_brep) == len(layer_objects)):
            #append the layer_objects_brep to the layers_objects_brep
            layers_objects_brep.append(layer_objects_brep)
    #if the length of the layers_objects_brep is equal to the length of layers_objects then return the layers_objects_brep list
    if (len(layers_objects_brep) == len(layers_objects)):
        return layers_objects_brep
    else:
        return False
Esempio n. 19
0
def convertToPolylines(obj):

    # get object properties
    text            = rs.TextObjectText(obj)
    pt              = rs.TextObjectPoint(obj)
    origin          = rs.coerce3dpoint([0,0,0])
    ht              = rs.TextObjectHeight(obj)
    object_layer    = rs.ObjectLayer(obj)
    plane           = rs.TextObjectPlane(obj)
        
    diff = rs.coerce3dpoint([pt.X, pt.Y, pt.Z])

    p1 = rs.WorldXYPlane()
        
    matrix = rs.XformRotation4(p1.XAxis, p1.YAxis, p1.ZAxis, plane.XAxis, plane.YAxis, plane.ZAxis)


    rs.DeleteObject(obj)
        


    # set current layer to put strings in
    prevlayer = rs.CurrentLayer()
    layer = rs.AddLayer('temptextlayer')
    rs.CurrentLayer('temptextlayer')

    # split text at enters
    text = text.split('\r\n')
    opts='GroupOutput=No FontName="timfont" Italic=No Bold=No Height='+ str(ht)
    opts+=" Output=Curves AllowOpenCurves=Yes LowerCaseAsSmallCaps=No AddSpacing=No "
    
    origin.Y += ht * len(text) *1.2
    for item in text:
        rs.Command("_-TextObject " + opts + '"'+item+'"' + " " + str(origin) , False)
        origin.Y -= ht *1.5
        
    #restore current layer
    rs.CurrentLayer(prevlayer)

    
    #select newly created texts
    polylines = rs.ObjectsByLayer('temptextlayer')
    
    # transform to old position
    rs.TransformObjects(polylines, matrix, copy=False)
    rs.MoveObjects(polylines, diff)
    
    rs.ObjectLayer(polylines, object_layer)
    
    return polylines
Esempio n. 20
0
def convertTextToPolylines2(obj):

    # get object properties
    text = rs.TextObjectText(obj)
    pt = rs.TextObjectPoint(obj)
    origin = rs.coerce3dpoint([0, 0, 0])
    ht = rs.TextObjectHeight(obj)
    object_layer = rs.ObjectLayer(obj)
    plane = rs.TextObjectPlane(obj)

    diff = rs.coerce3dpoint([pt.X, pt.Y, pt.Z])

    p1 = rs.WorldXYPlane()
    #restore view cplane
    rs.ViewCPlane(None, p1)

    matrix = rs.XformRotation4(p1.XAxis, p1.YAxis, p1.ZAxis, plane.XAxis,
                               plane.YAxis, plane.ZAxis)

    rs.DeleteObject(obj)

    # split text at enters
    text = text.split('\r\n')
    opts = 'GroupOutput=No FontName="' + EXPORT_FONT + '" Italic=No Bold=No Height=' + str(
        ht)
    opts += " Output=Curves AllowOpenCurves=Yes LowerCaseAsSmallCaps=No AddSpacing=No "

    n_lines = len(text)

    origin.Y += 1.6 * ht * (len(text) - 1)

    polylines = []
    for item in text:
        rs.Command(
            "_-TextObject " + opts + '"' + item + '"' + " " + str(origin),
            False)
        polylines += rs.LastCreatedObjects()
        origin.Y -= ht * 1.6

    rs.ObjectLayer(polylines, object_layer)

    polylines = rs.ScaleObjects(polylines, (0, 0, 0), (0.7, 1, 1), True)

    # transform to old position
    rs.TransformObjects(polylines, matrix, copy=False)
    rs.MoveObjects(polylines, diff)

    return polylines
Esempio n. 21
0
def get_inner_box(bb_dims, tol, T_IBOX, TOL_INSIDE):
    """input:
	bbdims float(w,l,h). l is longest dimension.
	tol float: percentage "give" to have
	T_IBOX: thickness in mm
	T_OBOX: thickness in mm
	TOL_INSIDE: additional absolute tolerance added to the inner dimension of the box
	return: 
	br: list of four points representing the bounding rectangle of the output.
	"""
    W = (1 + tol) * bb_dims[0] + T_IBOX * 2 + TOL_INSIDE * 2
    L = (1 + tol) * bb_dims[1] + T_IBOX * 2 + TOL_INSIDE * 2
    H = (1 + tol) * bb_dims[2] + T_IBOX * 2 + TOL_INSIDE * 1 - 0.1 * T_IBOX

    bottom = rs.AddRectangle(ORIGIN_IB, L - 2, W - 2)

    # top: overall dim - material + rabet - lid tolerance
    # print L - T_IBOX*2 - TOL_LID_ABSOLUTE*2
    # print L - T_IBOX*2 - TOL_LID_ABSOLUTE*2
    top = rs.AddRectangle([0, W + LCUT_GAP, 0],
                          L - T_IBOX * 2 - TOL_LID_ABSOLUTE * 2,
                          W - T_IBOX * 2 - TOL_LID_ABSOLUTE * 2)

    short_a = rs.AddRectangle([L + LCUT_GAP, 0, 0], W - 2 * T_IBOX, H - T_IBOX)
    short_b = rs.AddRectangle([L + LCUT_GAP, H + LCUT_GAP - T_IBOX, 0],
                              W - 2 * T_IBOX, H - T_IBOX)
    long_a = rs.AddRectangle([L + W + LCUT_GAP * 2 - 2 * T_IBOX, 0, 0], L,
                             H - T_IBOX)
    long_b = rs.AddRectangle(
        [L + W + LCUT_GAP * 2 - 2 * T_IBOX, H + LCUT_GAP - T_IBOX, 0], L,
        H - T_IBOX)

    grip_data = make_slots(bb_dims[0], bb_dims[1])
    desired_grip_gap = 130
    if bb_dims[1] > desired_grip_gap * 1.4:
        slots = add_slots(top, grip_data, desired_grip_gap)
    else:
        slots = add_slots(top, grip_data, bb_dims[1] / 20)
    rs.ObjectLayer(slots, LCUT_NAMES[1])

    all_geo = [bottom, top, short_a, short_b, long_a, long_b]
    rs.ObjectLayer(all_geo, LCUT_NAMES[1])

    br = rs.BoundingBox(all_geo)[:4]

    SELECT_GUIDS.extend(all_geo)
    SELECT_GUIDS.extend(slots)
    return br
Esempio n. 22
0
def drawDivisionLine(emblem, color=True):
    objs = []
    # line
    r = 24
    for i in range(int(emblem.division)):
        p = [r, 0, 0]
        if (emblem.division % 4 == 0):
            angle = i * 360.0 / emblem.division + 360.0 / emblem.division / 2.0
        else:
            angle = i * 360.0 / emblem.division
        p = rs.VectorRotate(p, angle, [0, 0, 1])
        obj = rs.AddLine([0, 0, 0], p)
        if (color):
            layer = "line%s" % (i % int(emblem.division / 2.0))
        else:
            layer = "lineGray"
        rs.ObjectLayer(obj, layer)
        objs.append(obj)
    # circle
    obj = rs.AddCircle([0, 0, 0], r)
    if (color):
        layer = "lineBlack"
    else:
        layer = "lineGray"
    rs.ObjectLayer(obj, layer)
    objs.append(obj)
    # text
    planeOri = rs.ViewCPlane()
    for i in range(int(emblem.division / 2.0)):
        if (emblem.division % 4 == 0):
            angle = i * 360.0 / emblem.division + 360.0 / emblem.division / 2.0
        else:
            angle = i * 360.0 / emblem.division
        p = [r, 0, 0]
        txt = "%d" % (angle)
        height = 1.2
        pt = [0, height / 2.0, 0]
        font_style = 0
        justification = 2 + 65536
        obj = rs.AddText(txt, pt, height, font, font_style, justification)
        rs.RotateObject(obj, [0, 0, 0], -90.0, [0, 0, 1], False)
        rs.MoveObject(obj, [r, 0, 0])
        rs.RotateObject(obj, [0, 0, 0], angle, [0, 0, 1], False)
        rs.ObjectLayer(obj, "textLine")
        objs.append(obj)
        rs.ViewCPlane(None, planeOri)
    #return
    return objs
Esempio n. 23
0
 def get_frame_instance_pair(cls, rule):
     """Receives:
         rule            str. The name of a layer containing two frame 
                         instances (i.e., a rule layer). The value is 
                         guaranteed
     Returns:
         ordered_frame_instance_pair
                         (guid, guid). A pair of the guids of the two frame 
                         instances on the layer, ordered from left to right 
     """
     all_frame_instances = rs.BlockInstances(s.Settings.frame_name)
     frame_instances = []
     for instance_i in all_frame_instances:
         if rs.ObjectLayer(instance_i) == rule:
             frame_instances.append(instance_i)
     p0 = f.Frame.get_instance_position(frame_instances[0])
     p1 = f.Frame.get_instance_position(frame_instances[1])
     if p0 < p1:
         ordered_frame_instance_pair = (
             frame_instances[0], frame_instances[1])
     elif p0 > p1:
         ordered_frame_instance_pair = (
             frame_instances[1], frame_instances[0])
     else:
         pass
     return ordered_frame_instance_pair
def addComponent():
    libPath = 'C:\\Users\\Tim\\Desktop\\temp\\library'
    rhinoFiles = []

    items = os.listdir(libPath)

    if items is None:
        print "Library is empty or path is wrong"
        return

    for item in items:
        parts = item.split(".")
        if len(parts) == 2:
            if parts[1] == "3dm":
                rhinoFiles.append(parts[0])

    choice = rs.ComboListBox(rhinoFiles, "Select Components to add",
                             "add Component")
    if choice is None:
        return
    choiceFile = choice + ".3dm"
    rs.EnableRedraw(False)
    rs.Command('-_NoEcho _-Import ' + libPath + "\\" + choiceFile +
               ' Objects Enter -_SelLast Enter')
    importedGeo = rs.GetObjects(preselect=True)
    rs.ObjectLayer(importedGeo, rs.CurrentLayer())
    rs.SelectObjects(importedGeo)
    rs.EnableRedraw(True)
def NewFracturesGuids(dom_new_fractures, fracture_list):
    """
    function to swap old guids to new ones in fracture objects
    and return new guids.
    Deletes previous fractures and swap the layers of new fractures
    with those of old ones

    Parameter
    --------
    fracture_list: list
        list of old fracture objects
    dom_new_fractures: list
        list of new fracture objects
    """
    # initialise list for guids
    guids = []
    for i in range(len(fracture_list)):
        # delete previous fractures
        rs.DeleteObject(fracture_list[i].fracture_GUID)
        # change the guid of our fracture instances
        fracture_list[i].fracture_GUID = dom_new_fractures[i]
        guids.append(dom_new_fractures[i])
        # put new fractures in old layers
        rs.ObjectLayer(dom_new_fractures[i], fracture_list[i].fracture_name)
    return guids
Esempio n. 26
0
def vector_sum(lines, preview=False):

    vector_list = []
    total_time = 0
    total_length = 0
    last_feed = 0
    for i in range(len(lines)):
        point_a = lines[i][:3]
        if i == len(lines) - 1: break
        point_b = lines[i + 1][:3]
        vector = rs.AddLine(point_a, point_b) if preview else rs.VectorCreate(
            point_a, point_b)
        if preview:
            rs.ObjectLayer(vector, LAYER_NAME)
            rs.ObjectColor(vector, color_palette["cut"])
        vector_list.append(vector)
        if len(lines[i]) == 4:
            feed = lines[i][-1]
            last_feed = feed

        vector_length = rs.CurveLength(vector) if preview else rs.VectorLength(
            vector)
        total_length += vector_length
        total_time += (vector_length) / last_feed

    return vector_list, round(total_time, 2), round(total_length, 2)
Esempio n. 27
0
def main():
    object_id = rs.GetObject("Select an object to sort")
    if object_id is None: return

    object_type = rs.ObjectType(object_id)
    if object_type is None: return

    layer_name = "Unsorted"
    if object_type == 1 or object_type == 2:
        layer_name = "Points"
    elif object_type == 4:
        layer_name = "Curves"
    elif object_type == 8 or object_type == 16:
        layer_name = "PolySurfaces"
    elif object_type == 32:
        layer_name = "Meshes"
    elif object_type == 256:
        layer_name = "Lights"
    elif object_type == 512 or object_type == 8192:
        layer_name = "Annotations"
    elif object_type == 2048 or object_type == 4096:
        layer_name = "Blocks"

    if not rs.IsLayer(layer_name):
        rs.AddLayer(layer_name)
    rs.ObjectLayer(object_id, layer_name)
Esempio n. 28
0
 def get_frame_instance(cls, initial_shape):
     """Receives:
         initial_shape   str. The name of a layer containing one frame 
                         instance (i.e., an initial shape layer). The value 
                         is guaranteed
     Returns:
         frame_instance  guid. The guid of the frame instance on the layer 
                         Isn't this redundant?
     """
     if not rs.IsLayer(initial_shape):
         message = "There is no layer named '%s'" % initial_shape
     all_frame_instances = rs.BlockInstances(s.Settings.frame_name)
     frame_instances_on_layer = []
     for frame_instance in all_frame_instances:
         if rs.ObjectLayer(frame_instance) == initial_shape:
             frame_instances_on_layer.append(frame_instance)
     n_instances = len(frame_instances_on_layer)
     if n_instances == 0:
         message = "%s %s" % (
             "There is no frame instance", 
             "on the layer '%s'" % initial_shape)
         return_value = None
     elif n_instances == 1:
         message = None
         return_value = frame_instances_on_layer.pop()
     else:
         message = "%s %s" % (
             "There is more than 1 frame instance", 
             "on the layer '%s'" % initial_shape)
         return_value = None
     if message:
         print(message)
     return return_value
def LockAllOtherLayers():
    try:
        obj = rs.GetObject(message="Select the object on the layer you want to stay unlocked", filter=0,
                           preselect=True, select=False, custom_filter=None, subobjects=False)

        rs.EnableRedraw(False)

        groupName = random.random()

        layer = rs.ObjectLayer(obj)
        objs = rs.ObjectsByLayer(layer, select=False)
        allobj = rs.AllObjects(select=True, include_lights=False,
                               include_grips=False, include_references=False)
        rs.UnselectObjects(objs)
        toBeLockedObj = rs.SelectedObjects()
        rs.UnselectAllObjects()

        group = rs.AddGroup(groupName)
        rs.AddObjectsToGroup(toBeLockedObj, group)

        rs.LockGroup(groupName)

        rs.DeleteGroup(groupName)

        rs.EnableRedraw(True)

    except:
        rs.EnableRedraw(True)
        print("Failed to execute")
        return
def cutAtPlan(level):
    planPlane = rs.AddPlaneSurface([-1000,-1000,level], 3000, 3000)
    baseLayer = rs.AddLayer("60_PLANS")
    newParent = rs.AddLayer("PLAN_"+str(level), parent = baseLayer)
    origLayer = rs.CurrentLayer()
    shortName = rs.LayerName(origLayer, fullpath = False)
    
    #newChildsParent = rs.AddLayer( , parent = newParent)
    newChild = rs.AddLayer(shortName, parent = newParent, color = rs.LayerColor(origLayer))
    rs.CurrentLayer(newChild)
    
    objs = rs.ObjectsByLayer(origLayer)
    #if len(objs)<1:
    #    skip = True
    intersectCrvs = []
    tempCrv = None
    for obj in objs:
        if rs.IsBrep(obj):
            
            tempCrv = rs.IntersectBreps(obj, planPlane)
        if tempCrv != None:
            intersectCrvs.append(tempCrv)
    
    for crv in intersectCrvs:
        if not None:
            rs.ObjectLayer(crv, newChild)
    
    rs.DeleteObject(planPlane)
    rs.CurrentLayer(origLayer)