Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def createcurve(index, offset, np, c_x, c_z):
    #List definition
    pts = []
    
    #Layer creation
    rs.AddLayer("PythonCurve", Color.Blue)
    rs.AddLayer("PythonCosineCurve", Color.Aquamarine)
    rs.AddLayer("CosineCurve", Color.Red)
    rs.AddLayer("CosineSurface", Color.AliceBlue)
    
    ##################Geometric Operations##################
    
    if index%2 == 0:
        f = sin
    else:
        f = cos
    
    
    rs.CurrentLayer("CosineCurve")
    
    for i in range(np):
        #x = 50 + i*c_x
        x = i*c_x
        y = 0 + offset
        z = f(i*c_z)
        
        pts.append([x,y,z])
        
    #rs.addInterpCurve(pts)
    return rs.AddInterpCurve(pts, 3,0)
Ejemplo n.º 3
0
def import_file(name):
    """Import file with name specified relative to script path."""

    if (name[-4:] == "json"):

        layer = name[:-5]

        rs.AddLayer(layer)

        rs.CurrentLayer(layer)

        json_file_path = geo_path + name

        with open(json_file_path) as json_file:
            json_data = json.load(json_file)

        features = json_data["features"]

        for feature in features:

            sublayer = get_sublayer_name(feature["properties"])

            rs.AddLayer(sublayer, parent=layer)
            rs.CurrentLayer(layer + '::' + sublayer)

            import_feature(feature)
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)
Ejemplo n.º 5
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")
Ejemplo n.º 6
0
def layer(name):
    if rs.IsLayer(name):
        return name
    else:
        if name != "porcupines":
            return rs.AddLayer(name, parent="porcupines")
        else:
            return rs.AddLayer(name)
Ejemplo n.º 7
0
def plot_reaction_forces(structure, step, layer=None, scale=1.0):
    """ Plots reaction forces for the Structure analysis results.

    Parameters
    ----------
    structure : obj
        Structure object.
    step : str
        Name of the Step.
    layer : str
        Layer name for plotting.
    scale : float
        Scale of the arrows.

    Returns
    -------
    None

    """

    if not layer:
        layer = '{0}-{1}'.format(step, 'reactions')

    rs.CurrentLayer(rs.AddLayer(layer))
    rs.DeleteObjects(rs.ObjectsByLayer(layer))
    rs.EnableRedraw(False)

    rfx = structure.results[step]['nodal']['rfx']
    rfy = structure.results[step]['nodal']['rfy']
    rfz = structure.results[step]['nodal']['rfz']

    nkeys = rfx.keys()
    v = [scale_vector([rfx[i], rfy[i], rfz[i]], -scale * 0.001) for i in nkeys]
    rm = [length_vector(i) for i in v]
    rmax = max(rm)
    nodes = structure.nodes_xyz(nkeys)

    for i in nkeys:

        if rm[i] > 0.001:
            l = rs.AddLine(nodes[i], add_vectors(nodes[i], v[i]))
            rs.CurveArrows(l, 1)
            col = [
                int(j) for j in colorbar(rm[i] / rmax, input='float', type=255)
            ]
            rs.ObjectColor(l, col)
            vector = [rfx[i], rfy[i], rfz[i]]
            name = json.dumps({
                'rfx': rfx[i],
                'rfy': rfy[i],
                'rfz': rfz[i],
                'rfm': length_vector(vector)
            })
            rs.ObjectName(l, '_' + name)

    rs.CurrentLayer(rs.AddLayer('Default'))
    rs.LayerVisible(layer, False)
    rs.EnableRedraw(True)
Ejemplo n.º 8
0
 def initLayers(self):
     #propagate required layers
     parent = get_layer_name('LOCKEDLAYERS')
     rs.AddLayer(get_layer_name('LOCKEDLAYERS'), locked=False)
     for phase in PHASES:
         lay = get_layer_name(phase)
         if not rs.IsLayer(lay): rs.AddLayer(lay, locked=False)
         else: rs.LayerLocked(lay, False)
         #rs.ParentLayer(lay,parent)
     rs.ExpandLayer(parent, False)
Ejemplo n.º 9
0
    def CreateReferenceLayers(self, parentPrefix, refLayers, norefLayers,
                              colours):
        # get timestamp
        ts = time.strftime("%y%m%d_%H-%M")

        # create parent layer name
        parentLayername = parentPrefix + ts
        self.Message = "Referenced: " + str(parentLayername)

        # check if parent layer exists
        sc.doc = Rhino.RhinoDoc.ActiveDoc
        exists = rs.IsLayer(parentLayername)

        if exists:
            self.AddRuntimeMessage(
                self.RuntimeMessageLevel.Remark,
                "Parent Layer already exists! Returning valid existing layers."
            )
            # get all children layers
            allchildren = rs.LayerChildren(parentLayername)
            # check all children layers for validity
            validchildren = [parentLayername + "::" + vc for vc in refLayers]
            realchildren = []
            for c in allchildren:
                if c in validchildren:
                    realchildren.append(c)
            # set sticky to real found child layers
            st[self.LNKEY] = realchildren

            # switch back to ghdoc
            sc.doc = ghdoc

            # return layer names
            return realchildren
        else:
            # switch to Rhino doc
            sc.doc = Rhino.RhinoDoc.ActiveDoc
            # create parent layer
            parentLayer = rs.AddLayer(parentLayername, Color.Black)

            # create referenced layers
            newLayers = []
            for i, rl in enumerate(refLayers + norefLayers):
                lay = rs.AddLayer(rl, colours[i], parent=parentLayername)
                if rl in refLayers:
                    newLayers.append(lay)

            # add them to the sticky
            st[self.LNKEY] = newLayers

            # switch back to ghdoc
            scdoc = ghdoc

            # return layer names/paths
            return newLayers
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def setLayer():
    # ---emblem
    if not rs.IsLayer("emblem"):
        ptsLayer = rs.AddLayer("emblem",
                               Color.FromArgb(0, 0, 0),
                               visible=True,
                               locked=False,
                               parent=None)

    # ---emblem.lineBlack
    if not rs.IsLayer("lineBlack"):
        ptsLayer = rs.AddLayer("lineBlack",
                               Color.FromArgb(0, 0, 0),
                               visible=True,
                               locked=False,
                               parent="emblem")
    # ---emblem.lineGray
    if not rs.IsLayer("lineGray"):
        ptsLayer = rs.AddLayer("lineGray",
                               Color.FromArgb(200, 200, 200),
                               visible=True,
                               locked=False,
                               parent="emblem")
    # ---emblem.rhomboidText
    if not rs.IsLayer("textRhomboid"):
        ptsLayer = rs.AddLayer("textRhomboid",
                               Color.FromArgb(0, 0, 0),
                               visible=True,
                               locked=False,
                               parent="emblem")
    # ---emblem.lineGray
    if not rs.IsLayer("srfRhomboid"):
        ptsLayer = rs.AddLayer("srfRhomboid",
                               Color.FromArgb(200, 200, 200),
                               visible=True,
                               locked=False,
                               parent="emblem")
    # ---emblem.line,srf
    for i in range(12):
        if not rs.IsLayer("line%s" % i):
            r = random.randint(0, 255)
            g = random.randint(0, 255)
            b = random.randint(0, 255)
            ptsLayer = rs.AddLayer("line%s" % i,
                                   Color.FromArgb(r, g, b),
                                   visible=True,
                                   locked=False,
                                   parent="emblem")
            ptsLayer = rs.AddLayer("srf%s" % i,
                                   Color.FromArgb(r, g, b),
                                   visible=True,
                                   locked=False,
                                   parent="emblem")
    # ---emblem.parallelLine.lineText
    if not rs.IsLayer("textLine"):
        ptsLayer = rs.AddLayer("textLine",
                               Color.FromArgb(0, 0, 0),
                               visible=True,
                               locked=False,
                               parent="emblem")
Ejemplo n.º 12
0
 def _new_definition(cls):
     """Requires:
         A frame definition does not already exist
         A layer named <frame_layer_name> does not already exist
     Creates a frame definition on its own layer. Returns:
         frame_name_out  str. The name of the frame definition
     """
     (   layer_name, 
         color_name
     ) = (
         s.Settings.frame_layer_name, 
         s.Settings.frame_color_name)
     rs.AddLayer(layer_name, color_name)
     rs.CurrentLayer(layer_name)
     (   line_guids, 
         base_point, 
         frame_name_in,
         delete_input
     ) = (
         cls._get_guids(), 
         s.Settings.frame_base_point,
         s.Settings.frame_name,
         True)
     frame_name_out = rs.AddBlock(
         line_guids, base_point, frame_name_in, delete_input)
     (   default_layer_name
     ) = (
         s.Settings.default_layer_name)
     rs.CurrentLayer(default_layer_name)
     return frame_name_out
Ejemplo n.º 13
0
    def create(self):
        """Creates layer within Rhino, including all ancestors.
        Returns:
          self
        """

        if rs.IsLayer(self.name):

            return self

        mom = ""

        for s in self.path:

            son = s if (mom == "") else (mom + "::" + s)

            mommy = None if mom == "" else mom

            if not rs.IsLayer(son):

                rs.AddLayer(s,
                            color=None,
                            visible=True,
                            locked=False,
                            parent=mommy)

            mom = son

        return self
Ejemplo n.º 14
0
def create_layers_from_path(path, separator='::'):
    """Create a nested layer structure from a hierarchical path string.

    Parameters
    ----------
    path : str
        The path string.
    separator : str, optional

    Examples
    --------
    The following snippet will created 3 nested layers,
    with "COMPAS" at the root level, "Datastructures" at the first nested level, and "Mesh" at the deepest level.

    * COMPAS
      * Datastructures
        * Mesh

    .. code-block:: python

        create_layers_from_path("COMPAS::Datastructures::Mesh")

    """
    names = path.split(separator)
    parent = None
    for name in names:
        if parent:
            name = parent + separator + name
        if not rs.IsLayer(name):
            rs.AddLayer(name)
        parent = name
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
def draw_harmonic_disp(path, amp, name):
    nodes, elements = get_nodes_elements_from_result_files(path)
    har_disp, freqs = get_harmonic_data_from_result_files(path)
    vkeys = sorted(nodes.keys(), key=int)
    vert = [[nodes[k]['x'], nodes[k]['y'], nodes[k]['z']] for k in vkeys]
    fkeys = sorted(elements.keys(), key=int)
    faces = [elements[k]['topology'] for k in fkeys]
    dkeys = sorted(har_disp.keys(), key=int)
    for freq in freqs:
        print freq
        lname = 'freq ' + str(round(freq, 2)) + 'Hz'
        rs.AddLayer(lname)
        rs.CurrentLayer(lname)
        disp = [har_disp[k][freq]['real'] for k in dkeys]
        disp = [[disp[k]['x'] * amp, disp[k]['y'] * amp, disp[k]['z'] * amp]
                for k in dkeys]
        dvert = []
        dlens = []
        for i in range(len(vert)):
            v = vert[i]
            d = disp[i]
            dlens.append(sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]))
            dvert.append([v[0] + d[0], v[1] + d[1], v[2] + d[2]])
        colors = []
        maxd = max(dlens)
        mind = min(dlens)
        if mind == maxd:
            colors = [0, 0, 0] * len(vert)
        else:
            for dlen in dlens:
                value = (dlen - mind) / (maxd - mind)
                colors.append(i_to_rgb(value))
        rs.AddMesh(dvert, faces, vertex_colors=colors)
Ejemplo n.º 17
0
def NewPart():
    """Create a 'New Part' layer as a sublayer of '30_3D'."""

    input_obj = rs.SelectedObjects()
    layers = rs.LayerNames()

    if "30_3D" not in layers:
        rs.AddLayer("30_3D")

    for i in range(1, 30):
        new_layer = "30_3D::3{}_Part".format(i)
        if new_layer not in layers:
            rs.AddLayer("3{}_Part".format(i), parent="30_3D")
            if input_obj:
                rs.ObjectLayer(input_obj, new_layer)
            return
Ejemplo n.º 18
0
 def __init__(self, tPop, gen):
     self.totalPopulation = tPop
     self.generation = gen
     self.population = []
     self.selectedPlanes = {}
     newLayer = rs.AddLayer("generation: " + str(generation))
     rs.CurrentLayer(newLayer)
Ejemplo n.º 19
0
def CopyObjectsToLayer():
    "Copy selected objects to a different layer"
    # Get the objects to copy
    objectIds = rs.GetObjects("Select objects")
    # Get all layer names
    layerNames = rs.LayerNames()
    if (objectIds == None or layerNames == None): return

    # Make sure select objects are unselected
    rs.UnselectObjects(objectIds)

    layerNames.sort()
    # Get the destination layer
    layer = rs.ComboListBox(layerNames,
                            "Destination Layer <" + rs.CurrentLayer() + ">")
    if layer:
        # Add the new layer if necessary
        if (not rs.IsLayer(layer)): rs.AddLayer(layer)
        # Copy the objects
        newObjectIds = rs.CopyObjects(objectIds)

        # Set the layer of the copied objects
        [rs.ObjectLayer(id, layer) for id in newObjectIds]
        # Select the newly copied objects
        rs.SelectObjects(newObjectIds)
Ejemplo n.º 20
0
def Export():
    count = 0
    folder = ChooseFolderPath()
    layer_names = rs.LayerNames()
    newDefaultLayer = 'NewDefault'
    rs.AddLayer(newDefaultLayer)
    rs.CurrentLayer(newDefaultLayer)

    for l in layer_names:
        if l != newDefaultLayer:
            for t in layer_names:
                if rs.IsLayer(l):
                        if l != newDefaultLayer:
                            rs.LayerVisible(t, False)
                else:
                    print "The layer does not exist."
            rs.LayerVisible(l, True)
            if rs.CurrentLayer() == l:
                break
            """answer = rs.MessageBox("Continue?", 1 | 32)
            if answer is 2: break
            rs.Sleep(1000)"""
            Render(folder, count)
            count += 1
            rs.LayerVisible(l, False)
    for l in layer_names:
        if l != newDefaultLayer:
            rs.LayerVisible(l, False)
            rs.CurrentLayer(l)
    rs.DeleteLayer(newDefaultLayer)
Ejemplo n.º 21
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
Ejemplo n.º 22
0
def lay_rand():

    if rs.IsLayer("Temporary"):
        str_rand = str(random.randrange(0, 9999999999))
        print str_rand
        if not rs.IsLayer(str_rand):
            lay_temp = rs.AddLayer(str_rand,randomcolor())
            rs.ParentLayer(lay_temp,"Temporary")
            rs.CurrentLayer(lay_temp)
            return lay_temp
        else:
            lay_rand();
            print "The random already exists, rerandomizing"
    else:
        rs.AddLayer("Temporary",Color.DarkViolet)
        lay_rand();
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
def main():

    try:
        check_output("python E:\python\gsheets\quickstart.py", shell=True)
        print 'tooltable updated'
    except:
        print 'NOT updated'

    tools = []

    with open('output.txt') as fp:
        # read header
        line = fp.readline()
        # read first line
        line = fp.readline()
        cnt = 1
        while line:
            list = line.split(',')
            # print cnt, list[1]

            tools.append(list[0] + " - " + list[1])

            line = fp.readline()
            cnt += 1

    tools = tuple(tools)

    form = AnnotateForm(tools)
    if (form.ShowDialog() == DialogResult.OK):
        #  this block of script is run if the user pressed the apply button
        layername = form.getLayerName()

        if layername != '':
            rs.AddLayer(name=layername, parent="CNC")
            rs.MessageBox(layername)
Ejemplo n.º 25
0
    def AddThisLayer(thisLayerData, counter):
        ##########################
        isRoot = False
        try:
            counter += 1
            if counter > 4:
                print "Loooop detected"
                return
            int(thisLayerData[parentColumn])
            parentLayData = layerData[thisLayerData[parentColumn]]
            parentLay = AddThisLayer(parentLayData, counter)
        except:
            isRoot = True
            parentLay = None
        ##########################
        if rs.IsLayer(thisLayerData[fullLayerNameColumn]):
            rootLayers.append(thisLayerData[fullLayerNameColumn])

            return thisLayerData[fullLayerNameColumn]
        newLayer = rs.AddLayer(thisLayerData[fullLayerNameColumn],
                               thisLayerData[colorColumn])
        rs.LayerLinetype(newLayer, thisLayerData[linetypeColumn])
        rs.LayerPrintColor(newLayer, thisLayerData[printcolorColumn])
        rs.LayerPrintWidth(newLayer, thisLayerData[printwidthColumn])
        try:
            MaterialToLayer(newLayer, thisLayerData[materialColumn])
        except:
            print "Material failed"
            #pass

        if isRoot:
            rootLayers.append(newLayer)
        return newLayer
Ejemplo n.º 26
0
def iterate():
    colDelta = 20
    origLayer = rs.GetLayer("Select Layer to Iterate")
    if origLayer is None:
        return

    shortName = origLayer.split("::")[-1]
    parentLay = rs.ParentLayer(origLayer)
    nameParts = shortName.split("_")
    if len(nameParts) > 1:
        num = int(nameParts[1]) + 1
    else:
        num = 1
    if len(str(num)) == 1:
        newNum = "0" + str(num)
    else:
        newNum = str(num)
    newName = nameParts[0] + "_" + newNum
    lay1 = rs.CurrentLayer(origLayer)

    #MAterials
    matIndex = rs.LayerMaterialIndex(lay1)

    #New Color
    oldCol = rs.LayerColor(lay1)
    oldRed = rs.ColorRedValue(oldCol)
    oldGreen = rs.ColorGreenValue(oldCol)
    oldBlue = rs.ColorBlueValue(oldCol)

    newRed = oldRed + randCol(colDelta)
    if newRed > 255:
        newRed = 255 - (newRed - 255)
    if newRed < 0:
        newRed = abs(newRed)

    newGreen = oldGreen + randCol(colDelta)
    if newGreen > 255:
        newGreen = 255 - (newGreen - 255)
    if newGreen < 0:
        newGreen = abs(newGreen)

    newBlue = oldBlue + randCol(colDelta)
    if newBlue > 255:
        newBlue = 255 - (newBlue - 255)
    if newBlue < 0:
        newBlue = abs(newBlue)
    newCol = (newBlue, newGreen, newBlue)
    newLay = rs.AddLayer(newName, color=newCol, parent=parentLay)
    #print nameParts
    #print newName
    finalLayer = rs.CurrentLayer(newLay)
    #sc.doc.Layers.CurrentLayer.RenderMaterialIndex = 3
    #c = sc.doc.Layers.CurrentLayer.RenderMaterialIndex
    #sc.doc.Layers.Modify(
    #Rhino.DocObjects.Tables.LayerTable.CurrentLayer.r
    #sc.doc.Views.Redraw()
    #b = sc.doc.Layers.CurrentLayer
    #print ""
    return
Ejemplo n.º 27
0
def layerSet(text, color):
    #deletes existing information regarding this layer
    if rs.LayerId(text):
        rs.DeleteObjects(rs.ObjectsByLayer(text))
        rs.PurgeLayer(text)

    #recomputes layer as new layer
    rs.AddLayer(text, color)
Ejemplo n.º 28
0
    def checkName():
        block_name = rs.GetString("enter block name")
        if block_name == '' or block_name == None:
            print "block name can't be empty"
            return checkName()
        #check if layer Block_Definitions exist, else create it
        if not rs.IsLayer("Block_Definitions"):
            rs.AddLayer("Block_Definitions")

        #check if layer with block name exists, else create it
        if not rs.IsLayer("Block_Definitions::" + block_name):
            block_layer = rs.AddLayer(block_name, parent="Block_Definitions")

        else:
            print "block definition with this name already exists"
            return checkName()
        return block_layer, block_name
Ejemplo n.º 29
0
 def clean_layers(self):
     
     try:
         rs.LayerLocked(PREVIEW_LAYER_NAME,False)
         rs.LayerLocked(LAYER_CLUSTER,False)
         rs.LayerLocked(LAYER_SORTING,False)
         rs.DeleteObjects(rs.ObjectsByLayer(PREVIEW_LAYER_NAME))
         rs.DeleteObjects(rs.ObjectsByLayer(LAYER_CLUSTER))
         rs.DeleteObjects(rs.ObjectsByLayer(LAYER_SORTING))
     except:
         preview_layer = rs.AddLayer(PREVIEW_LAYER_NAME, color=0, visible=True, locked=True, parent=None)
         rs.AddLayer(LAYER_SORTING, color=0, visible=True, locked=True, parent=preview_layer)
         rs.AddLayer(LAYER_CLUSTER, color=0, visible=True, locked=True, parent=preview_layer)
             
     rs.LayerLocked(PREVIEW_LAYER_NAME,True)
     rs.LayerLocked(LAYER_SORTING,True)
     rs.LayerLocked(LAYER_CLUSTER,True)
Ejemplo n.º 30
0
 def new(cls, name_in):
     """Receives:
         name_in         str. A well-formed and available layer name
     Adds a layer named <name_in>. Returns:
         name_out        str. The name of the layer
     """
     name_out = rs.AddLayer(name_in)
     return name_out