Ejemplo n.º 1
0
 def initExportByLayer(self,
                       fileType="obj",
                       visibleonly=False,
                       byObject=False):
     for layerName in self.arrLayers:
         layer = scriptcontext.doc.Layers.FindByFullPath(layerName, True)
         if layer >= 0:
             layer = scriptcontext.doc.Layers[layer]
             save = True
             if visibleonly:
                 if not layer.IsVisible:
                     save = False
             if rs.IsLayerEmpty(layerName):
                 save = False
             if save:
                 cutName = layerName.split("::")
                 cutName = cutName[len(cutName) - 1]
                 objs = scriptcontext.doc.Objects.FindByLayer(cutName)
                 if len(objs) > 0:
                     if byObject:
                         i = 0
                         for obj in objs:
                             i += 1
                             self.saveObjectsToFile(cutName + "_" + str(i),
                                                    [obj], fileType)
                     else:
                         self.saveObjectsToFile(cutName, objs, fileType)
def get_layer_info(root_layer_name):
    lay_root = sc.doc.Layers.FindName(root_layer_name, 0)
    if lay_root is None: return False
    ret = {"parent": lay_root, "children": []}
    if lay_root.GetChildren() is not None:
        for lay_child in lay_root.GetChildren():
            if not rs.IsLayerEmpty(lay_child.Id):
                ret["children"].append(lay_child)

    return ret
Ejemplo n.º 3
0
def importCAD(filePath, scaleDWG = False):
    explodeBlockBoo = True

    #setup the layers
    importLayerNumber = 6000
    importLayerObj = layers.AddLayerByNumber(importLayerNumber, False)
    importLayerName = layers.GetLayerNameByNumber(importLayerNumber)

    #Shorten cad file name
    fileNameExt = os.path.basename(filePath)
    fileName = os.path.splitext(fileNameExt)[0]

    #create layer name
    time = utils.GetDatePrefix()
    iter = "01"
    layerName = time+"_"+fileName+"_"+iter

    #Check if this layer already exists
    while rs.IsLayer(importLayerName + "::" + time + "_" + fileName + "_" + iter):
        iterInt = int(iter)+1
        if len(str(iterInt))<2:
            iter = "0" + str(iterInt)
        else:
            iter = str(iterInt)

    elementLayerName = importLayerName + "::" + time + "_" + fileName + "_" + iter
    elementLayer = rs.AddLayer(elementLayerName)

    rs.CurrentLayer(elementLayer)

    #get intial list of all layers in the file
    currentLayers = rs.LayerNames()

    rs.Command('_-Import "' + filePath + '" _IgnoreThickness=Yes _ModelUnits=Inches _Enter', False)

    #get new layers added
    endLayersNames = rs.LayerNames()
    newLayers = diff(endLayersNames, currentLayers)

    for layer in newLayers:
        rs.ParentLayer(layer, elementLayer)
        objects = rs.ObjectsByLayer(layer)
        if rs.IsLayerEmpty(layer):
            rs.DeleteLayer(layer)
        else:
            for obj in objects:
                if rs.IsDimension(obj):
                    rs.DeleteObject(obj)
                elif rs.IsHatch(obj):
                    rs.DeleteObject(obj)

    #Get all the imported geometry
    allObjects = []
    finalLayers = rs.LayerChildren(rs.CurrentLayer())
    blockNames = []
    for finalLayer in finalLayers:
        layerObjects = rs.ObjectsByLayer(finalLayer)
        for layerObject in layerObjects:
            if rs.IsBlockInstance(layerObject):
                blockNames.append(rs.BlockInstanceName(layerObject))
                allObjects.append(rs.ExplodeBlockInstance(layerObject, True))
            else:
                allObjects.append(layerObject)
    finalAllObjects = list(flatten(allObjects))

    for eachBlock in blockNames:
        try:
            rs.DeleteBlock(eachBlock)
        except:
            pass

    #Scale objects
    if scaleDWG:
        rs.ScaleObjects(finalAllObjects, [0,0,0], [.001, .001, .001])

    #Collapse layers
    try:
        rootLay = sc.doc.Layers.FindId(rs.coerceguid(rs.LayerId(elementLayerName)))
        rootLay.IsExpanded = False
    except:
        pass
    print "Import Successful"
    return finalAllObjects
Ejemplo n.º 4
0
# Origin https://discourse.mcneel.com/t/the-best-way-to-identify-layers-without-objects-to-delete/7690/4

import rhinoscriptsyntax as rs
layers = rs.LayerNames()
for layer in layers:
    if rs.IsLayerEmpty(layer): rs.DeleteLayer(layer)
Ejemplo n.º 5
0
Archivo: test.py Proyecto: tmshv/sisu
def test_is_layer_not_empty(options):
    layer_name = options['layer']
    # log('Test: layer {} should not be empty'.format(layer_name))

    return rs.IsLayer(layer_name) and not rs.IsLayerEmpty(layer_name)
Ejemplo n.º 6
0
import rhinoscriptsyntax as rs
#delete empty layers(simple clean up code)

count = rs.LayerCount()
layerNames = rs.LayerNames()
for i in range(count):
    if rs.IsLayerEmpty(layerNames[i]):
        rs.PurgeLayer(layerNames[i])
    else:
        print "The layer" + layerNames[i] + "is not empty."
Ejemplo n.º 7
0
Archivo: test.py Proyecto: tmshv/sisu
def test_is_layer_not_empty(options):
    layer_name = options['layer']

    s = rs.IsLayer(layer_name) and not rs.IsLayerEmpty(layer_name)
    return s, None
Ejemplo n.º 8
0
def importTEN_CAD():
    savePath0 = rs.OpenFileName("Open", "Autocad (*.dwg)|*.dwg||")
    items = [["Units", "Meters", "Millimeters"]]
    defaults = [False]
    CADinMilli = rs.GetBoolean("Is that CAD file in meters or mm?", items,
                               defaults)[0]

    explodeBlockBoo = True

    if savePath0 is None:
        return
    rs.EnableRedraw(False)

    #setup the layers
    rs.AddLayer("7_REF")
    rs.AddLayer("CAD", parent="7_REF")

    fileNameExt = savePath0.split('\\')[-1]
    fileName = fileNameExt.split('.')[0]
    savePath1 = '"' + savePath0 + '"'

    #create layer name
    now = datetime.date.today()
    dateList = []
    if len(str(now.month)) > 1:
        month = str(now.month)
    else:
        month = "0" + str(now.month)
    if len(str(now.day)) > 1:
        day = str(now.day)
    else:
        day = "0" + str(now.day)
    time = str(now.year) + month + day
    layerName = time + "_" + fileName + "_01"
    children = rs.LayerChildren("7_REF::CAD")
    finalNums = []
    for child in children:
        num = rs.LayerName(child, fullpath=False).split("_")[-1]
        try:
            finalNums.append(int(num))
        except:
            finalNums.append(0)
    finalNums.sort()
    if rs.IsLayer("7_REF::CAD::" + layerName):
        num = int(finalNums[-1]) + 1
        if len(str(num)) < 2:
            finalNum = "0" + str(num)
        else:
            finalNum = str(num)
        layerName = time + "_" + fileName + "_" + finalNum
    par = rs.AddLayer("7_REF")
    cat = rs.AddLayer("CAD", parent=par)
    element = rs.AddLayer(layerName, parent=cat)
    rs.CurrentLayer(element)

    #get intial list of all layers in the file
    currentLayers = rs.LayerNames()

    rs.Command('_-Import ' + savePath1 + ' _Enter')

    #get new layers added
    endLayersNames = rs.LayerNames()
    #newLayers = [item for item in currentLayers if item not in endLayersNames]
    newLayers = diff(endLayersNames, currentLayers)
    print newLayers

    for layer in newLayers:
        rs.ParentLayer(layer, element)
        objects = rs.ObjectsByLayer(layer)
        if rs.IsLayerEmpty(layer):
            rs.DeleteLayer(layer)
        else:
            for obj in objects:
                if rs.IsDimension(obj):
                    rs.DeleteObject(obj)
                elif rs.IsHatch(obj):
                    rs.DeleteObject(obj)

    #Get all the imported geometry
    allObjects = []
    finalLayers = rs.LayerChildren(rs.CurrentLayer())
    for finalLayer in finalLayers:
        allObjects.append(rs.ObjectsByLayer(finalLayer))
    finalAllObjects = [item for sublist in allObjects for item in sublist]

    #Format Coordinate
    try:
        rawCoordinate = rs.GetDocumentData("Project Info",
                                           "CAD coordinate (X,Y,Z)")
    except:
        print "No CAD Coordinate specified in the Project Info"
        rawCoordinate = (0, 0, 0)
    coordinate = rawCoordinate.split(",")
    print "Aa"

    try:
        for i in range(0, 3):
            coordinate[i] = float(coordinate[i])
    except:
        coordinate = None
    if coordinate is None:
        print "CAD coordinate has an error"

    else:  #move all objects
        negVec = rs.VectorReverse(coordinate)
        rs.MoveObjects(finalAllObjects, negVec)

    if CADinMilli:
        rs.ScaleObjects(finalAllObjects, [0, 0, 0], [.001, .001, .001])

    importGroup = rs.AddGroup(str(layerName))

    rs.AddObjectsToGroup(finalAllObjects, importGroup)

    rs.ZoomSelected()
    print "Import EXECUTED"
    rs.EnableRedraw(True)
    return None
Ejemplo n.º 9
0
"""
SHL Architects 30-01-2019
Sean Lamb (Developer)
[email protected]
-better handling of different brep types
"""

import rhinoscriptsyntax as rs
layers = rs.LayerNames()
num_layers = 0
for layer in layers:
    if rs.IsLayerEmpty(layer):
        if rs.IsLayerCurrent(layer):
            print "Current layer is empty but will not be removed."
        else:
            rs.DeleteLayer(layer)
            num_layers += 1
print "%d empty layers removed." % num_layers
Ejemplo n.º 10
0
    s = 5
    for sid in ids:

        setView(sid)
        # unhide all and delete all
        [rs.LayerVisible(n, True) for n in layers]
        FileTools.deleteAll()
        # get all the geometry
        for layer in layers:
            # make the layer
            att = LayerTools.layerAttributes(layer)
            path = '/amigos/db/%s%s' % (sid, layer)
            # get the geometry
            bakePickle(path, layer, att)

            if not rs.IsLayerEmpty(layer) and len(layers[layer]) > 1:
                # set the material
                material = None
                material = layers[layer][1]
                matindex = __getMaterial(material)
                uv = materials[material]
                cmds = materialConfig(layer, material, uv)
                cmds = [formatCmd(c) for c in cmds]
                rcmds(cmds, False)

        # run through render frames
        for frame in range(6):

            # get the name of the frame/scene
            scene = scenes[frame]