diff --git a/CHANGELOG.md b/CHANGELOG.md index 3543d87..d1e55c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +- 2022-12-16 **2.0.0** + - Add support IronPython 3.4 [#136](https://github.com/architecture-building-systems/revitpythonshell/pull/136) + - Please follow [Upgrade from IronPython2 to IronPython 3](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/upgrading-from-ipy2.md) to upgrade your code. - 2022-09-22 **1.0.2** - Fix set CollectorExt.m_app error. [#128](https://github.com/architecture-building-systems/revitpythonshell/pull/128) - 2022-06-27 **1.0.1** diff --git a/Installer/Installer.cs b/Installer/Installer.cs index 8816425..bdc323a 100644 --- a/Installer/Installer.cs +++ b/Installer/Installer.cs @@ -12,7 +12,7 @@ const string projectName = "RevitPythonShell"; const string outputName = "RevitPythonShell"; const string outputDir = "output"; -const string version = "1.0.2"; +const string version = "2.0.0"; var fileName = new StringBuilder().Append(outputName).Append("-").Append(version); var project = new Project diff --git a/Installer/Installer.csproj b/Installer/Installer.csproj index 73fc313..e229580 100644 --- a/Installer/Installer.csproj +++ b/Installer/Installer.csproj @@ -12,10 +12,10 @@ - 1.19.* + 1.20.2 - 3.11.* + 3.11.2 diff --git a/PythonConsoleControl/PythonConsoleCompletionDataProvider.cs b/PythonConsoleControl/PythonConsoleCompletionDataProvider.cs index e6c6262..af16688 100644 --- a/PythonConsoleControl/PythonConsoleCompletionDataProvider.cs +++ b/PythonConsoleControl/PythonConsoleCompletionDataProvider.cs @@ -157,7 +157,7 @@ protected void PopulateFromPythonType(List items, string n //string dirCommand = "dir(" + objectName + ")"; string dirCommand = "sorted([m for m in dir(" + name + ") if not m.startswith('__')], key = str.lower) + sorted([m for m in dir(" + name + ") if m.startswith('__')])"; object value = commandLine.ScriptScope.Engine.CreateScriptSourceFromString(dirCommand, SourceCodeKind.Expression).Execute(commandLine.ScriptScope); - foreach (object member in (value as IronPython.Runtime.List)) + foreach (object member in (value as IronPython.Runtime.PythonList)) { bool isInstance = false; diff --git a/PythonConsoleControl/PythonConsoleControl.csproj b/PythonConsoleControl/PythonConsoleControl.csproj index 6fefb45..36113c7 100644 --- a/PythonConsoleControl/PythonConsoleControl.csproj +++ b/PythonConsoleControl/PythonConsoleControl.csproj @@ -14,6 +14,7 @@ + diff --git a/README.md b/README.md index d2c1c53..c7102ab 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,14 @@ database exploration tool to become a Revit API Ninja :) - `lookup()` function for snooping `Element`, `ElementSet` and `ElementId` objects in [RevitLookup](https://github.com/jeremytammik/RevitLookup) +## IronPython 3 + +IronPython 3.4 uses Python 3.4 syntax and standard libraries and so your Python code will need to be updated accordingly. There are numerous tools and guides available on the web to help porting from Python 2 to 3. + +IronPython 3 targets Python 3, including the re-organized standard library, Unicode strings, and all of the other new features.with user upgrade from **IronPython 2** to **IronPython 3**, please follow [Upgrade from IronPython 2 to IronPython 3](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/upgrading-from-ipy2.md). + +Various differences between IronPython and CPython can follow at [Differences IronPython and CPython](https://github.com/IronLanguages/ironpython3/blob/master/Documentation/differences-from-c-python.md). + ## Installation Please follow last release at section [Release](https://github.com/architecture-building-systems/revitpythonshell/releases/latest) support version Support From Revit 2018-2023. @@ -69,7 +77,7 @@ Learn some python: Learn about the Revit API: -* [Autodesk Developer Network](T) +* [Autodesk Developer Network](https://www.autodesk.com/developer-network/open) * [Jeremy Tammiks blog "The Building Coder"](http://thebuildingcoder.typepad.com/) Tutorials recommended by the community: diff --git a/RequiredLibraries/IronPython.Modules.dll b/RequiredLibraries/IronPython.Modules.dll deleted file mode 100644 index f9ae5c2..0000000 Binary files a/RequiredLibraries/IronPython.Modules.dll and /dev/null differ diff --git a/RequiredLibraries/IronPython.SQLite.dll b/RequiredLibraries/IronPython.SQLite.dll deleted file mode 100644 index 3b46157..0000000 Binary files a/RequiredLibraries/IronPython.SQLite.dll and /dev/null differ diff --git a/RequiredLibraries/IronPython.Wpf.dll b/RequiredLibraries/IronPython.Wpf.dll deleted file mode 100644 index 8399ec3..0000000 Binary files a/RequiredLibraries/IronPython.Wpf.dll and /dev/null differ diff --git a/RequiredLibraries/IronPython.dll b/RequiredLibraries/IronPython.dll deleted file mode 100644 index 3a7e463..0000000 Binary files a/RequiredLibraries/IronPython.dll and /dev/null differ diff --git a/RequiredLibraries/Microsoft.CSharp.dll b/RequiredLibraries/Microsoft.CSharp.dll deleted file mode 100644 index f11e2a9..0000000 Binary files a/RequiredLibraries/Microsoft.CSharp.dll and /dev/null differ diff --git a/RequiredLibraries/Microsoft.Dynamic.dll b/RequiredLibraries/Microsoft.Dynamic.dll deleted file mode 100644 index 0d7e6a7..0000000 Binary files a/RequiredLibraries/Microsoft.Dynamic.dll and /dev/null differ diff --git a/RequiredLibraries/Microsoft.Scripting.AspNet.dll b/RequiredLibraries/Microsoft.Scripting.AspNet.dll deleted file mode 100644 index ecbec45..0000000 Binary files a/RequiredLibraries/Microsoft.Scripting.AspNet.dll and /dev/null differ diff --git a/RequiredLibraries/Microsoft.Scripting.Metadata.dll b/RequiredLibraries/Microsoft.Scripting.Metadata.dll deleted file mode 100644 index c3cda22..0000000 Binary files a/RequiredLibraries/Microsoft.Scripting.Metadata.dll and /dev/null differ diff --git a/RequiredLibraries/Microsoft.Scripting.dll b/RequiredLibraries/Microsoft.Scripting.dll deleted file mode 100644 index 3f0771a..0000000 Binary files a/RequiredLibraries/Microsoft.Scripting.dll and /dev/null differ diff --git a/RequiredLibraries/System.Windows.Controls.WpfPropertyGrid.dll b/RequiredLibraries/System.Windows.Controls.WpfPropertyGrid.dll deleted file mode 100644 index 8d9f2d1..0000000 Binary files a/RequiredLibraries/System.Windows.Controls.WpfPropertyGrid.dll and /dev/null differ diff --git a/RequiredLibraries/WPG.dll b/RequiredLibraries/WPG.dll deleted file mode 100644 index ea4623a..0000000 Binary files a/RequiredLibraries/WPG.dll and /dev/null differ diff --git a/RevitPythonShell/DefaultConfig/init.py b/RevitPythonShell/DefaultConfig/init.py index ee7181f..27ac2b9 100644 --- a/RevitPythonShell/DefaultConfig/init.py +++ b/RevitPythonShell/DefaultConfig/init.py @@ -17,10 +17,12 @@ def alert(msg): def quit(): __window__.Close() + + exit = quit -def get_selected_elements(doc): +def GetSelectedElements(doc): """API change in Revit 2016 makes old method throw an error""" try: # Revit 2016 @@ -31,7 +33,7 @@ def get_selected_elements(doc): return list(__revit__.ActiveUIDocument.Selection.Elements) -selection = get_selected_elements(doc) +selection = GetSelectedElements(doc) # convenience variable for first element in selection if len(selection): s0 = selection[0] @@ -51,7 +53,7 @@ def __init__(self, uiApplication): try: rlapp = [app for app in uiApplication.LoadedApplications if app.GetType().Namespace == 'RevitLookup' - and app.GetType().Name == 'App'][0] + and app.GetType().Name == 'Application'][0] except IndexError: self.RevitLookup = None return @@ -59,35 +61,73 @@ def __init__(self, uiApplication): clr.AddReference(rlapp.GetType().Assembly) import RevitLookup self.RevitLookup = RevitLookup - # See note in CollectorExt.cs in the RevitLookup source: - try: - self.RevitLookup.Snoop.CollectorExts.CollectorExt.m_app = uiApplication - except TypeError: # assigning m_app is now not required and even not possible - pass - self.revit = uiApplication - def lookup(self, element): + def IsInstalled(self): if not self.RevitLookup: print('RevitLookup not installed. Visit https://github.com/jeremytammik/RevitLookup to install.') - return - if isinstance(element, int): - element = self.revit.ActiveUIDocument.Document.GetElement(ElementId(element)) - if isinstance(element, ElementId): - element = self.revit.ActiveUIDocument.Document.GetElement(element) - if isinstance(element, list): - elementSet = ElementSet() - for e in element: - elementSet.Insert(e) - element = elementSet - form = self.RevitLookup.Snoop.Forms.Objects(element) - form.ShowDialog() + return False + return True + + def SnoopCurrentSelection(self): + if self.IsInstalled(): + form = self.RevitLookup.Views.ObjectsView() + form.SnoopAndShow(self.RevitLookup.Core.Selector.SnoopCurrentSelection) + + def SnoopElement(self,element): + if self.IsInstalled(): + if element is None: + print("element null object, Please input element to snoop") + return + if isinstance(element, int): + element = doc.GetElement(ElementId(element)) + if isinstance(element, ElementId): + element = doc.GetElement(element) + if isinstance(element, list): + elementSet = ElementSet() + for e in element: + elementSet.Insert(e) + form = self.RevitLookup.Views.ObjectsView(elementSet) + self.RevitLookup.Core.ModelessWindowFactory.Show(form) + pass + form = self.RevitLookup.Views.ObjectsView(element) + self.RevitLookup.Core.ModelessWindowFactory.Show(form) + + def SnoopActiveView(): + if self.IsInstalled(): + self.SnoopElement(doc.ActiveView) + + def SnoopDb(self): + if self.IsInstalled(): + form = self.RevitLookup.Views.ObjectsView() + form.SnoopAndShow(self.RevitLookup.Core.Selector.SnoopDb) _revitlookup = RevitLookup(__revit__) -def lookup(element): - _revitlookup.lookup(element) +def SnoopCurrentSelection(): + _revitlookup.SnoopCurrentSelection() + + +''' +## Example : +## _revitlookup.SnoopElement(doc.ActiveView) +## _revitlookup.SnoopElement(959510) +## _revitlookup.SnoopElement(doc.ActiveView.Id) +''' + + +def SnoopElement(element): + _revitlookup.SnoopElement(element) + + +def SnoopActiveView(): + _revitlookup.SnoopActiveView() + + +def SnoopDb(): + _revitlookup.SnoopDb() + # ------------------------------------------------------------------------------ diff --git a/RevitPythonShell/Examples/helloworld.py b/RevitPythonShell/Examples/helloworld.py index 8d2f226..b3a0653 100644 --- a/RevitPythonShell/Examples/helloworld.py +++ b/RevitPythonShell/Examples/helloworld.py @@ -2,4 +2,4 @@ helloworld.py - example RevitPythonShell script for testing the DeployRpsAddin program. ''' -print 'hello, world :)' \ No newline at end of file +print("Hello World!") \ No newline at end of file diff --git a/RpsRuntime/Resources/IronPython.3.4.0.zip b/RpsRuntime/Resources/IronPython.3.4.0.zip new file mode 100644 index 0000000..75452e6 Binary files /dev/null and b/RpsRuntime/Resources/IronPython.3.4.0.zip differ diff --git a/RpsRuntime/RpsRuntime.csproj b/RpsRuntime/RpsRuntime.csproj index 40ea59f..8d8950d 100644 --- a/RpsRuntime/RpsRuntime.csproj +++ b/RpsRuntime/RpsRuntime.csproj @@ -52,14 +52,16 @@ true - - - + + + - - - + + + + + @@ -82,34 +84,34 @@ - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + + Form ScriptOutput.cs - - + + @@ -118,15 +120,18 @@ - + - + - + - + + + + \ No newline at end of file diff --git a/RpsRuntime/ScriptExecutor.cs b/RpsRuntime/ScriptExecutor.cs index d39a76c..70706c0 100644 --- a/RpsRuntime/ScriptExecutor.cs +++ b/RpsRuntime/ScriptExecutor.cs @@ -131,8 +131,9 @@ private void AddEmbeddedLib(ScriptEngine engine) { // use embedded python lib var asm = this.GetType().Assembly; - var resQuery = from name in asm.GetManifestResourceNames() - where name.ToLowerInvariant().EndsWith("python_27_lib.zip") + string[] resourceNames = asm.GetManifestResourceNames(); + var resQuery = from name in resourceNames + where name.ToLowerInvariant().EndsWith("ironpython.3.4.0.zip") select name; var resName = resQuery.Single(); var importer = new IronPython.Modules.ResourceMetaPathImporter(asm, resName);