Skip to content

Commit

Permalink
Update parameter.py
Browse files Browse the repository at this point in the history
  • Loading branch information
marcantondahmen committed Feb 5, 2021
1 parent 45b9c86 commit 2259a2b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions revitron/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,15 @@ def get(self, name):

class ParameterTemplate:
"""
Create a string based on a parameter template where parameter names are wrapped in :code:`{}` and get substituted with their value::
Create a string based on a parameter template where parameter names are wrapped in :code:`{...}` and get substituted with their value::
This sheet has the number {Sheet Number} and the name {Sheet Name}
It is also possible to get parameter values from the project information instead by wrapping the parameter names
in :code:`{%...%}` instead::
This sheet of the project {%Project Name%} has the number {Sheet Number} and the name {Sheet Name}
"""

def __init__(self, element, template, sanitize = True):
Expand All @@ -421,6 +427,9 @@ def __init__(self, element, template, sanitize = True):
template (string): A template string
sanitize (bool, optional): Optionally sanitize the returned string. Defaults to True.
"""
import revitron

self.projectInfo = revitron.DOC.ProjectInformation
self.element = element
self.template = template
self.sanitize = sanitize
Expand All @@ -439,7 +448,13 @@ def reCallback(self, match):
import revitron

parameter = match.group(1)
string = str(revitron.Element(self.element).get(parameter))

try:
match = re.match('^%(.+?)%$', parameter)
parameter = match.group(1)
string = str(revitron.Element(self.projectInfo).get(parameter))
except:
string = str(revitron.Element(self.element).get(parameter))

if self.sanitize:
string = revitron.String.sanitize(string)
Expand Down

0 comments on commit 2259a2b

Please sign in to comment.