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
Register Dockable Panel at Startup #1184
Comments
Check this out. I just added an example to the pyRevitDev extension from pyrevit.framework import Windows
from pyrevit.framework import wpf
from pyrevit.coreutils import Guid
class DockableExample (Windows.Controls.Page):
def __init__(self, xaml_file):
wpf.LoadComponent(self, op.join(op.dirname(__file__), xaml_file))
def do_something(self, sender, args):
forms.alert("DockableExample Action")
class DockableExamplePanelProvider (UI.IDockablePaneProvider):
def SetupDockablePane(self, data):
# https://apidocs.co/apps/revit/2021.1/cde36571-ccf1-f628-9e34-6a720388d348.htm
data.FrameworkElement = DockableExample("DockableExample.xaml")
data.VisibleByDefault = True
DOCKABLE_PANE_ID = UI.DockablePaneId(Guid.NewGuid())
HOST_APP.uiapp.RegisterDockablePane(
DOCKABLE_PANE_ID,
"pyRevit Dockable Panel Example",
DockableExamplePanelProvider()
) <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="White">
<StackPanel Margin="20">
<TextBlock Text="pyRevit Dockable Panel Example" />
<Button Content="Do Something" Click="do_something" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="50" Margin="0,10,0,0"/>
</StackPanel>
</Page> It will create a panel like this |
Thanks Ehsan. I already have my dockable panel and logic and it's all in C#. Any examples? Even better if it creates types from DLLs in the lib folder |
You should be able to import the dotnet dll using class DockableExamplePanelProvider (UI.IDockablePaneProvider):
def SetupDockablePane(self, data):
data.FrameworkElement = YourImportedDockableType()
data.VisibleByDefault = True
DOCKABLE_PANE_ID = UI.DockablePaneId(Guid.NewGuid())
HOST_APP.uiapp.RegisterDockablePane(
DOCKABLE_PANE_ID,
"pyRevit Dockable Panel Example",
DockableExamplePanelProvider()
) |
What I'm not following is your question about C#. If that's the case why are you using pyRevit? Just register the panel in your C# addon startup. It's the same mechanism shown above in python |
Yeah sorry fair question. My bad in poorly explaining my issue. The reason is that my application is all in C# and I use pyRevit to host/run it (it is part of a bigger set of tools all in pyRevit, but it is fairly more complex than the rest). So this is exactly the reason. If I load the dockable panel through pyRevit, in its startup script, Revit is not blocking any dll so I can freely work on the the code and just have the users to click the update button when I make changes. I hope it's a bit clearer now? |
I think so. Have you tried using |
Yeah I did and it works in python but if I do a Could it be because the dll is not in the lib folder but one of its subfolders? |
Oh yeah it needs to be inside the |
Still doesn't work for some reason. No idea why |
Do you want to send me something to test? You can send to my gmail |
Mate if you're happy to do that it would be amazing! I'll send it through now |
@eirannejad |
@BIMONE-OUTILS So this is part of pyRevitdev extension which is not installed by default. You'd need a full clone of pyRevit git repo and attach that to Revit. See this for a bit more info on how to clone |
Is there a way to run an OnStartup method (inside a IExternalApplication class) when Revit is starting up, through pyRevit?
I am trying to register a Dockable Panel, but because this happens on startup and pyRevit only runs commands I'm struggling to understand how to do it.
In a standalone C# application (without pyRevit) I would do something like this:
I have read about startup.* scripts that you can have at .extension level, but there aren't many examples in C# so I'm not being successful at using it.
(Biggest problem while I try this is that pyRevit doesn't find the type MyDockablePanel even though it is in one of the dlls in a subfolder of the lib folder)
I've also seen this issue here #1027 so I'd be curious to see how they did that.
Any help? :)
The text was updated successfully, but these errors were encountered: