Exemplo n.º 1
0
def get_block_descriptions(blocknames):
    descriptions = []
    for blockname in blocknames:
        description = rs.BlockDescription(blockname)
        if description is None:
            description = ""
        descriptions.append(description)
    return descriptions
Exemplo n.º 2
0
def main():
    """
    Creates a part list for all blocks in a document. Numbers will correspond with 
    balloons, but balloons don't need to be present for the table to be generated
    
    version 1.3
    www.studiogijs.nl
    
    version 1.1 adds table heading
    version 1.2 option for choosing between all or only top level blocks
    version 1.3 adds block description. Use change_block_description.py
    or change in block manager
   
    """
    t = sc.sticky['top_level_only'] if sc.sticky.has_key(
        'top_level_only') else 0  #0 = top level only, 1= all blocks
    if t == None:
        t = 0
    top_level_only = rs.GetBoolean("annotate top level blocks only?",
                                   ["top_level_only", "yes", "no"], t)
    if not top_level_only:
        return
    sc.sticky['top_level_only'] = top_level_only[0]

    previous_layer = rs.CurrentLayer()
    #check if layer 'annotation' exist, else create it
    if not rs.IsLayer("annotation"): rs.AddLayer("annotation")
    rs.LayerColor("annotation", Col.Black)

    rs.CurrentLayer("annotation")

    groups = sc.doc.ActiveDoc.Groups
    partlist = []

    blocknames = get_block_names()
    if not blocknames:
        print "This file does not contain block items (titleblock will be ignored)"
        return
    #add headings
    texts = ["ITEM", "PART NAME", "DESCR", "QTY"]
    partlist.append(texts)
    texts = []
    for block_nr, blockname in enumerate(blocknames, 1):
        texts.append(str(block_nr))
        texts.append(blockname)
        description = rs.BlockDescription(blockname)
        if description is None:
            description = ""
        texts.append(description)
        blockcount = get_block_count(blockname)
        texts.append(str(blockcount))
        partlist.append(texts)
        texts = []
    create_table(partlist)
    #change back to previous layer
    rs.CurrentLayer(previous_layer)
Exemplo n.º 3
0
def change_block_description():
    """
    change or set a block description
    
    version 1.0
    www.studiogijs.nl
    """

    block = rs.GetObject("select block to add or change description",
                         filter=4096,
                         preselect=True)
    if not block:
        return
    block = rs.coercerhinoobject(block).InstanceDefinition

    desc = rs.BlockDescription(block.Name)
    if desc == None:
        print "Current description not set"
    else:
        print "Current description: " + desc
    newdesc = rs.GetString(
        "Set new description, to use spaces enter description between \" \"")
    if newdesc:
        rs.BlockDescription(block.Name, newdesc)
Exemplo n.º 4
0
def main():
    objs = rs.GetObjects("select block", 0, True, True)
    print len(objs)

    for obj in objs:
        if rs.ObjectType(obj) == 4096:
            name = rs.BlockInstanceName(obj)
            print rs.BlockDescription(name)
            children = rs.ExplodeBlockInstance(obj)
            text = rs.AddText(name, [0, 0, 0],
                              height=1.0,
                              font="Arial",
                              font_style=0,
                              justification=None)

            print type(children)

            children.Append(text)
            print children[0]
Exemplo n.º 5
0
def TreeMassing():
    try:

        litre = rs.GetReal("Enter the root ball litres, max 2000 Litres", 400)
        soilDepth = rs.GetReal('Enter the soil depth available in m', 0.8)
        matureHeight = rs.GetReal('Enter the mature tree height in m', 5)
        dbh = rs.GetReal(
            'Enter the DBH at maturity in m, if unknown hit Enter', 0)
        userPt = rs.GetPoint('Pick a point to place rootball')

        rs.EnableRedraw(False)

        # Dictionery for litre size to pot Rootball Diameter [0] / Rootball Height [1] / Calliper [2] / Height [3] / Spread [4]
        # Figures obtained from https://winterhill.com.au/tree-sizes/
        PotDict = {
            25: [0.300, 0.250, 0.020, 1.000, 0.500],
            45: [0.420, 0.350, 0.025, 2.000, 1.000],
            75: [0.465, 0.500, 0.035, 2.500, 2.000],
            100: [0.520, 0.560, 0.050, 3.500, 2.000],
            200: [0.700, 0.625, 0.070, 4.500, 3.000],
            400: [0.980, 0.715, 0.090, 6.000, 4.000],
            600: [1.200, 0.600, 0.100, 6.000, 5.000],
            800: [1.300, 0.600, 0.120, 7.000, 5.000],
            1000: [1.500, 0.600, 0.150, 8.000, 5.000],
            2000: [2.000, 0.800, 0.200, 9.000, 5.000],
        }

        def closest(lst, K):

            return lst[min(range(len(lst)), key=lambda i: abs(lst[i]-K))]

        def scale():
            system = rs.UnitSystem()
            if system == 2 or system == 3 or system == 4:
                scaleFactorDict = {2: 1000, 3: 100, 4: 1}
                scaleFactor = scaleFactorDict[system]
                return scaleFactor

            if system != 2 or system != 3 or system != 4:
                return None

        s = scale()

        if s == None:
            rs.MessageBox(
                "This tool is can only be used in mm, cm or m model units")
            return None

        # Calc for standard soil requirements as per Australian Standards

        if dbh == 0:
            dbh = ((matureHeight / 100) * 4) * 1000  # Gives a DBH in mm
        # Gives a required soil volume in M3
        reqSoil = (matureHeight * dbh) / 100
        reqSoilRadius = math.sqrt(reqSoil / ((math.pi)*soilDepth))

        # Add soil puck to doc
        reqSoilRadiusCyl = rs.AddCylinder(
            userPt, (soilDepth*s), (reqSoilRadius*s), cap=True)
        rs.ObjectColor(reqSoilRadiusCyl, (150, 75, 0))

        # Calc for size of rootball as per standard pot sizes
        litreMatch = closest(list(PotDict.keys()), litre)
        dia = (PotDict[litreMatch])[0]
        height = (PotDict[litreMatch])[1]

        # Add Rootball to doc
        rootballCyl = rs.AddCylinder(userPt, (height*s), ((dia/2)*s))
        rs.ObjectColor(rootballCyl, (0, 128, 0))
        vec = (0, 0, ((soilDepth*s) - (height*s)))
        rs.MoveObject(rootballCyl, vec)

        # Add Tree model based on Dict
        calliper = (PotDict[litreMatch])[2]
        treeHeight = (PotDict[litreMatch])[3]
        spread = (PotDict[litreMatch])[4]
        vec02 = (0, 0, (((soilDepth*s) - (height*s))) + (height*s))

        treeTrunk = rs.AddCylinder(userPt, (treeHeight*s), (calliper*s))
        rs.ObjectColor(treeTrunk, (101, 67, 33))
        rs.MoveObject(treeTrunk, vec02)
        canopy = rs.AddSphere(userPt, ((spread/2)*s))
        rs.ObjectColor(canopy, (33, 101, 67))
        vec03 = (0, 0, (((soilDepth*s) - (height*s))) +
                 (height*s) + (treeHeight*s) - ((spread/2)*s))
        rs.MoveObject(canopy, vec03)

        # Various Text Annotation
        txt1 = rs.AddText('Rootball ' + 'Height = ' + str(height*s) + ', Diameter = ' + str(dia*s), userPt,
                          height=(.1*s), font="Arial", font_style=0, justification=2)

        txt2 = rs.AddText('Soil Volume Requirement = ' + str(reqSoil) + ' m3', (userPt.X, (userPt.Y - (.2*s)), userPt.Z),
                          height=(.1*s), font="Arial", font_style=0, justification=2)

        block = rs.AddBlock((reqSoilRadiusCyl, rootballCyl, treeTrunk, canopy, txt1, txt2), userPt,
                            ("Rootball and Soil " + (str(random.random()))), delete_input=True)
        rs.BlockDescription(block, 'Rootball ' + 'Height = ' + str(height*s) + ', Diameter = ' + str(dia*s)
                            + ', Soil Volume Requirement = ' + str(reqSoil) + ' m3')

        guid = rs.InsertBlock(block, userPt)
        rs.ObjectName(guid, 'Rootball ' + 'Height = ' + str(height*s) + ', Diameter = ' + str(dia*s)
                            + ', Soil Volume Requirement = ' + str(reqSoil) + ' m3')

        rs.EnableRedraw(True)

    except:
        print("Failed to execute")
        rs.EnableRedraw(True)
        return