def launchHelp(): try: fileLocations = config.GetDict() path = fileLocations['Help File'] subprocess.Popen([path],shell=True) return True except: return False
def IsSavedInProjectFolder(): """Checks if Rhino file is saved in a project folder """ fileLocations = config.GetDict() x = rs.DocumentPath() if x is None: return False print if rs.DocumentPath()[:2] == fileLocations['Project Folders'][:2]: return True else: return False
def SaveToAnalyticsOLD(funcName): """SaveToAnalytics(funcName) Inputs: funcName(str): The functions name returns: None """ try: fileLocations = config.GetDict() filepath = fileLocations['Analytics'] #filepath = 'data\Analytics.csv' with open(filepath, 'rb') as File: reader = csv.reader(File) data = list(reader) #Update date data[0][1] = 'Last Updated: ' + GetDatePrefix() #Username userName = encrypt.encrypt(getpass.getuser()) #Update Column colPos = None for i,item in enumerate(data[1]): if item == funcName: colPos = i if colPos is None: colPos = len(data[1]) data[1].append(funcName) rowPos = None for i,item in enumerate(data): if item[0] == userName: rowPos = i if rowPos is None: rowPos = len(data) data.append([userName]) newCells = (colPos+1) - len(data[rowPos]) for i in range(newCells): data[rowPos].append('') try: data[rowPos][colPos] = int(data[rowPos][colPos]) + 1 except: data[rowPos][colPos] = 1 myFile = open(filepath, 'wb') with myFile: csvwriter = csv.writer(myFile) csvwriter.writerows(data) except: print "Analytics failed"
def LoadStyles(filepath=None): if filepath is None: fileLocations = config.GetDict() filepath = '"' + fileLocations['Template File'] + '"' else: filepath = '"' + filepath + '"' try: rs.Command('-_ImportAnnotationStyles ' + filepath + ' Enter Enter Enter', echo=False) print "\tAnnotation Styles Updated" except: print "FAIL-----Annotation Style Import Failed"
def ForceMaterialToLayer(materialName, mylayer): """ Applies material by name to layer. If no layer found, it is imported. materialName: str mylayer: str """ fileLocations = config.GetDict() materialNameFull = materialName + '.rmtl' dir = fileLocations['Material Folder'] matpath = os.path.join(dir, materialNameFull) if IsMaterial(materialName): ApplyMaterialToLayer(materialName, mylayer) else: result = loadMatFromPath(matpath) if result is None: print "Material {} not found".format(materialName) else: ApplyMaterialToLayer(materialName, mylayer)
def SaveFunctionData(funcName, funcData): """ SaveFunctionData(funcName, funcData) funcName = name of function(str) funcData = data to save [list] """ try: now=datetime.datetime.now() monthString=('%02d%02d'%(now.year, now.month))[2:] fileLocations = config.GetDict() filepath = fileLocations['Data Folder'] fileName = monthString + '_' + funcName + '.csv' fullName = os.path.join(filepath, fileName) userName = encrypt.encrypt(getpass.getuser()) now=datetime.datetime.now() dateString='%02d-%02d-%02d'%(now.year, now.month, now.day) timeString= '%02d:%02d:%02d'%(now.hour, now.minute,now.second) if not os.path.isfile(fullName): data = [[funcName],['Date', 'Time', 'User', 'Version']] myFile = open(fullName, 'wb') with myFile: csvwriter = csv.writer(myFile) csvwriter.writerows(data) with open(fullName, 'rb') as File: reader = csv.reader(File) data = list(reader) row = [dateString, timeString, userName] + funcData data.append(row) myFile = open(fullName, 'wb') with myFile: csvwriter = csv.writer(myFile) csvwriter.writerows(data) except: print "SaveFunctionData failed"
def setupVariables(): fileLocations = config.GetDict() global csvPath csvPath = fileLocations['PCPA Layers'] global layNumColumn layNumColumn = 0 global nameColumn nameColumn = 1 global parentColumn parentColumn = 2 global colorColumn colorColumn = 3 global materialColumn materialColumn = 4 global linetypeColumn linetypeColumn = 5 global printcolorColumn printcolorColumn = 6 global printwidthColumn printwidthColumn = 7 global fullLayerNameColumn fullLayerNameColumn = 8
__author__ = 'Tim Williams' __version__ = "2.1.0" def OpenFolder(path): try: subprocess.call("explorer " + path, shell=True) return True except: return False if __name__ == "__main__": func = rs.GetInteger("Func number") fileLocations = config.GetDict() if func == 0: OpenFolder(fileLocations['PCPA GH Components']) if func == 1: OpenFolder(fileLocations['GH Dependencies']) if func == 2: OpenFolder(fileLocations['Template Folder']) if func == 3: OpenFolder(fileLocations['Display Mode Folder']) if func == 4: OpenFolder(fileLocations['ACAD Scheme Folder']) if func == 5: OpenFolder(rs.DocumentPath()) if func == 6: OpenFolder(fileLocations['3d Blocks'])
def SaveToAnalytics(funcName): """SaveToAnalytics(funcName) Inputs: funcName(str): The functions name returns: None """ try: now=datetime.datetime.now() monthString=('%02d%02d'%(now.year, now.month))[2:] fileLocations = config.GetDict() filepath = fileLocations['Data Folder'] fileName = monthString + '_Analytics.csv' fullName = os.path.join(filepath, fileName) dateString='%02d-%02d-%02d'%(now.year, now.month, now.day) if not os.path.isfile(fullName): data = [[funcName , 'Last Updated']] myFile = open(fullName, 'wb') with myFile: csvwriter = csv.writer(myFile) csvwriter.writerows(data) myFile.close() with open(fullName, 'rb') as File: reader = csv.reader(File) data = list(reader) File.close() #Update date data[0][1] = 'Last Updated: ' + GetDatePrefix() #Username userName = encrypt.encrypt(getpass.getuser()) #Update Column colPos = None if len(data)>1: #If there is a second row: for i,item in enumerate(data[1]): if item == funcName: colPos = i if colPos is None: colPos = len(data[1]) data[1].append(funcName) else: #If there is not a second row colPos = 1 data.append(['User', funcName]) rowPos = None for i,item in enumerate(data): if item[0] == userName: rowPos = i if rowPos is None: rowPos = len(data) data.append([userName]) newCells = (colPos+1) - len(data[rowPos]) for i in range(newCells): data[rowPos].append('') try: data[rowPos][colPos] = int(data[rowPos][colPos]) + 1 except: data[rowPos][colPos] = 1 with open(fullName, 'wb') as myFile: csvwriter = csv.writer(myFile) csvwriter.writerows(data) except: pass
def exportToRenderDWG(): try: fileLocations = config.GetDict() print "Exporting to 3ds max" objs = rs.GetObjects("Select objects to export", preselect=True) if objs is None: return #SAVE FILE NAME defaultFolder = rs.DocumentPath() defaultFilename = utils.GetDatePrefix() + '_OPTION_01' fileName = rs.SaveFileName("Export to render", "Autocad (*.dwg)|*.dwg||", defaultFolder, defaultFilename) if fileName is None: return base=os.path.basename(fileName) cadName = os.path.splitext(base)[0] #SUPER EXPLODE #EXPLODE SELECTED BLOCKS (CHECKLIST) #blockNames = rs.BlockNames(True) #print blockNames #results = rs.CheckListBox(blockNames, "Select blocks to explode", "Explode for render") #CHECK BACKFACES #CHECK GEOMETRY #EXPORT EACH LAYER AS SAT FILE. #CHECK ORIGIN #INSERT ORIGIN #CHECK SCALE (Units) if rs.UnitSystem() == 8: print "Units checked" else: print "This model is in {}, it should be in Inches".format(rs.UnitSystemName(singular=False)) #UNIFY MESH NORMALS #MERGE ALL EDGES #MERGE ALL FACES #DELETE DUPS #rs.UnselectAllObjects() #rs.Command('-_Seldup ', echo=False) #dupObjs = rs.SelectedObjects() #if len(dupObjs) > 0: # rs.DeleteObjects(dupObjs) # print "{} duplicate objects deleted".format(len(dupObjs)) #JOIN BY LAYER #PLACE UNDER A PARENT LAYER W/ DATESTAMP AddMasterRootLayer(cadName) #CHANGE LAYER NAMES? #IMPORT ACAD SCHEME standards.LoadAcadSchemes(fileLocations['ACAD Scheme Folder']) #SET DEFAULT FOLDER TO REFERENCE FOLDER UNDER RENDERING #EXPORT TO DWG rs.SelectObjects(objs) exportScheme = 'PCPA_MaxSolids' rs.Command('-_Export ' + '"' + fileName + '" S ' + '"' + exportScheme + '"' + ' Enter P 100 Enter', False) #REMOVE MASTER ROOT LAYER RemoveMasterRootLayer(cadName) return True except: return False
def AddTitleBlock(size): filelocations = config.GetDict() rs.EnableRedraw(False) if size == 11: offset = .354 row1 = offset row2 = row1 * 2 row3 = row1 * 3 row4 = row1 * 4 leftEdge = offset middle = 17 / 2 rightEdge = 17 - offset pt1 = [leftEdge, row4] pt2 = [rightEdge, 11 - row1] txtBase1 = [middle, row2] txtBase2 = [leftEdge, row2] txtBase3 = [rightEdge, row2] txtBase4 = [leftEdge, row1] txtBase5 = [rightEdge, row1] lineSt = [leftEdge, row3] lineEnd = [rightEdge, row3] txtSizeL = .125 txtSizeM = .094 logoPlane = [13.834, .247, 0] logoWidth = 2.823 logoHeight = .116 elif size == 8: offset = .229 row1 = offset row2 = row1 * 2 row3 = row1 * 3 row4 = row1 * 4 leftEdge = offset middle = 11 / 2 rightEdge = 11 - offset pt1 = [leftEdge, row4] pt2 = [rightEdge, 8.5 - row1] txtBase1 = [middle, row2] txtBase2 = [leftEdge, row2] txtBase3 = [rightEdge, row2] txtBase4 = [leftEdge, row1] txtBase5 = [rightEdge, row1] lineSt = [leftEdge, row3] lineEnd = [rightEdge, row3] txtSizeL = .125 txtSizeM = .063 logoPlane = [8.347, .157, 0] logoWidth = 2.434 logoHeight = .100 elif size == 18: offset = .5 row1 = offset row2 = row1 * 2 row3 = row1 * 3 row4 = row1 * 4 leftEdge = offset middle = 24 / 2 rightEdge = 24 - offset pt1 = [leftEdge, row4] pt2 = [rightEdge, 18 - row1] txtBase1 = [middle, row2] txtBase2 = [leftEdge, row2] txtBase3 = [rightEdge, row2] txtBase4 = [leftEdge, row1] txtBase5 = [rightEdge, row1] lineSt = [leftEdge, row3] lineEnd = [rightEdge, row3] txtSizeL = .250 txtSizeM = .125 logoPlane = [19.627, .367, 0] logoWidth = 3.885 logoHeight = .160 layout = sc.doc.Views.GetPageViews()[-1] if layout is None: return sc.doc.Views.ActiveView = layout if rs.GetDocumentData(section="PCPA", entry="Project_Name") is None: rs.SetDocumentData(section="PCPA", entry="Project_Name", value="PROJECT TITLE") projectTitle = '%<DocumentText("PCPA\Project_Name")>%' if rs.GetDocumentData(section="PCPA", entry="Client_Name") is None: rs.SetDocumentData(section="PCPA", entry="Client_Name", value="Client Name") clientName = '%<DocumentText("PCPA\Client_Name")>%' #Add text textList = [] textList.append(rs.AddText("Title", txtBase1, txtSizeL, justification=2)) textList.append( rs.AddText(projectTitle, txtBase2, txtSizeL, justification=1)) textList.append( rs.AddText('%<Date("MMMM d, yyyy")>%', txtBase3, txtSizeM, justification=4)) textList.append(rs.AddText(clientName, txtBase4, txtSizeM, justification=1)) #ADD Copyright copyright = 'COPYRIGHT ' + u"\u00a9" + ' %<Date("yyyy")>%' copyrightText = rs.AddText(copyright, txtBase5, txtSizeM, justification=4) #ADD Pelli Clarke Pelli pcp = 'Pelli Clarke Pelli' pcpText = rs.AddText(pcp, txtBase5, txtSizeM, justification=4) if rs.IsDimStyle('PCPA_10'): dimstyleID = sc.doc.DimStyles.FindName('PCPA_14') ############## #Just trying to change the dim style here #pcpRhobj = rs.coercerhinoobject(pcpText) #test = pcpRhobj.Attributes #pcpRhobj.CommitChanges() ############## #ADD Architects architects = 'Architects' architectsText = rs.AddText(architects, txtBase5, txtSizeM, justification=4) #Horizontal line line = rs.AddLine(lineSt, lineEnd) #Add detail detail = rs.AddDetail(layout.ActiveViewportID, pt1, pt2, "PCPA " + str(layout.PageName), 7) #Change layers AddLayerByNumber try: rs.ObjectLayer(line, layers.GetLayerNameByNumber(8204)) except: pass try: rs.ObjectLayer(detail, layers.GetLayerNameByNumber(8106)) except: pass try: for eachText in textList: rs.ObjectLayer(eachText, layers.GetLayerNameByNumber(8105)) except: pass try: rs.ObjectLayer(copyrightText, layers.GetLayerNameByNumber(8211)) except: pass try: rs.ObjectLayer(pcpText, layers.GetLayerNameByNumber(8210)) except: pass try: rs.ObjectLayer(architectsText, layers.GetLayerNameByNumber(8211)) except: pass rs.EnableRedraw(True)