Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings - Revit versions listing automation #2390

Open
jmcouffin opened this issue Sep 6, 2024 · 2 comments
Open

Settings - Revit versions listing automation #2390

jmcouffin opened this issue Sep 6, 2024 · 2 comments
Labels
Enhancement Enhancement request [class->Improved #{number}: {title}] Good First Issue Bug or feature with trivial solution that awaits you to be fixed! New Feature New feature request [class->Implemented #{number}: {title}]

Comments

@jmcouffin
Copy link
Contributor

jmcouffin commented Sep 6, 2024

image

It requires automation in these two files

<CheckBox x:Name="revit2024_cb" Style="{StaticResource RevitCheckbox}" Margin="0,10,0,0" IsChecked="False" IsEnabled="False">

@jmcouffin jmcouffin added New Feature New feature request [class->Implemented #{number}: {title}] Enhancement Enhancement request [class->Improved #{number}: {title}] Good First Issue Bug or feature with trivial solution that awaits you to be fixed! labels Sep 6, 2024
@jmcouffin jmcouffin added this to pyRevit Sep 6, 2024
@jmcouffin jmcouffin moved this to Later in pyRevit Sep 6, 2024
@jmcouffin jmcouffin added this to the post pyRevit 5 RC milestone Sep 6, 2024
@Malouche-git
Copy link
Contributor

I found part of the solution !

This involves a few changes:

  1. Creating a RevitVersionCB class to store the checkbox information.
  2. Generating a list of checkbox objects dynamically.
  3. Applying the list to the XAML file using data binding.
  4. Using the list to create the _addinfiles_cboxes dictionary, which previously existed (for further processing).

Python code :

class RevitVersionCB:
    """Represents a Revit version Checkbox for binding with XAML."""
    def __init__(self, version, is_checked=False, is_enabled=True):
        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
# Dynamically define Revit versions
self.available_revit_versions = ['2024', '2023', '2022', '2021', '2020', '2019', '2018', '2017']
self.SupportedRevitVersions_CB = [
        RevitVersionCB(rvt_ver,is_checked=False, is_enabled=True)
        for rvt_ver in self.available_revit_versions]

#create the dict for further processing
#(maybe some easier or clearer code by modifying these func _setup_addinfiles and update_addinfiles ?)
self._addinfiles_cboxes = {ver_cb.Version : ver_cb for ver_cb in self.SupportedRevitVersions_CB}

# Bind the SupportedVersions to the XAML's DataContext
self.DataContext = self

XAML code :

<Expander Header="{DynamicResource SupportedRevitVersions.Title}" IsExpanded="False" Margin="10px">
   <StackPanel Margin="10px">
        <TextBlock x:Name="revitversions_tb" TextWrapping="WrapWithOverflow" Text="{DynamicResource SupportedRevitVersions.Description}"/>
        <!--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>

To go further :

  1. Remove the _addinfiles_cboxes dictionary and use the SupportedRevitVersions_CB object list directly in both _setup_addinfiles and update_addinfiles functions.
  2. Automate the creation of the version list by parsing the bin/pyrevit-hosts.json file.
    (This might not be necessary)

@jmcouffin
Copy link
Contributor Author

Great,
Care to make a draft PR so that we can test it ?

Parsing the pyrevit hosts file is a possibility, but we need to automate it's updating process. Adding versions is still a manual process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Enhancement request [class->Improved #{number}: {title}] Good First Issue Bug or feature with trivial solution that awaits you to be fixed! New Feature New feature request [class->Implemented #{number}: {title}]
Projects
Status: Later
Development

No branches or pull requests

2 participants