示例#1
0
文件: rh_trial.py 项目: tanyaroi/PyGH
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)
示例#2
0
def GetCustomBlockNames():
    block = rs.BlockNames(True)
    if len(block) < 1:
        print "There are no blocks in the file"
        return None
    objs = rs.GetObjects('Select block(s) to populate', rs.filter.instance,
                         True)
    if objs is None: return None, None
    blockNames = []
    for obj in objs:
        blockNames.append(rs.BlockInstanceName(obj))
    return blockNames, objs
def main():

    for name in rs.BlockNames():
        block = rs.InsertBlock(name, (0,0,0))
        
        rs.UnselectAllObjects()
        
        # explodblock
        uids = rs.ExplodeBlockInstance(block)
        
        rs.SelectObjects(uids)

        rs.Command('! _-Export _Pause "E:\\TNM\\template\\tools\\' + name + '.3dm" _Enter')
def InstanceDefinitionObjects():

    names = rs.BlockNames(True)
    if names:
        for block_name in names:

            instanceDefinition = doc.InstanceDefinitions.Find(block_name, True)
            if not instanceDefinition:
                print "{0} block does not exist".format(block_name)
                return
            else:
                # set the layer status
                instanceDefinition.LayerStyle = 1
                print instanceDefinition.LayerStyle
示例#5
0
def main():

    for name in rs.BlockNames():
        block = rs.InsertBlock(name, (0, 0, 0))

        rs.UnselectAllObjects()

        # explodblock
        uids = rs.ExplodeBlockInstance(block)

        rs.SelectObjects(uids)

        rs.Command(
            "_-Insert File=Yes LinkMode=Link E:\\TNM\\template\\tools\\" +
            name + ".3dm Block 0,0,0 1.0 0.0")
示例#6
0
def assignBlockToPanel(obj):
    """
    Assigns block containing a base surface to a surface with the matching name.
    Block, base surface, and target surface must all have the same name.
    
    input: target surface (with name)
    returns: None
    """
    allBlockNames = rs.BlockNames()
    for eachBlockName in allBlockNames:
        if rs.ObjectName(obj) == eachBlockName:
            blockName = eachBlockName
            print "Matching Block Found"

            objBasePt = rs.SurfaceEditPoints(obj)[0]
            objYPt = rs.SurfaceEditPoints(obj)[1]
            objXPt = rs.SurfaceEditPoints(obj)[2]
            objXVec = rs.VectorCreate(objXPt, objBasePt)
            objXLength = rs.VectorLength(objXVec)
            objYLength = rs.Distance(objBasePt, objYPt)

            blockObjs = rs.BlockObjects(blockName)
            for blockObj in blockObjs:
                if rs.ObjectName(blockObj) == blockName:
                    print "Contains base plane"
                    if rs.IsSurface(blockObj):
                        blockBasePt = rs.SurfaceEditPoints(blockObj)[0]
                        blockYPt = rs.SurfaceEditPoints(blockObj)[1]
                        blockXPt = rs.SurfaceEditPoints(blockObj)[2]
                        blockXVec = rs.VectorCreate(blockXPt, blockBasePt)
                        rotAngle = rs.VectorAngle(objXVec, blockXVec)
                        blockXLength = rs.VectorLength(blockXVec)
                        blockYLength = rs.VectorLength(
                            rs.VectorCreate(blockYPt, blockBasePt))
                        xScale = objXLength / blockXLength
                        yScale = objYLength / blockYLength
                        newScale = [yScale, xScale, 1]
                        rs.InsertBlock(blockName,
                                       objBasePt,
                                       scale=newScale,
                                       angle_degrees=rotAngle)
                        break
                    else:
                        print "Error: Base plane was not a surface"
示例#7
0
def ExportAndLinkBlock():
    try:
        name = rs.ListBox(rs.BlockNames(True),
                          'Select Block to Export and Link', 'Export and Link')
        if name is None: return

        path = rs.SaveFileName('Export and Link',
                               "Rhino 6 3D Models|.3dm||",
                               filename=name)
        if path is None: return

        try:
            rs.Command(
                "_-BlockManager e " + '"' + name + '" ' + path + ' Enter',
                False)
            rs.Command(
                "_-BlockManager _Properties " + '"' + name + '"' +
                " _UpdateType i " + path +
                " _UpdateType _Linked _Enter _Enter", False)
        except:
            pass
        return True
    except:
        return False
示例#8
0
composite_path = "inputs\\composite.csv"
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):
def RunCommand(is_interactive):
    if sc.escape_test(False):
        print "script cancelled"  #do something

    print "Making unique..."

    #******* Get blocks *****************
    #************************************

    objectIds = rs.GetObjects("Pick some blocks", 4096, preselect=True)
    if not objectIds:
        print "No objects"
        return False

    #pause viewport redraw
    rs.EnableRedraw(False)

    #******* Sort blocks by type ********
    #************************************
    blockTypes = {}
    for id in objectIds:
        blockName = rs.BlockInstanceName(id)
        if blockName not in blockTypes:
            blockTypes[blockName] = []
        blockTypes[blockName].append(id)

    #***** Define new block and add *****
    #************************************

    #Get block names
    blockNames = rs.BlockNames()

    #gather all new objects when done
    finalObjs = []

    for blockType in blockTypes:
        for id in blockTypes[blockType]:
            #Get the block transformation matrix and name
            blockXForm = rs.BlockInstanceXform(id)
            blockName = rs.BlockInstanceName(id)

            #Insert new block in 0,0,0
            newBlock = rs.InsertBlock(blockName, [0, 0, 0])

            #Explode the block
            exObjs = rs.ExplodeBlockInstance(newBlock)

            #create new block name

            # if the string ends in digits m will be a Match object, or None otherwise.
            strippedName = re.sub(r'#[0-9]+$', '', blockName)

            #test if block name exist and add to the end number if true.
            x = 0
            tryAgain = True
            while tryAgain:
                x += 1
                newerBlockName = strippedName + "#" + str(x)
                if newerBlockName not in blockNames:
                    tryAgain = False
                    break

            #insert exObjs as new block
            rs.AddBlock(exObjs, [0, 0, 0], newerBlockName, delete_input=True)
            newerBlock = rs.InsertBlock(newerBlockName, [0, 0, 0])

            #match properties from original
            rs.MatchObjectAttributes(newerBlock, id)

            #transform new block
            rs.TransformObject(newerBlock, blockXForm)

            #append for final selection
            finalObjs.append(newerBlock)

        #add name to list of used blocknames.
        blockNames.append(newerBlockName)

    #Delete original block
    rs.DeleteObjects(objectIds)

    #Select all new objects
    rs.SelectObjects(finalObjs)

    rs.EnableRedraw(True)

    print "...aaand its done."
    #End RunCommand()

    #end sane
    return 0
示例#10
0
 def _clear_blocks(cls):
     block_names = rs.BlockNames()
     for name in block_names:
         rs.DeleteBlock(name)