Skip to content

Commit

Permalink
resolved issue #571 [tool]
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Aug 15, 2020
1 parent 3563fce commit 2f1dce4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
Content="Re-Order"
Click="reorder_items"/>
</Grid>
<Grid DockPanel.Dock="Left" Width="30" Margin="0,0,10,0">
<Grid x:Name="shift_buttons" DockPanel.Dock="Left" Width="30" Margin="0,0,10,0" IsEnabled="False">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
Expand Down Expand Up @@ -119,6 +119,7 @@
CanUserSortColumns="True"
HorizontalGridLinesBrush="#dedede"
VerticalGridLinesBrush="#dedede"
SelectionChanged="sheet_selection_changed"
Sorting="sorting_changed">
<DataGrid.CellStyle>
<Style TargetType="DataGridCell" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This tool looks for project parameters (on Sheets) that are
Instance, of type Integer, and have "Order" in their names.
"""
#pylint: disable=W0613,E0401,C0103
# pylint: disable=W0613,E0401,C0103
import re

from pyrevit import forms
Expand Down Expand Up @@ -35,9 +35,9 @@ def __init__(self, xaml_file_name):

self._setup_item_params_combobox()

self.grouping_pattern = \
self._config.get_option('index_grouping_pattern',
r'([A-Z])\d')
self.grouping_pattern = self._config.get_option(
"index_grouping_pattern", r"([A-Z])\d"
)

@property
def items_list(self):
Expand Down Expand Up @@ -73,7 +73,7 @@ def _refresh(self):

def _update_order_indices(self):
if self.grouping_pattern:
last_groupid = ''
last_groupid = ""
grouping_index = 0
grouping_range = 1000
for idx, item in enumerate(self.items_list):
Expand All @@ -95,10 +95,13 @@ def _setup_item_params_combobox(self):
items = revit.query.get_sheets()
if items:
item_sample = items[0]
item_params = [x.Definition.Name for x in item_sample.Parameters
if x.StorageType == DB.StorageType.Integer]
item_params = [
x.Definition.Name
for x in item_sample.Parameters
if x.StorageType == DB.StorageType.Integer
]

order_params = [x for x in item_params if 'order' in x.lower()]
order_params = [x for x in item_params if "order" in x.lower()]
self.orderparams_cb.ItemsSource = sorted(order_params)
self.orderparams_cb.SelectedIndex = 0

Expand All @@ -107,9 +110,10 @@ def _get_ordered_items(self):
if self.selected_item_param:
items = sorted(
items,
key=lambda x: x.LookupParameter(self.selected_item_param)
.AsInteger()
)
key=lambda x: x.LookupParameter(
self.selected_item_param
).AsInteger(),
)
return items

def _get_selected_nonselected(self):
Expand Down Expand Up @@ -139,62 +143,75 @@ def selection_changed(self, sender, args):
# Show all items
self.items_list = items_list

def sheet_selection_changed(self, sender, args):
selected, non_selected = self._get_selected_nonselected()
self.shift_buttons.IsEnabled = True if selected else False

def sorting_changed(self, sender, args):
order_param = args.Column.SortMemberPath
if order_param == 'number':
if order_param == "number":
self.items_list = sorted(self.items_list, key=lambda x: x.number)
elif order_param == 'name':
elif order_param == "name":
self.items_list = sorted(self.items_list, key=lambda x: x.name)

def grouping_pattern_changed(self, sender, args):
self._refresh()

def move_to_top(self, sender, args):
selected, non_selected = self._get_selected_nonselected()
new_list = self._insert_list_in_list(selected, non_selected, 0)
self.items_list = new_list
if selected:
new_list = self._insert_list_in_list(selected, non_selected, 0)
self.items_list = new_list

def move_10_to_top(self, sender, args):
selected, non_selected = self._get_selected_nonselected()
index = self.items_dg.ItemsSource.index(selected[0])
new_list = self._insert_list_in_list(selected, non_selected, index - 10)
self.items_list = new_list
if selected:
index = self.items_dg.ItemsSource.index(selected[0])
new_list = self._insert_list_in_list(
selected, non_selected, index - 10
)
self.items_list = new_list

def move_1_to_top(self, sender, args):
selected, non_selected = self._get_selected_nonselected()
index = self.items_dg.ItemsSource.index(selected[0])
new_list = self._insert_list_in_list(selected, non_selected, index - 1)
self.items_list = new_list
if selected:
index = self.items_dg.ItemsSource.index(selected[0])
new_list = self._insert_list_in_list(selected, non_selected, index - 1)
self.items_list = new_list

def move_1_to_bottom(self, sender, args):
selected, non_selected = self._get_selected_nonselected()
index = self.items_dg.ItemsSource.index(selected[0])
new_list = self._insert_list_in_list(selected, non_selected, index + 1)
self.items_list = new_list
if selected:
index = self.items_dg.ItemsSource.index(selected[0])
new_list = self._insert_list_in_list(selected, non_selected, index + 1)
self.items_list = new_list

def move_10_to_bottom(self, sender, args):
selected, non_selected = self._get_selected_nonselected()
index = self.items_dg.ItemsSource.index(selected[0])
new_list = self._insert_list_in_list(selected, non_selected, index + 10)
self.items_list = new_list
if selected:
index = self.items_dg.ItemsSource.index(selected[0])
new_list = self._insert_list_in_list(selected, non_selected, index + 10)
self.items_list = new_list

def move_to_bottom(self, sender, args):
selected, non_selected = self._get_selected_nonselected()
new_list = self._insert_list_in_list(selected,
non_selected,
len(non_selected))
self.items_list = new_list
if selected:
new_list = self._insert_list_in_list(
selected, non_selected, len(non_selected)
)
self.items_list = new_list

def reorder_items(self, sender, args):
self.Close()
self._config.set_option('index_grouping_pattern',
self.grouping_pattern)
with revit.Transaction('Reorder Sheets'):
self._config.set_option("index_grouping_pattern", self.grouping_pattern)
with revit.Transaction("Reorder Sheets"):
for item in self.items_list:
idx_param = \
item.revit_item.LookupParameter(self.selected_item_param)
idx_param = item.revit_item.LookupParameter(
self.selected_item_param
)
if idx_param:
idx_param.Set(item.order_index)


ReOrderWindow('ReOrderWindow.xaml').ShowDialog()
ReOrderWindow("ReOrderWindow.xaml").ShowDialog()

0 comments on commit 2f1dce4

Please sign in to comment.