Exemplo n.º 1
0
def pre_process():
    # delete all previous user text
    all_objs = rs.AllObjects()
    for obj in all_objs:
        rh_obj = rs.coercerhinoobject(obj)
        rh_obj.Attributes.DeleteAllUserStrings()

    # remove all blocks
    for block in rs.BlockNames():
        rs.DeleteBlock(block)

    # set current layer
    rs.CurrentLayer(relevant_layers_dict["buildings"])

    # remove redundant layers
    for layer_name in rs.LayerNames():
        if layer_name not in relevant_layers_dict.values():
            rs.PurgeLayer(layer_name)

    # get all objects in building layer
    building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"])

    for building_obj in building_objs:
        if rs.IsCurve(building_obj) and rs.IsCurveClosed(building_obj):

            # flatten curve to XY plane
            matrix = rs.XformPlanarProjection(rg.Plane.WorldXY)
            rs.TransformObject(building_obj, matrix, copy=False)

            # delete all object with a surface grater or smaller from MIN_BUILDING_AREA_SQ by TOLERANCE or just smaller than MIN_BUILDING_AREA_SQ
            TOLERANCE = 2
            if rs.CurveArea(building_obj)[0] < MIN_BUILDING_AREA_SQM or abs(
                    rs.CurveArea(building_obj)[0] -
                    MIN_BUILDING_AREA_SQM) < TOLERANCE:
                rs.DeleteObject(building_obj)
def Delete():
    blockName = rs.GetString("block to delete")
    instanceDefinition = doc.InstanceDefinitions.Find(blockName, True)
    if not instanceDefinition:
        print "{0} block does not exist".format(blockName)
        return

    rs.DeleteBlock(blockName)
Exemplo n.º 3
0
proc_composite_path = "inputs\\proc_composite.csv"
proc_polylines_path = "inputs\\proc_polylines.csv"
proc_attributes_path = "inputs\\proc_attributes.csv"

relevant_layers_dict = {"buildings": "2200", "plots": "chelkot lines"}
MIN_BUILDING_AREA_SQM = 50
FLOOR_HEIGHT_M = 3

##########################################################################################################################################

# set scriptcontext.doc to Rhino.ActiveDoc
sc.doc = rh.RhinoDoc.ActiveDoc

# remove all blocks
for block in rs.BlockNames():
    rs.DeleteBlock(block)

# set current layer
rs.CurrentLayer(relevant_layers_dict["buildings"])

# remove redundant layers
for layer_name in rs.LayerNames():
    if layer_name not in relevant_layers_dict.values():
        rs.PurgeLayer(layer_name)

# get all objects in building layer
building_objs = rs.ObjectsByLayer(relevant_layers_dict["buildings"])

for building_obj in building_objs:
    if rs.IsCurve(building_obj) and rs.IsCurveClosed(building_obj):
        # flatten curve to XY plane
Exemplo n.º 4
0
 def _clear_blocks(cls):
     block_names = rs.BlockNames()
     for name in block_names:
         rs.DeleteBlock(name)
Exemplo n.º 5
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
def clear_blocks():
    rs.DeleteBlock('shape frame')