Skip to content

Commit

Permalink
Merge pull request #2498 from Malouche-git/settings-version-automation
Browse files Browse the repository at this point in the history
Settings - Automated Versions Listing
  • Loading branch information
jmcouffin authored Feb 1, 2025
2 parents 2ca3b6c + 5ae99f4 commit 59e22f7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
<system:String x:Key="RevitAttachment.Current">&lt;current&gt;</system:String>
<system:String x:Key="RevitAttachment.AllUsers">&lt;all users&gt;</system:String>
<system:String x:Key="RevitAttachment.NotAttached">&lt;Not attached&gt;</system:String>
<system:String x:Key="RevitAttachment.NotInstalled">Revit {} &lt;Not installed&gt;</system:String>
<system:String x:Key="RevitAttachment.NotInstalled">&lt;Not installed&gt;</system:String>

<system:String x:Key="Engines.WasChanged">
Active engine has changed.
Expand Down Expand Up @@ -367,4 +367,4 @@

<system:String x:Key="pyRevit.AdminInstall">pyRevit settings are set by your admin.</system:String>

</ResourceDictionary>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
<system:String x:Key="RevitAttachment.Current">&lt;actuel&gt;</system:String>
<system:String x:Key="RevitAttachment.AllUsers">&lt;tous les utilisateurs&gt;</system:String>
<system:String x:Key="RevitAttachment.NotAttached">&lt;Non attaché&gt;</system:String>
<system:String x:Key="RevitAttachment.NotInstalled">Revit {} &lt;Non installé&gt;</system:String>
<system:String x:Key="RevitAttachment.NotInstalled">&lt;Non installé&gt;</system:String>

<system:String x:Key="Engines.WasChanged">
Le moteur actif a été modifié.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@
<system:String x:Key="RevitAttachment.Current">&lt;текущий&gt;</system:String>
<system:String x:Key="RevitAttachment.AllUsers">&lt;все пользователи&gt;</system:String>
<system:String x:Key="RevitAttachment.NotAttached">&lt;не прикреплен&gt;</system:String>
<system:String x:Key="RevitAttachment.NotInstalled">Revit {} &lt;не установлен&gt;</system:String>
<system:String x:Key="RevitAttachment.NotInstalled">&lt;не установлен&gt;</system:String>

<system:String x:Key="Engines.WasChanged">
Активный движок изменился.
Expand Down Expand Up @@ -369,4 +369,4 @@

<system:String x:Key="pyRevit.AdminInstall">Настройки pyRevit устанавливаются вашим администратором.</system:String>

</ResourceDictionary>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -447,33 +447,18 @@
<Expander Header="{DynamicResource SupportedRevitVersions.Title}" IsExpanded="False" Margin="10px">
<StackPanel Margin="10px">
<TextBlock x:Name="revitversions_tb" TextWrapping="WrapWithOverflow" Text="{DynamicResource SupportedRevitVersions.Description}"/>
<CheckBox x:Name="revit2025_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2025
</CheckBox>
<CheckBox x:Name="revit2024_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2024
</CheckBox>
<CheckBox x:Name="revit2023_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2023
</CheckBox>
<CheckBox x:Name="revit2022_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2022
</CheckBox>
<CheckBox x:Name="revit2021_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2021
</CheckBox>
<CheckBox x:Name="revit2020_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2020
</CheckBox>
<CheckBox x:Name="revit2019_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2019
</CheckBox>
<CheckBox x:Name="revit2018_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2018
</CheckBox>
<CheckBox x:Name="revit2017_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">
Autodesk Revit 2017
</CheckBox>
<!--Link the list 'SupportedRevitVersions_CB' from python to the xaml-->
<ItemsControl ItemsSource="{Binding SupportedRevitVersions_CB}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Content}"
IsChecked="{Binding IsChecked}"
IsEnabled="{Binding IsEnabled}"
Margin="0,10,0,0"
Style="{StaticResource RevitCheckbox}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Expander>
<Separator Margin="10,0,10,0" Background="#dfdfdf"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


logger = script.get_logger()

available_revit_versions = ['2025', '2024', '2023', '2022', '2021', '2020', '2019', '2018', '2017']

class EnvVariable(object):
"""List item for an environment variable.
Expand Down Expand Up @@ -67,6 +67,15 @@ def name(self):
self.engine.Description)


class RevitVersionCB:
"""Represents a Revit version Checkbox for binding with XAML."""
def __init__(self, version, is_checked=False, is_enabled=False):
self.Content = "Revit {}".format(version) # Display name in the UI
self.Version = version # YEAR version (e.g., '2024')
self.IsChecked = is_checked # Whether the checkbox is checked
self.IsEnabled = is_enabled # Whether the checkbox is enabled


class SettingsWindow(forms.WPFWindow):
"""pyRevit Settings window that handles setting the pyRevit configs"""

Expand All @@ -86,19 +95,9 @@ def __init__(self, xaml_file_name):
self._setup_env_vars_list()

# check boxes for each version of Revit
# this could be automated but it pushes me to verify and test
# before actually adding a new Revit version to the list
self._addinfiles_cboxes = {
'2017': self.revit2017_cb,
'2018': self.revit2018_cb,
'2019': self.revit2019_cb,
'2020': self.revit2020_cb,
'2021': self.revit2021_cb,
'2022': self.revit2022_cb,
'2023': self.revit2023_cb,
'2024': self.revit2024_cb,
'2025': self.revit2025_cb,
}
self.supported_revit_versions_CB = [RevitVersionCB(rvt_ver, is_checked=False, is_enabled=False) for rvt_ver in available_revit_versions]
# Bind the SupportedVersions to the XAML's DataContext
self.DataContext = self

self.set_image_source(self.lognone, 'lognone.png')
self.set_image_source(self.logverbose, 'logverbose.png')
Expand Down Expand Up @@ -372,14 +371,6 @@ def _setup_telemetry(self):
event_checkbox.IsChecked = \
telemetry.get_apptelemetry_event_state(event_flags, event_type)

def _make_product_name(self, product, note):
return '_{} | {}({}) {}'.format(
product.Name,
product.BuildNumber,
product.BuildTarget,
note
)

def _setup_addinfiles(self):
"""Gets the installed Revit versions and sets up the ui"""
installed_revits = \
Expand All @@ -389,42 +380,23 @@ def _setup_addinfiles(self):
{str(x.Product.ProductYear):x
for x in PyRevit.PyRevitAttachments.GetAttachments()}

for rvt_ver, checkbox in self._addinfiles_cboxes.items():
if rvt_ver in attachments:
if rvt_ver != HOST_APP.version:
checkbox.Content = \
self._make_product_name(
attachments[rvt_ver].Product,
''
)
else:
checkbox.Content = \
self._make_product_name(
attachments[rvt_ver].Product,
self.get_locale_string("RevitAttachment.Current")
)

checkbox.IsChecked = True
if attachments[rvt_ver].AttachmentType == \
PyRevit.PyRevitAttachmentType.AllUsers:
checkbox.IsEnabled = False
checkbox.Content += self.get_locale_string("RevitAttachment.AllUsers")
else:
checkbox.IsEnabled = True
else:
if rvt_ver in installed_revits:
checkbox.Content = \
self._make_product_name(
installed_revits[rvt_ver],
self.get_locale_string("RevitAttachment.NotAttached")
)
checkbox.IsEnabled = True
checkbox.IsChecked = False
else:
checkbox.Content = \
self.get_locale_string("RevitAttachment.NotInstalled").format(rvt_ver)
checkbox.IsEnabled = False
checkbox.IsChecked = False
for checkbox in self.supported_revit_versions_CB:
#checkbox.IsEnabled and checkbox.IsChecked are False by default
if checkbox.Version not in installed_revits:
checkbox.Content += self.get_locale_string("RevitAttachment.NotInstalled")
continue
product = installed_revits[checkbox.Version]
checkbox.Content += ' | {} | {}({}) '.format(product.Name, product.BuildNumber, product.BuildTarget)
checkbox.IsEnabled = True
if checkbox.Version not in attachments:
checkbox.Content += self.get_locale_string("RevitAttachment.NotAttached")
continue
checkbox.IsChecked = True
if checkbox.Version == HOST_APP.version:
checkbox.Content += self.get_locale_string("RevitAttachment.Current")
if attachments[checkbox.Version].AttachmentType == PyRevit.PyRevitAttachmentType.AllUsers:
checkbox.Content += self.get_locale_string("RevitAttachment.AllUsers")
checkbox.IsEnabled = False

def is_same_version_as_running(self, version):
return str(version) == EXEC_PARAMS.engine_ver
Expand Down Expand Up @@ -454,17 +426,12 @@ def update_addinfiles(self):
)

# now setup the attachments for other versions
for rvt_ver, checkbox in self._addinfiles_cboxes.items():
for checkbox in self.supported_revit_versions_CB:
if checkbox.IsEnabled:
if checkbox.IsChecked:
PyRevit.PyRevitAttachments.Attach(
int(rvt_ver),
attachment.Clone,
new_engine,
False
)
PyRevit.PyRevitAttachments.Attach(int(checkbox.Version),attachment.Clone,new_engine,False)
else:
PyRevit.PyRevitAttachments.Detach(int(rvt_ver))
PyRevit.PyRevitAttachments.Detach(int(checkbox.Version))
else:
logger.error('Error determining current attached clone.')

Expand Down

0 comments on commit 59e22f7

Please sign in to comment.