Skip to content

Commit

Permalink
Merge pull request #137 from architecture-building-systems/develop
Browse files Browse the repository at this point in the history
Puhblish New Version For IronPython3.4
  • Loading branch information
daren-thomas authored Jan 6, 2023
2 parents eecc688 + ad777c2 commit 86bb941
Show file tree
Hide file tree
Showing 22 changed files with 120 additions and 62 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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**
Expand Down
2 changes: 1 addition & 1 deletion Installer/Installer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Installer/Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WixSharp.bin">
<Version>1.19.*</Version>
<Version>1.20.2</Version>
</PackageReference>
<PackageReference Include="WixSharp.wix.bin">
<Version>3.11.*</Version>
<Version>3.11.2</Version>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected void PopulateFromPythonType(List<PythonCompletionData> 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;

Expand Down
1 change: 1 addition & 0 deletions PythonConsoleControl/PythonConsoleControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.0.1" />
<PackageReference Include="IronPython" Version="3.4.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="IronPython">
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
Binary file removed RequiredLibraries/IronPython.Modules.dll
Binary file not shown.
Binary file removed RequiredLibraries/IronPython.SQLite.dll
Binary file not shown.
Binary file removed RequiredLibraries/IronPython.Wpf.dll
Binary file not shown.
Binary file removed RequiredLibraries/IronPython.dll
Binary file not shown.
Binary file removed RequiredLibraries/Microsoft.CSharp.dll
Binary file not shown.
Binary file removed RequiredLibraries/Microsoft.Dynamic.dll
Binary file not shown.
Binary file removed RequiredLibraries/Microsoft.Scripting.AspNet.dll
Binary file not shown.
Binary file removed RequiredLibraries/Microsoft.Scripting.Metadata.dll
Binary file not shown.
Binary file removed RequiredLibraries/Microsoft.Scripting.dll
Binary file not shown.
Binary file not shown.
Binary file removed RequiredLibraries/WPG.dll
Binary file not shown.
88 changes: 64 additions & 24 deletions RevitPythonShell/DefaultConfig/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -51,43 +53,81 @@ 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
# tell IronPython about the assembly of the RevitLookup plugin
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()


# ------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion RevitPythonShell/Examples/helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
helloworld.py - example RevitPythonShell script
for testing the DeployRpsAddin program.
'''
print 'hello, world :)'
print("Hello World!")
Binary file added RpsRuntime/Resources/IronPython.3.4.0.zip
Binary file not shown.
65 changes: 35 additions & 30 deletions RpsRuntime/RpsRuntime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore"/>
<Reference Include="PresentationFramework"/>
<Reference Include="WindowsBase"/>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nice3point.Revit.Api.RevitAPI" Version="$(RevitVersion).*"/>
<PackageReference Include="Nice3point.Revit.Api.RevitAPIUI" Version="$(RevitVersion).*"/>
<PackageReference Include="AvalonEdit" Version="6.0.1"/>
<PackageReference Include="DynamicLanguageRuntime" Version="1.3.3" />
<PackageReference Include="IronPython" Version="3.4.0" />
<PackageReference Include="Nice3point.Revit.Api.RevitAPI" Version="$(RevitVersion).*" />
<PackageReference Include="Nice3point.Revit.Api.RevitAPIUI" Version="$(RevitVersion).*" />
<PackageReference Include="AvalonEdit" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="IronPython">
Expand All @@ -82,34 +84,34 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore"/>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Drawing"/>
<Reference Include="System.Windows.Forms"/>
<Reference Include="System.Xaml"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>
<Reference Include="System.Data"/>
<Reference Include="System.Xml"/>
<Reference Include="WindowsBase"/>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExternalCommandAssemblyBuilder.cs"/>
<Compile Include="IRpsConfig.cs"/>
<Compile Include="RpsConfig.cs"/>
<Compile Include="RpsExternalApplicationBase.cs"/>
<Compile Include="RpsExternalCommandBase.cs"/>
<Compile Include="RpsExternalCommandScriptBase.cs"/>
<Compile Include="ScriptExecutor.cs"/>
<Compile Include="ExternalCommandAssemblyBuilder.cs" />
<Compile Include="IRpsConfig.cs" />
<Compile Include="RpsConfig.cs" />
<Compile Include="RpsExternalApplicationBase.cs" />
<Compile Include="RpsExternalCommandBase.cs" />
<Compile Include="RpsExternalCommandScriptBase.cs" />
<Compile Include="ScriptExecutor.cs" />
<Compile Include="ScriptOutput.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ScriptOutput.Designer.cs">
<DependentUpon>ScriptOutput.cs</DependentUpon>
</Compile>
<Compile Include="ScriptOutputStream.cs"/>
<Compile Include="SettingsDictionary.cs"/>
<Compile Include="ScriptOutputStream.cs" />
<Compile Include="SettingsDictionary.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ScriptOutput.resx">
Expand All @@ -118,15 +120,18 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\PythonScript16x16.png"/>
<EmbeddedResource Include="Resources\PythonScript16x16.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\PythonScript32x32.png"/>
<EmbeddedResource Include="Resources\PythonScript32x32.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\python_27_lib.zip"/>
<EmbeddedResource Include="Resources\python_27_lib.zip" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\"/>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\IronPython.3.4.0.zip" />
</ItemGroup>
</Project>
5 changes: 3 additions & 2 deletions RpsRuntime/ScriptExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 86bb941

Please sign in to comment.