def __init__(self, elements): out = output.get_output() self.info = [] for element in elements: dependents = [] for dep in _(element).getDependent(): depFamType = revitron.Parameter( dep, 'Family and Type').getValueString() depInfo = '{} {}, {}'.format(out.linkify(dep.Id), _(dep).getCategoryName(), depFamType).strip(', ') depInfo = depInfo + '<br>' dependents.append(depInfo) self.info.append([ out.linkify(element.Id), _(element).getClassName(), _(element).getCategoryName(), revitron.Parameter(element, 'Family and Type').getValueString(), ''.join(dependents) ])
def set(self, paramName, value, paramType='Text'): """ Sets a parameter value. Example:: _(element).set('name', 'value', 'type') Some possible parameter types are: - ``Text`` - ``Integer`` - ``Number`` - ``Length`` - ``Angle`` - ``Material`` - ``YesNo`` - ``MultilineText`` - ``FamilyType`` You can find a list of all types `here <https://www.revitapidocs.com/2019/f38d847e-207f-b59a-3bd6-ebea80d5be63.htm>`_. Args: paramName (string): The parameter name value (mixed): The value paramType (string, optional): The parameter type. Defaults to 'Text'. Returns: object: The element instance """ import revitron revitron.Parameter(self._element, paramName).set(value, paramType) return self
def onSynced(self, sender, args): if str(args.Status) == 'Succeeded': doc = self.getCurrentlyActiveDoc() hdu = HistoryDocUtils(doc) if hdu.isTrackedProject(): if doc.PathName in self.activeDocs: self.activeDocs[ doc.PathName]['finishTime'] = self.timestamp() self.activeDocs[doc.PathName]['size'] = hdu.getFileSize() data = self.activeDocs[doc.PathName] db = HistoryDatabase(hdu.getSqliteFile()) self.debug('Writing to sync data') syncId = db.sync({ 'startTime': data['startTime'], 'finishTime': data['finishTime'], 'size': data['size'], 'user': data['user'] }) self.debug('Writing to transaction data') rows = [] for elemId in data['elements']: row = dict() row['elementId'] = elemId row['transactions'] = json.dumps( data['elements'][elemId]['transactions']) # Add current Type to change type event. try: elem = doc.GetElement( revitron.DB.ElementId(int(elemId))) if elem: row['transactions'] = row[ 'transactions'].replace( 'Change Type', 'Change Type to ' + revitron.Parameter( elem, 'Family and Type' ).getValueString()) except: pass rows.append(row) db.transactions(rows, syncId) # Reset lists del self.activeDocs[doc.PathName] # Delete dump file hdu.deleteDumpFile() self.debug('Synced') else: self.debug('Syncing failed or cancelled')
def getParameter(self, paramName): """ Returns a parameter object. Args: paramName (string): The name of the parameter Returns: object: The parameter object """ import revitron return revitron.Parameter(self._element, paramName)
def byRegex(self, paramName, regex, invert=False): """ Filters a collection by a given regex. Args: paramName (string): The name of the parameter to be matched. regex (string): The regex. invert (bool, optional): Inverts the filter. Defaults to False. Returns: object: The Filter instance """ import revitron passed = [] failed = [] for element in self.getElements(): value = revitron.Parameter(element, paramName).getString() if not value: value = revitron.Parameter(element, paramName).getValueString() if value: if re.search(regex, value, re.IGNORECASE): passed.append(element) else: failed.append(element) if not invert: elements = passed else: elements = failed if elements: self.collector = Filter(elements).collector return self
def get(self, paramName): """ Returns a parameter value. Example:: value = _(element).get('name') Args: paramName (string): The name of the parameter Returns: mixed: The parameter value """ import revitron return revitron.Parameter(self._element, paramName).get()
def getLinkedDocuments(self, scope = None): """ Returns a dictionary of all linked documents. The key is the ID of the link and the value is the actual document object. Args: scope (mixed, optional): List or view ID. Defaults to None. Returns: dict: A dictionary of all linked documents. """ import revitron linkedDocuments = dict() extension = '.rvt' for link in revitron.Filter(scope).byCategory('RVT Links').noTypes().getElements(): linkType = revitron.Parameter(link, 'Type').getValueString() if linkType.endswith(extension): linkType = linkType[:-len(extension)] for openDoc in revitron.APP.Documents: if openDoc.IsLinked: if openDoc.Title == linkType: linkedDocuments[link.Id] = openDoc return linkedDocuments
out.print_html( '<hr style="border: none; border-bottom: 1px dotted #ccc;" />') info = '' try: if element.Category is not None: info += element.Category.Name + ' ' except: pass try: if element.Name is not None: info += element.Name + ' ' except: pass info += revitron.Parameter(element, 'Family and Type').getValueString() out.print_md('###' + info.strip() + ' ' + out.linkify(element.Id)) try: conn = sqlite3.connect(sqliteFile) cursor = conn.cursor() cursor.execute(sqlTransactions, {'id': element.Id.ToString()}) rows = cursor.fetchall() except: out.close() forms.alert('There hasn\'t been anything logged yet!', exitscript=True) if rows: table = '<table>' table += '<tr>'
forms.Label('Replacement'), forms.TextBox('replace'), forms.Separator(), forms.Button('Apply') ]) form.show() t = revitron.Transaction() for element in selection: if 'parameter' in form.values.keys(): param = form.values['parameter'] if param: prefix = form.values['prefix'] suffix = form.values['suffix'] regex = form.values['regex'] replace = form.values['replace'] if isFamilyType(element) and param == 'Name': if prefix or suffix: element.Name = prefix + _(element).get('Type Name') + suffix if regex: element.Name = str(re.sub(regex, replace, _(element).get('Type Name'), flags = re.IGNORECASE)) else: if revitron.Parameter(element, param).exists(): if prefix or suffix: _(element).set(param, prefix + _(element).get(param) + suffix) if regex: _(element).set(param, str(re.sub(regex, replace, _(element).get(param), flags = re.IGNORECASE))) t.commit()
def testParameterSet(self): wall = self.fixture.createWall() with revitron.Transaction(): _(wall).set('text', 'some text') _(wall).set('integer', 5, 'Integer') _(wall).set('integerAuto', 5) _(wall).set('number', 10.5, 'Number') _(wall).set('numberAuto', 10.5) _(wall).set('length', 5, 'Length') _(wall).set('Comments', 'some comment') self.assertEquals( str(revitron.Parameter(wall, 'integer').parameter.StorageType), 'Integer') self.assertEquals( str(revitron.Parameter(wall, 'integerAuto').parameter.StorageType), 'Integer') self.assertEquals( str(revitron.Parameter(wall, 'number').parameter.StorageType), 'Double') self.assertEquals( str(revitron.Parameter(wall, 'numberAuto').parameter.StorageType), 'Double') self.assertEquals( str(revitron.Parameter(wall, 'length').parameter.StorageType), 'Double') self.assertEquals( 'Text', str( revitron.Parameter(wall, 'text').parameter.Definition.ParameterType)) self.assertEquals( 'Integer', str( revitron.Parameter( wall, 'integer').parameter.Definition.ParameterType)) self.assertEquals( 'Integer', str( revitron.Parameter( wall, 'integerAuto').parameter.Definition.ParameterType)) self.assertEquals( 'Number', str( revitron.Parameter( wall, 'number').parameter.Definition.ParameterType)) self.assertEquals( 'Number', str( revitron.Parameter( wall, 'numberAuto').parameter.Definition.ParameterType)) self.assertEquals( 'Length', str( revitron.Parameter( wall, 'length').parameter.Definition.ParameterType)) self.assertEquals(_(wall).get('text'), 'some text') self.assertEquals(_(wall).get('integer'), 5) self.assertEquals(_(wall).get('integerAuto'), 5) self.assertEquals(_(wall).get('number'), 10.5) self.assertEquals(_(wall).get('numberAuto'), 10.5) self.assertEquals(_(wall).get('length'), 5) self.assertEquals(_(wall).get('Comments'), 'some comment')