コード例 #1
0
def find_objects_on_layer(name, include_hidden=True, include_children=True):
    if include_hidden:
        show_hidden_objects_on_layer(name)
    to_delete = rs.ObjectsByLayer(name)
    if include_children:
        to_visit = deque(rs.LayerChildren(name))
        while to_visit:
            name = to_visit.popleft()
            if include_hidden:
                show_hidden_objects_on_layer(name)
            to_delete += rs.ObjectsByLayer(name)
            if rs.LayerChildCount(name):
                to_visit.extend(rs.LayerChildren(name))
    return to_delete
コード例 #2
0
def main():
    rs.EnableRedraw(enable=False)

    notes = sc.doc.Notes
    if notes:
        variables = notes.split("\r")
        vardict = {}
        for variable in variables:
            var = variable.split("=")
            var = list([x.strip() for x in var])
            vardict[var[0]] = var[1]

    allLayers = rs.LayerNames()
    topList = []
    for layer in allLayers:
        if rs.LayerChildCount(layer) > 0:
            if re.search("::", layer):
                layer = layer.split("::")[0]
            if re.search("^L\d", layer) or re.search(
                    "^R\d", layer) or re.search("^M\d", layer) or re.search(
                        "^P\d",
                        layer) or re.search("^SECTION ", layer) or re.search(
                            "^ROOFPLAN", layer) or re.search("^SOLIDS", layer):
                topList.append(layer)
    topList = sorted(list(set(topList)))
    thisLayer = rs.CurrentLayer()

    topList.append("TURN ALL ON")
    destinationLayer = rs.ListBox(topList, "Layer To Activate")

    if not destinationLayer:
        print("No Layer Selected")
        return None
    elif destinationLayer == "TURN ALL ON":
        topList.remove(destinationLayer)
        for layer in topList:
            sc.doc = Rhino.RhinoDoc.ActiveDoc
            rs.LayerVisible(layer, True)
            rs.ExpandLayer(layer, False)
    else:
        topList.remove("TURN ALL ON")
        topList.remove(destinationLayer)
        rs.CurrentLayer(layer=destinationLayer)
        rs.ExpandLayer(destinationLayer, True)
        for layer in topList:
            sc.doc = Rhino.RhinoDoc.ActiveDoc
            rs.LayerVisible(layer, False)
            rs.ExpandLayer(layer, False)
    print(destinationLayer)
    rs.EnableRedraw(enable=True)
コード例 #3
0
    def LoadCurrentLayers(self, refLayers):
        # switch to RhinoDoc
        sc.doc = Rhino.RhinoDoc.ActiveDoc

        # retrieve current layer
        cl = rs.CurrentLayer()

        # check childcount
        childcount = rs.LayerChildCount(cl)

        # if no children, layer has to be childlayer or unrelated
        if childcount == 0:
            # get parent layer
            parent = rs.ParentLayer(cl)
            # switch back to GhDoc
            sc.doc = ghdoc
            if parent:
                allvalid = [parent + "::" + l for l in refLayers]
                # set message and return all valid children
                self.Message = "Referenced: " + str(parent)
                st[self.LNKEY] = allvalid
                return allvalid
            else:
                st[self.LNKEY] = None
                self.Message = None
                return None

        # if no children, layer has to be parent layer
        elif childcount > 0:
            parent = cl
            # switch back to GhDoc and return all valid layers
            scdoc = ghdoc
            if parent:
                allvalid = [parent + "::" + l for l in refLayers]
                # set message and return all valid children
                self.Message = "Referenced: " + str(parent)
                st[self.LNKEY] = allvalid
                return allvalid

        else:
            # switch back to GhDoc
            scdoc = ghdoc
            st[self.LNKEY] = None
            return None
コード例 #4
0
def mergeLayers(layA, layB):
    """
    layA is kept, layB is deleted
    input: (layA, layB) each is a layer, the top parent in a tree to merge with another.
    returns: None
    """
    rs.EnableRedraw(False)
    Alayers = rs.LayerChildren(layA)
    Blayers = rs.LayerChildren(layB)
    AlayersShort = []
    BlayersShort = []
    for Alayer in Alayers:
        AlayersShort.append(rs.LayerName(Alayer, False))
    for Blayer in Blayers:
        BlayersShort.append(rs.LayerName(Blayer, False))
    uniqueLayers = list(set(BlayersShort) - set(AlayersShort))
    #move unique layers
    for uniqueLayer in uniqueLayers:
        rs.ParentLayer(uniqueLayer, layA)

    #get duplicate name layers
    duppedLayers = list(set(BlayersShort) - set(uniqueLayers))

    #move objects to layA twin
    for duppedLayer in duppedLayers:
        newParent = layA + "::" + duppedLayer
        duppedObjs = rs.ObjectsByLayer(layB + "::" + duppedLayer)
        for duppedObj in duppedObjs:
            rs.ObjectLayer(duppedObj, newParent)
        #if it has children, recursively move them
        if rs.LayerChildCount(layB + "::" + duppedLayer) > 0:
            mergeLayers(layA + "::" + duppedLayer, layB + "::" + duppedLayer)
        else:
            rs.DeleteLayer(layB + "::" + duppedLayer)
            rs.DeleteLayer(layB)
    rs.EnableRedraw(True)
    return None
コード例 #5
0
    #
    # create Toolpaths parent layer if not present
    #
    if not rs.IsLayer("Toolpaths"):
        rs.AddLayer("Toolpaths")

    #
    # run form to collect data about the toolpath operation
    #
    objects, mode, totalDepth, passDepth, toolDiameter = getToolpathParameters(
    )

    #
    # add sublayer for the new toolpath
    #
    nrOfPaths = rs.LayerChildCount("Toolpaths")
    pathLayerName = "path%03d" % nrOfPaths
    rs.AddLayer(name="Toolpaths::" + pathLayerName, color=[255, 0, 0])
    rs.CurrentLayer(pathLayerName)

    #
    # generate the toolpath
    #
    rc = prepareToolpaths(pathLayerName, objects, mode, totalDepth, passDepth,
                          toolDiameter)

    #
    # remove toolpath layer if the operation failed
    #
    if rc == False:
        print "Removing layer"
コード例 #6
0
    newLayer = rs.AddLayer(name, color=rs.LayerColor(source), parent = destination)
    matchLayer(newLayer, source)
    return(newLayer)

def matchLayer(name, source):
    rs.LayerLinetype(name, linetype = rs.LayerLinetype(source))
    rs.LayerPrintColor(name, color = rs.LayerPrintColor(source))
    rs.LayerPrintWidth(name, width = rs.LayerPrintWidth(source))


sourceObjects = rs.GetObjects(message="Select Object to Move", preselect=True, select=False)

allLayers = rs.LayerNames()
topList = []
for layer in allLayers:
    if rs.LayerChildCount(layer) > 0:
        topList.append(layer)

destinationLayer = rs.ListBox(topList)

rs.EnableRedraw(enable=False)

for obj in sourceObjects:
    objLayer = rs.ObjectLayer(obj)
    parent, child = objLayer.split("::")
    fullDLayer = destinationLayer + "::" + child
    if not rs.IsLayer(fullDLayer):
        fullDLayer = duplicateLayer(child, objLayer, destinationLayer)    
    if copy[0] == True:
        copyObj = rs.CopyObject(obj, translation=None)
        rs.ObjectLayer(copyObj, layer=fullDLayer)