Hey,
I created a dockable panel and the basics work just fine.
When i select an element in revit i get a message with the name of the selected element ( Trigger_ElementSelection).
when i click the button next (With the element still selected) it puts out message [5] just as the base value of CurrentSelection is. (ButtonClicked_1)
How can i update a var inside a definition?
import System
import os.path as op
from pyrevit import HOST_APP, framework, coreutils, PyRevitException
from pyrevit import revit, DB, UI
from pyrevit import forms, script
from pyrevit.framework import wpf, ObservableCollection
from System.Windows.Media import Brushes
import subprocess
import sys
import os
def MM_to_FEET(a):
return a * 0.00328084
class _WPFPanelProvider(UI.IDockablePaneProvider):
def __init__(self, panel_type, default_visible=True):
self._panel_type = panel_type
self._default_visible = default_visible
self.panel = self._panel_type()
def SetupDockablePane(self, data):
data.FrameworkElement = self.panel
data.VisibleByDefault = self._default_visible
def register_dockable_panel(panel_type, default_visible=True):
if not issubclass(panel_type, forms.WPFPanel):
raise PyRevitException(
"Dockable pane must be a subclass of forms.WPFPanel"
)
panel_uuid = coreutils.Guid.Parse(panel_type.panel_id)
dockable_panel_id = UI.DockablePaneId(panel_uuid)
panel_provider = _WPFPanelProvider(panel_type, default_visible)
HOST_APP.uiapp.RegisterDockablePane(
dockable_panel_id,
panel_type.panel_title,
panel_provider
)
return panel_provider.panel
class DockableExample(forms.WPFPanel):
panel_source = op.join(op.dirname(__file__), "MainWindow.xaml")
panel_title = "Dockable Pane Sample"
panel_id = "3110e336-f81c-4927-87da-4e0d30d4d64a"
BaseDockablePanelsPath = "L:/REVIT/PyRevit/DockablePanels/"
DockablePanelName = "PanelOne/"
BasePath = BaseDockablePanelsPath + DockablePanelName
def __init__(self):
super(DockableExample, self).__init__()
self.CurrentSelection = [5]
def ExecuteScript(self, ScriptName, DefName):
with open(self.BasePath + ScriptName, 'r') as file:
code = file.read()
context = {}
exec(code, context)
return context.get(DefName)
def Trigger_ElementSelection(self, sender, args):
self.CurrentSelection = (self.ExecuteScript("GetCurrentSelection.py", "CurrentSelection_FamilyInstance"))()
print(self.CurrentSelection)
def ButtonClicked_1(self, sender, args):
print(self.CurrentSelection)
#if not self.CurrentSelection == []:
# print(self.ExecuteScript("GetParameterValue.py", "GetParameterValueByName"))#(self.CurrentSelection, "Annotation Offset RL")
# #(self.ExecuteScript("SetParameterValue.py", "SetParameterValueByName"))(self.CurrentSelection, "Annotation Offset RL", MM_to_FEET(+1.5))
#forms.alert("3")
registered_panel = register_dockable_panel(DockableExample)
dockable_example_instance = DockableExample() # Instantiate DockableExample
HOST_APP.uiapp.SelectionChanged += dockable_example_instance.Trigger_ElementSelection # Add event handler