Skip to content

Commit

Permalink
implemented #944
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Aug 9, 2020
1 parent 04e860a commit 693aaed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,26 @@
Height="24"
SelectionChanged="on_param_change"/>
</DockPanel>
<Expander Header="Guide" Margin="0,5,0,0">
<Border Margin="0,5,0,0" Padding="10" CornerRadius="5" Background="{DynamicResource pyRevitAccentBrush}">
<TextBlock TextWrapping="WrapWithOverflow" Margin="0,3,0,0" Foreground="White">
<Bold>By Format</Bold>
<LineBreak />
Specify the existing pattern of the values in the first box and a new format in the second box. For example,
if value is "OVERALL 1ST FLOOR", the first box can contain <Run FontFamily="Consolas">"{type} {lvl}ST {name}"</Run>.
The tool will match the specified format to the value and will extract the parts accordingly. Using the second box,
you can rearrange these extracted parts. In this example, specifying <Run FontFamily="Consolas">"LEVEL {lvl} - {type} {name} PLAN"</Run>
inside the second box will revalue to <Run FontFamily="Consolas">"LEVEL 1 - OVERALL FLOOR PLAN"</Run>
<LineBreak />
<LineBreak />
<Bold>By Regular Expression</Bold>
<LineBreak />
If the first box does not contain a format finder "{}", then the tool works in Find/Replace mode with Regular Expression support.
</TextBlock>
</Border>
</Expander>
<DockPanel Margin="0,10,0,0">
<TextBlock FontSize="14" Margin="0,0,10,0" Width="100" DockPanel.Dock="Left" VerticalAlignment="Center">Original Format:</TextBlock>
<TextBlock FontSize="14" Margin="0,0,10,0" Width="100" DockPanel.Dock="Left" VerticalAlignment="Center">Original Pattern:</TextBlock>
<TextBox x:Name="orig_format_tb"
Height="24"
FontSize="14" FontFamily="Courier New"
Expand All @@ -25,7 +43,7 @@
TextChanged="on_format_change"/>
</DockPanel>
<DockPanel Margin="0,10,0,0">
<TextBlock FontSize="14" Margin="0,0,10,0" Width="100" DockPanel.Dock="Left" VerticalAlignment="Center">New Format:</TextBlock>
<TextBlock FontSize="14" Margin="0,0,10,0" Width="100" DockPanel.Dock="Left" VerticalAlignment="Center">New Pattern:</TextBlock>
<TextBox x:Name="new_format_tb"
Height="24"
FontSize="14" FontFamily="Courier New"
Expand All @@ -45,13 +63,13 @@
</Grid.ColumnDefinitions>
<Button x:Name="apply_b"
Margin="5,0,0,0"
Grid.Column="2" Grid.Row="0"
Grid.Column="2" Grid.Row="0"
Height="24"
Content="Apply New Values"
Click="apply_new_values"/>
<Button x:Name="final_b"
Margin="0,0,5,0"
Grid.Column="1" Grid.Row="0"
Grid.Column="1" Grid.Row="0"
Height="24"
Content="Mark Selected as Final"
Click="mark_as_final"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Reformat parameter string values (Super handy for renaming elements)"""
#pylint: disable=E0401,W0703,W0613
import re

from pyrevit import coreutils
from pyrevit import revit, DB
from pyrevit import forms
Expand All @@ -17,15 +19,23 @@ def __init__(self, eid, oldvalue, final=False):
self.final = final
self.tooltip = ''

def format_value(self, old_format, new_format):
def format_value(self, from_pattern, to_pattern):
try:
if old_format and new_format:
self.newvalue = coreutils.reformat_string(self.oldvalue,
old_format,
new_format)
self.tooltip = '{} --> {}'.format(old_format, new_format)
if from_pattern and to_pattern:
# if format contains pattern finders use reformatter
if any(x in from_pattern for x in ['{', '}']):
self.newvalue = \
coreutils.reformat_string(self.oldvalue,
from_pattern,
to_pattern)
self.tooltip = '{} --> {}'.format(from_pattern, to_pattern)
# otherwise use a simple find/replacer
else:
self.newvalue = \
re.sub(from_pattern, to_pattern, self.oldvalue)
else:
self.tooltip = 'No Conversion Specified'
self.newvalue = ''
except Exception:
self.newvalue = ''

Expand Down

0 comments on commit 693aaed

Please sign in to comment.