Пример #1
0
    def addTBDataToDocumentUserText(self, _tbs, _psiInstalls):
        self._clearDocumentLibValues(['PHPP_lib_TB_', 'PHPP_lib_PsiInstall'])

        print('Writing New Library elements to the Document UserText....')
        # Write the new Assemblies to the Document's User-Text
        for i, eachTB in enumerate(_tbs):
            if eachTB[0] != None and len(
                    eachTB[0]) > 0:  # Filter our Null values
                newTB = {
                    "Name": eachTB[0],
                    "psiValue": eachTB[1],
                    "fRsi": eachTB[2],
                    "ID": int(i + 1)
                }
                rs.SetDocumentUserText("PHPP_lib_TB_{:02d}".format(i + 1),
                                       json.dumps(newTB))

        for i, eachPsiInst in enumerate(_psiInstalls):
            if eachPsiInst[0] != None and len(
                    eachPsiInst[0]) > 0:  # Filter our Null values
                newTB = {
                    "Name": eachPsiInst[0],
                    "Left": eachPsiInst[1],
                    "Right": eachPsiInst[2],
                    "Bottom": eachPsiInst[3],
                    "Top": eachPsiInst[4],
                    "ID": int(i + 1)
                }
                rs.SetDocumentUserText(
                    "PHPP_lib_PsiInstall_{:02d}".format(i + 1),
                    json.dumps(newTB))
 def test_GetDocumentUserTextWithNoArgsIgnoresDocumentData(self):
     s,k,v = sec_ent_val()
     rs.SetDocumentData(s,k,v)
     rs.SetDocumentUserText(k,v)
     _,k,v = sec_ent_val()
     rs.SetDocumentUserText(k,v)
     self.assertTrue(not any("\\" in k for k in rs.GetDocumentUserText()))
     self.assertEqual(2, rs.GetDocumentUserText().Count)
 def test_DocumentUserTextCountIgnoresDocumentData(self):
   s,e,v = sec_ent_val()
   rs.SetDocumentData(s,e,v)
   self.assertEqual(0, rs.DocumentUserTextCount())
   _,k,v = sec_ent_val()
   rs.SetDocumentUserText(k,v)
   _,k,v = sec_ent_val()
   rs.SetDocumentUserText(k,v)
   self.assertEqual(2, rs.DocumentUserTextCount())
Пример #4
0
    def addCompoDataToDocumentUserText(self, _glzgs, _frms, _assmbls):
        self._clearDocumentLibValues(
            ['PHPP_lib_Glazing', 'PHPP_lib_Frame', 'PHPP_lib_Assmbly'])

        print('Writing New Library elements to the Document UserText....')
        # Write the new Assemblies to the Document's User-Text
        for i, eachAssembly in enumerate(_assmbls):
            if eachAssembly[0] != None and len(
                    eachAssembly[0]) > 0:  # Filter our Null values
                newAssembly = {
                    "Name": eachAssembly[0],
                    "Thickness": eachAssembly[1],
                    "uValue": eachAssembly[2],
                    "intInsulation": eachAssembly[3],
                    "ID": int(i + 1)
                }
                rs.SetDocumentUserText("PHPP_lib_Assmbly_{:02d}".format(i + 1),
                                       json.dumps(newAssembly))

        # Write the new Glazings to the Document's User-Text
        for i, eachGlazing in enumerate(_glzgs):
            newGlazingType = {
                "Name": eachGlazing[0],
                "gValue": eachGlazing[1],
                "uValue": eachGlazing[2],
                "ID": int(i + 1)
            }
            rs.SetDocumentUserText("PHPP_lib_Glazing_{:02d}".format(i + 1),
                                   json.dumps(newGlazingType))

        # Write the new Frames to the Document's User-Text
        for i, eachFrame in enumerate(_frms):
            newFrameType = {
                "Name": eachFrame[0],
                "uFrame_L": eachFrame[1],
                "uFrame_R": eachFrame[2],
                "uFrame_B": eachFrame[3],
                "uFrame_T": eachFrame[4],
                "wFrame_L": eachFrame[5],
                "wFrame_R": eachFrame[6],
                "wFrame_B": eachFrame[7],
                "wFrame_T": eachFrame[8],
                "psiG_L": eachFrame[9],
                "psiG_R": eachFrame[10],
                "psiG_B": eachFrame[11],
                "psiG_T": eachFrame[12],
                "psiInst_L": eachFrame[13],
                "psiInst_R": eachFrame[14],
                "psiInst_B": eachFrame[15],
                "psiInst_T": eachFrame[16],
                "chi": eachFrame[17],
                "ID": int(i + 1)
            }
            rs.SetDocumentUserText("PHPP_lib_Frame_{:02d}".format(i + 1),
                                   json.dumps(newFrameType))
Пример #5
0
def runTest():
    areas = (createCoverage(objs), createFloors(objs))
    sitearea = float(rs.GetDocumentUserText("site area"))
    legalscr = float(rs.GetDocumentUserText("legal scr"))
    legalfar = float(rs.GetDocumentUserText("legal far"))
    designGFA = areas[1]
    designFAR = designGFA / sitearea
    designCVA = areas[0]
    designSCR = designCVA / sitearea
    rs.SetDocumentUserText("design gfa", str(round(designGFA, 2)))
    rs.SetDocumentUserText("design far", str(round(designFAR, 2)))
    rs.SetDocumentUserText("design cva", str(round(designCVA, 2)))
    rs.SetDocumentUserText("design scr", str(round(designSCR, 2)))
 def setUp(self):
   rs.DeleteDocumentData()
   # there's no DeleteDocumentUserText()
   keys = rs.GetDocumentUserText()
   if keys:
     for k in keys:
       rs.SetDocumentUserText(k)
 def test_DeleteDocumentData_not_delete_DocumentUserText(self):
     s, e, v = sec_ent_val()
     rs.SetDocumentData(s, e, v)
     _, k, v = sec_ent_val()
     rs.SetDocumentUserText(k, v)
     rs.DeleteDocumentData()
     self.assertEqual(v, rs.GetDocumentUserText(k))
Пример #8
0
def link_sisufile(filepath):
    config = read_sisufile(filepath)
    if not config:
        return False

    rs.SetDocumentUserText(SISUFILE_KEY, filepath)
    return True
Пример #9
0
def process(objs, isUG, func):
    
    groups = trp.groupByElevation(objs, isUG)
    trp.setLevel(groups, isUG, func)
    levels = [trp.createObjDict(x[0][0]) for x in groups]
    sc.sticky["levels"] = json.dumps(levels)
    rs.SetDocumentUserText("levels", json.dumps(levels))
Пример #10
0
    def _clearDocumentLibValues(self, _keys):
        if not rs.IsDocumentUserText():
            return

        for eachKey in rs.GetDocumentUserText():
            for k in _keys:
                if k in eachKey:
                    rs.SetDocumentUserText(eachKey)  # no second val = delete
Пример #11
0
    def changePrecisionVal(self, sender, e):
        global DIM_PRECISION
        DIM_PRECISION = sender.SelectedIndex
        rs.SetDocumentUserText("easy_cut_precision", str(DIM_PRECISION))
        specification = self.spec.details
        for row in specification:
            for det in row:
                det.setDims()

        self.rebuild()
Пример #12
0
def set_document_user_text():
    document_set_is_successful = rs.SetDocumentUserText('key1', 'value1')
    if document_set_is_successful:
        print('Document set is successful')
    else:
        print("Couldn't set")
    value1 = rs.GetDocumentUserText('key1')
    if value1:
        print('Document get is successful')
        print('key1: %s' % (value1))
Пример #13
0
    def setDocumentLibValues(self, _data):
#out with the old
        keys = set()
        for v in _data.values():
            keys.add(v['LibType'])
        self._clearDocumentLibValues( list(keys))
#in with the new: Adding in values from the GridView Window
        for k, v in _data.items():
            idNum = self._idAsInt(v['Data']['ID'])
            key = "{}_{:02d}".format( v['Libtype'], idNum )
            rs.SetDocumentUserText(key, json.dumps(v['Data']))
Пример #14
0
def process(objs, grade, func):

    isUG = trp.boolToggle(grade)
    groups = trp.groupByElevation(objs, isUG)

    trp.setLevel(groups, isUG, func)
    """setting lvldbdict as ordered for some reason
    """
    levels = [trp.createObjDict(x[0][0]) for x in groups]

    lvlk = [x['level'] for x in levels]
    lvldict = dict(zip(lvlk, levels))
    lvlpt = [rs.CreatePoint((0, 0, float(x['elevation']))) for x in levels]
    lvlptdict = dict(zip(lvlk, lvlpt))
    # pts = [" ".join(map(str,[0,0,float(x['elevation'])]))]
    # lvlptdict
    sc.sticky['lvlptdict'] = lvlptdict
    sc.sticky["lvldict"] = lvldict
    sc.sticky["levels"] = json.dumps(levels)
    rs.SetDocumentUserText("lvldict", json.dumps(lvldict))
    rs.SetDocumentUserText("levels", json.dumps(levels))
Пример #15
0
    def setDocumentLibValues(self, _data):
        # First, clear out all the existing values in the dict
        keys = set()
        for v in _data.values():
            keys.add(v['LibType'])
        self._clearDocumentLibValues(list(keys))

        # Now add in all the values from the GridView Window
        for k, v in _data.items():
            idNum = self._idAsInt(v['Data']['ID'])
            key = "{}_{:02d}".format(v['LibType'], idNum)
            rs.SetDocumentUserText(key, json.dumps(v['Data']))
Пример #16
0
def SetNewLayerStateInLayouts_Init():
    # Get it from document user text
    new_layer_state = rs.GetDocumentUserText("SafeLayout_NewLayerState")
    if new_layer_state is None:
        new_layer_state = "off"
    else:
        new_layer_state = new_layer_state.lower()
        if not new_layer_state in ['on', 'off']:
            new_layer_state = 'off'

    sc.sticky["SafeLayout_NewLayerState"] = new_layer_state
    # Set it to document user text
    rs.SetDocumentUserText("SafeLayout_NewLayerState", new_layer_state)
Пример #17
0
def RunCommand(is_interactive):
    # First, get any existing library paths in the Document User Text
    libPath_compo = rs.GetDocumentUserText('PHPP_Component_Lib')
    libPath_tb = rs.GetDocumentUserText('PHPP_TB_Lib')
    libPath_psiInstalls = rs.GetDocumentUserText('PHPP_PsiInstalls_Lib')

    # Apply defaults if nothing already loaded into the file
    libPath_compo = libPath_compo if libPath_compo else 'Load Main Library File...'
    libPath_tb = libPath_tb if libPath_tb else 'Load TB Library File ...'
    libPath_psiInstalls = libPath_psiInstalls if libPath_psiInstalls else 'Load Window Psi-Installs Library File...'

    # Call the Dialog Window
    dialog = Dialog_Libaries(libPath_compo, libPath_tb, libPath_psiInstalls)
    rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

    # If 'OK' button, then update the DocumentUserText
    if dialog.Update:
        if dialog.LibPath_compo:
            rs.SetDocumentUserText('PHPP_Component_Lib', dialog.LibPath_compo)
            print 'Setting PHPP Component Library for the Rhino Document to: {}'.format(
                dialog.LibPath_compo)

        if dialog.LibPath_tb:
            rs.SetDocumentUserText('PHPP_TB_Lib', dialog.LibPath_tb)
            print 'Setting PHPP Thermal Bridge Library for the Rhino Document to: {}'.format(
                dialog.LibPath_tb)

        if dialog.LibPath_psiInstalls:
            rs.SetDocumentUserText('PHPP_PsiInstalls_Lib',
                                   dialog.LibPath_psiInstalls)
            print 'Setting Window Psi-Installs Library for the Rhino Document to: {}'.format(
                dialog.LibPath_psiInstalls)

    return 1


# temp for debuggin in editor
# RunCommand(True)
Пример #18
0
def sortByAxis(objs, fn=lambda x: x[1].X, r=False, key='level', start=1):
    kv = []
    kv2 = []
    pairs = map(objPtPair, objs)
    sortedpairs = sorted(pairs, key=fn, reverse=r)
    for idx, pairs in enumerate(sortedpairs, start=start):
        rs.SetUserText(pairs[0], key, str(idx))
        kv.append((str(idx), pairs[1]))
        kv2.append((str(idx), (pairs[1].X, pairs[1].Y, pairs[1].Z)))
    planptdict = dict(kv)
    planpts = dict(kv2)
    rs.SetDocumentUserText("planpts", json.dumps(planpts))
    sc.sticky['planpts'] = json.dumps(planpts)
    sc.sticky['planptdict'] = planptdict
Пример #19
0
    def setLibraryFileAddress(self):
        """ Opens a dialogue window so the use can select a file
        """
        fd = Rhino.UI.OpenFileDialog()
        fd.Filter = "Excel Files (*.xlsx;*.xls)|*.xlsx;*.xls"

        #-----------------------------------------------------------------------
        # Add a warning to the user before proceeding
        # https://developer.rhino3d.com/api/rhinoscript/user_interface_methods/messagebox.htm
        msg = "Loading component parameters from a file will overwright all "\
        "the Assembly, Glazing and Window-Frame values in the current Rhino "\
        "file's library. Be sure you want to do this before proceeding."
        proceed = rs.MessageBox(msg, 1 | 48, 'Warning:')
        if proceed == 2:
            return fd.FileName

        #-----------------------------------------------------------------------
        if fd.ShowDialog() != System.Windows.Forms.DialogResult.OK:
            print 'Load is Canceled...'
            return None
        else:
            rs.SetDocumentUserText('PHPP_Component_Lib', fd.FileName)
            return fd.FileName
Пример #20
0
    def refresh_DocumentUserText_psi(self):
        """Reads Psi-Install Excel and adds entries to the file's DocumentUserText
        
        Removes all existing Window Pis-Install values from the
        DocumentUserText dictionary. Reads in all the values from the designated 
        XLSX Libary file and puts into the DocumentUserText dictionary
        
        Will look in the self.LibPath_psiInstalls (path) Excel file for:
            Worksheet named 'Psi-Installs'
            Reads from Cells B3:F103 (5 columns):
                Col 1: Type Name (str)
                Col 2: Left Psi-Install (float)
                Col 3: Right Psi-Install (float)
                Col 4: Bottom Psi-Install (float)
                Col 5: Top Psi-Install (float)
        """

        t1 = datetime.today()
        succesReading = False

        #####################################################################################
        #################              EXCEL-READ PART                      #################
        #####################################################################################
        try:
            if self.LibPath_psiInstalls != None:
                # If a Library File is set in the file...
                if os.path.exists(self.LibPath_psiInstalls):
                    print 'Reading the Window Psi-Installs Library File....'
                    # Make a Temporary copy
                    saveDir = os.path.split(self.LibPath_psiInstalls)[0]
                    tempFile = '{}_tempPsiInst.xlsx'.format(
                        random.randint(0, 1000))
                    tempFilePath = os.path.join(saveDir, tempFile)
                    copyfile(
                        self.LibPath_psiInstalls,
                        tempFilePath)  # create a copy of the file to read from

                    # Open the Excel Instance and File
                    ex = Excel.ApplicationClass()
                    ex.Visible = False  # False means excel is hidden as it works
                    ex.DisplayAlerts = False
                    workbook = ex.Workbooks.Open(tempFilePath)

                    # Find the Windows Worksheet
                    worksheets = workbook.Worksheets
                    try:
                        ws_PsiInst = worksheets['Psi-Installs']
                    except:
                        try:
                            ws_PsiInst = worksheets['Psi-Install']
                        except:
                            print "Could not find any worksheet names 'Psi-Installs' in the taget file?"

                    # Read in the Thermal Bridges from an Excel Worksheet
                    # Come in as 2D Arrays..... grrr.....
                    xlArray_Psi = ws_PsiInst.Range['B3:F103'].Value2

                    workbook.Close()  # Close the worbook itself
                    ex.Quit()  # Close out the instance of Excel
                    os.remove(tempFilePath)  # Remove the temporary read-file

                    # Build the Thermal Bridge Library
                    lib_PsiInst = []
                    xlList_Psi = list(xlArray_Psi)
                    for i in range(0, len(xlList_Psi), 5):
                        if xlList_Psi[i] != None:
                            newPsiInstall = [
                                xlList_Psi[i], xlList_Psi[i + 1],
                                xlList_Psi[i + 2], xlList_Psi[i + 3],
                                xlList_Psi[i + 4]
                            ]
                            lib_PsiInst.append(newPsiInstall)

                succesReading = True
            else:
                print('No Library filepath set.')
                succesReading = False
        except:
            print('Woops... something went wrong reading from the Excel file?')
            succesReading = False
        print lib_PsiInst
        #####################################################################################
        #################          Write the Rhino Doc Library              #################
        #####################################################################################
        if succesReading == True:
            # If there are any existing 'Document User-Text' Psi-Install objects, remove them
            print('Clearing out the old values from the Document UserText....')
            if rs.IsDocumentUserText():
                try:
                    for eachKey in rs.GetDocumentUserText():
                        if 'PHPP_lib_PsiInstall_' in eachKey:
                            print 'Deleting: Key:', eachKey
                            rs.SetDocumentUserText(
                                eachKey
                            )  # If no values are passed, deletes the Key/Value
                except:
                    print 'Error reading the Library File for some reason.'

            print('Writing New Library elements to the Document UserText....')
            # Write the new Psi-Installs to the Document's User-Text
            if lib_PsiInst:
                for eachPsiInstall in lib_PsiInst:
                    if eachPsiInstall[0] != None and len(
                            eachPsiInstall[0]) > 0:  # Filter our Null values
                        newPsiInstall = {
                            "Typename": eachPsiInstall[0],
                            "Left": eachPsiInstall[1],
                            "Right": eachPsiInstall[2],
                            "Bottom": eachPsiInstall[3],
                            "Top": eachPsiInstall[4],
                        }
                        rs.SetDocumentUserText(
                            "PHPP_lib_PsiInstall_{}".format(
                                newPsiInstall["Typename"]),
                            json.dumps(newPsiInstall))
        else:
            print 'Did not modify the Rhino User-Text Attributes.'

        print 'This ran in:', datetime.today() - t1, 'seconds'

        return 1
Пример #21
0
    def refresh_DocumentUserText_TB(self):
        """ Removes all existing Thermal Bridge values from the 
        DocumentUserText dictionary. Reads in all the values from the designated 
        XLSX Libary file and puts into the DocumentUserText dictionary
        """
        t1 = datetime.today()
        succesReading = False

        #####################################################################################
        #################              EXCEL-READ PART                      #################
        #####################################################################################
        try:
            if self.LibPath_tb != None:
                # If a Library File is set in the file...
                if os.path.exists(self.LibPath_tb):
                    print 'Reading the Thermal Bridge Library File....'
                    # Make a Temporary copy
                    saveDir = os.path.split(self.LibPath_tb)[0]
                    tempFile = '{}_temp.xlsx'.format(random.randint(0, 1000))
                    tempFilePath = os.path.join(saveDir, tempFile)
                    copyfile(
                        self.LibPath_tb,
                        tempFilePath)  # create a copy of the file to read from

                    # Open the Excel Instance and File
                    ex = Excel.ApplicationClass()
                    ex.Visible = False  # False means excel is hidden as it works
                    ex.DisplayAlerts = False
                    workbook = ex.Workbooks.Open(tempFilePath)

                    # Find the Windows Worksheet
                    worksheets = workbook.Worksheets
                    try:
                        ws_TBs = worksheets['Thermal Bridges']
                    except:
                        print "Could not find any worksheet names 'Thermal Bridges' in the taget file?"

                    # Read in the Thermal Bridges from an Excel Worksheet
                    # Come in as 2D Arrays..... grrr.....
                    xlArray_TBs = ws_TBs.Range['A2:C100'].Value2

                    workbook.Close()  # Close the worbook itself
                    ex.Quit()  # Close out the instance of Excel
                    os.remove(tempFilePath)  # Remove the temporary read-file

                    # Build the Thermal Bridge Library
                    lib_TBs = []
                    xlList_TBs = list(xlArray_TBs)
                    for i in range(0, len(xlList_TBs), 3):
                        newAssembly = [
                            xlList_TBs[i],
                            xlList_TBs[i + 1],
                            xlList_TBs[i + 2],
                        ]
                        lib_TBs.append(newAssembly)

                succesReading = True
            else:
                print('No Library filepath set.')
                succesReading = False
        except:
            print('Woops... something went wrong reading from the Excel file?')
            succesReading = False

        #####################################################################################
        #################          Write the Rhino Doc Library              #################
        #####################################################################################
        if succesReading == True:
            # If there are any existing 'Document User-Text' Thermal Bridge objects, remove them
            print('Clearing out the old values from the Document UserText....')
            if rs.IsDocumentUserText():
                try:
                    for eachKey in rs.GetDocumentUserText():
                        if 'PHPP_lib_TB_' in eachKey:
                            print 'Deleting: Key:', eachKey
                            rs.SetDocumentUserText(
                                eachKey
                            )  # If no values are passed, deletes the Key/Value
                except:
                    print 'Error reading the Library File for some reason.'

            print('Writing New Library elements to the Document UserText....')
            # Write the new Assemblies to the Document's User-Text
            if lib_TBs:
                for eachAssembly in lib_TBs:
                    if eachAssembly[0] != None and len(
                            eachAssembly[0]) > 0:  # Filter our Null values
                        newAssembly = {
                            "Name": eachAssembly[0],
                            "Psi-Value": eachAssembly[1],
                            "fRsi": eachAssembly[2],
                        }
                        rs.SetDocumentUserText(
                            "PHPP_lib_TB_{}".format(newAssembly["Name"]),
                            json.dumps(newAssembly))
        else:
            print 'Did not modify the Rhino User-Text Attributes.'

        print 'This ran in:', datetime.today() - t1, 'seconds'

        return 1
Пример #22
0
    def refresh_DocumentUserText_compo(self):
        """ Removes all existing Frame, Glazing, and Assmbly values from the 
        DocumentUserText dictionary. Reads in all the values from the designated 
        XLSX Libary file and puts into the DocumentUserText dictionary
        """
        t1 = datetime.today()
        succesReading = False

        #####################################################################################
        #################              EXCEL-READ PART                      #################
        #####################################################################################
        try:
            if self.LibPath_compo != None:
                # If a Library File is set in the file...
                if os.path.exists(self.LibPath_compo):
                    print 'Reading the Main Component Library File....'
                    # Make a Temporary copy
                    saveDir = os.path.split(self.LibPath_compo)[0]
                    tempFile = '{}_temp.xlsx'.format(random.randint(0, 1000))
                    tempFilePath = os.path.join(saveDir, tempFile)
                    copyfile(
                        self.LibPath_compo,
                        tempFilePath)  # create a copy of the file to read from

                    # Open the Excel Instance and File
                    ex = Excel.ApplicationClass()
                    ex.Visible = False  # False means excel is hidden as it works
                    ex.DisplayAlerts = False
                    workbook = ex.Workbooks.Open(tempFilePath)

                    # Find the Windows Worksheet
                    worksheets = workbook.Worksheets
                    try:
                        wsComponents = worksheets['Components']
                    except:
                        print "Could not find the 'Components' Worksheet in the taget file?"

                    # Read in the Components from Excel Worksheet
                    # Come in as 2D Arrays..... grrr.....
                    xlArrayGlazing = wsComponents.Range['IE15:IG113'].Value2
                    xlArrayFrames = wsComponents.Range['IL15:JC113'].Value2
                    xlArrayAssemblies = wsComponents.Range['E15:H113'].Value2

                    workbook.Close()  # Close the worbook itself
                    ex.Quit()  # Close out the instance of Excel
                    os.remove(tempFilePath)  # Remove the temporary read-file

                    # Build the Glazing Library
                    lib_Glazing = []
                    xlListGlazing = list(xlArrayGlazing)
                    for i in range(0, len(xlListGlazing), 3):
                        if xlListGlazing[i] != None:
                            newGlazing = [
                                xlListGlazing[i], xlListGlazing[i + 1],
                                xlListGlazing[i + 2]
                            ]
                            lib_Glazing.append(newGlazing)

                    # Build the Frame Library
                    lib_Frames = []
                    xlListFrames = list(xlArrayFrames)
                    for i in range(0, len(xlListFrames), 18):
                        newFrame = []
                        if xlListFrames[i] != None:
                            for k in range(i, i + 18):
                                newFrame.append(xlListFrames[k])
                            lib_Frames.append(newFrame)

                    # Build the Assembly Library
                    lib_Assemblies = []
                    xlListAssemblies = list(xlArrayAssemblies)
                    for i in range(0, len(xlListAssemblies), 4):
                        newAssembly = [
                            xlListAssemblies[i], xlListAssemblies[i + 1],
                            xlListAssemblies[i + 2], xlListAssemblies[i + 3]
                        ]
                        lib_Assemblies.append(newAssembly)

                succesReading = True
            else:
                print('No Library filepath set.')
                succesReading = False
        except:
            print('Woops... something went wrong reading from the Excel file?')
            succesReading = False

        #####################################################################################
        #################          Write the Rhino Doc Library              #################
        #####################################################################################
        if succesReading == True:
            # If there is any existing 'Document User-Text' Assemblies, Frames or Glazing Types, remove them
            print('Clearing out the old values from the Document UserText....')
            if rs.IsDocumentUserText():
                try:
                    for eachKey in rs.GetDocumentUserText():
                        if 'PHPP_lib_Glazing_' in eachKey or 'PHPP_lib_Frame_' in eachKey or 'PHPP_lib_Assmbly_' in eachKey:
                            print 'Deleting: Key:', eachKey
                            rs.SetDocumentUserText(
                                eachKey
                            )  # If no values are passed, deletes the Key/Value
                except:
                    print 'Error reading the Library File for some reason.'

            print('Writing New Library elements to the Document UserText....')
            # Write the new Assemblies to the Document's User-Text
            if lib_Assemblies:
                for eachAssembly in lib_Assemblies:
                    if eachAssembly[0] != None and len(
                            eachAssembly[0]) > 0:  # Filter our Null values
                        newAssembly = {
                            "Name": eachAssembly[0],
                            "Thickness": eachAssembly[1],
                            "uValue": eachAssembly[2],
                            "intInsulation": eachAssembly[3]
                        }
                        rs.SetDocumentUserText(
                            "PHPP_lib_Assmbly_{}".format(newAssembly["Name"]),
                            json.dumps(newAssembly))

            # Write the new Glazings to the Document's User-Text
            if lib_Glazing:
                for eachGlazing in lib_Glazing:
                    newGlazingType = {
                        "Name": eachGlazing[0],
                        "gValue": eachGlazing[1],
                        "uValue": eachGlazing[2]
                    }
                    rs.SetDocumentUserText(
                        "PHPP_lib_Glazing_{}".format(newGlazingType["Name"]),
                        json.dumps(newGlazingType))

            # Write the new Frames to the Document's User-Text
            if lib_Frames:
                for eachFrame in lib_Frames:
                    newFrameType = {
                        "Name": eachFrame[0],
                        "uFrame_L": eachFrame[1],
                        "uFrame_R": eachFrame[2],
                        "uFrame_B": eachFrame[3],
                        "uFrame_T": eachFrame[4],
                        "wFrame_L": eachFrame[5],
                        "wFrame_R": eachFrame[6],
                        "wFrame_B": eachFrame[7],
                        "wFrame_T": eachFrame[8],
                        "psiG_L": eachFrame[9],
                        "psiG_R": eachFrame[10],
                        "psiG_B": eachFrame[11],
                        "psiG_T": eachFrame[12],
                        "psiInst_L": eachFrame[13],
                        "psiInst_R": eachFrame[14],
                        "psiInst_B": eachFrame[15],
                        "psiInst_T": eachFrame[16],
                        "chi": eachFrame[17]
                    }
                    rs.SetDocumentUserText(
                        "PHPP_lib_Frame_{}".format(newFrameType["Name"]),
                        json.dumps(newFrameType))

        else:
            print 'Did not modify the Rhino User-Text Attributes.'

        print 'This ran in:', datetime.today() - t1, 'seconds'

        return 1
Пример #23
0
import rhinoscriptsyntax as rs
import trkRhinoPy as trp
import scriptcontext as sc
import json
import Rhino as rc
# import collections

sc.doc = rc.RhinoDoc.ActiveDoc

def createPtDict(pt):
    ptkeys = ["X","Y","Z"]
    ptVals = [pt.X, pt.Y, pt.Z]
    return dict(zip(ptkeys, ptVals))

def createLvlDict(pt, lvl):
    ptdict = createPtDict(pt)
    planekeys = ["level", "point"]
    planevals = [lvl, ptdict]
    lvldict = dict(zip(planekeys, planevals))
    return lvldict

planplanes = map(lambda x, y:createLvlDict(x, y), point, level)

sc.sticky["planplanes"] = planplanes
rs.SetDocumentUserText("planplanes", json.dumps(planplanes))
Пример #24
0
# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
import trkRhinoPy as trp
import scriptcontext as sc
import json

objs = rs.GetObjects('select objs',
                     rs.filter.surface | rs.filter.curve | rs.filter.point
                     | rs.filter.polysurface,
                     preselect=True)

levels = map(trp.createObjDict, objs)

sc.sticky["levels"] = json.dumps(levels)
rs.SetDocumentUserText("levels", json.dumps(levels))
Пример #25
0
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as rc
import json

sc.doc = rc.RhinoDoc.ActiveDoc

planplanes = x

sc.sticky["planplanes"] = map(json.loads, planplanes)
rs.SetDocumentUserText("planplanes", json.dumps(map(json.loads, planplanes)))
 def test_IsDocumentDataIgnoresUserText(self):
   _,k,v = sec_ent_val()
   rs.SetDocumentUserText(k,v)
   self.assertTrue(rs.IsDocumentData() == False)
Пример #27
0
def startupUserText():
    for key in siteKeys:
        rs.SetDocumentUserText(key, " ")
 def test_SetDocumentUserText_Typical(self):
   _,k,v = sec_ent_val()
   self.assertTrue(rs.SetDocumentUserText(k, v))
   self.assertEqual(v, rs.GetDocumentUserText(k))
Пример #29
0
def setDocLvlDB():
    map(getObjDict, objs)
    docval = str(docLvlDB)
    rs.SetDocumentUserText("docLvlDB", docval)