Skip to content

Commit e369cb3

Browse files
committed
Ported to Revit 2016
also, added backward compatibility for the "script" attribute in the "PushButton" tag for AddIn manifest files. But seriously, use "src" instead!
1 parent a6f84fe commit e369cb3

14 files changed

+154
-8
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6.02 MB
Binary file not shown.

PythonConsoleControl/PythonConsoleControl.csproj

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@
4545
<ErrorReport>prompt</ErrorReport>
4646
<WarningLevel>4</WarningLevel>
4747
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 2016|AnyCPU'">
49+
<DebugSymbols>true</DebugSymbols>
50+
<OutputPath>bin\Debug 2016\</OutputPath>
51+
<DefineConstants>DEBUG;TRACE</DefineConstants>
52+
<DebugType>full</DebugType>
53+
<PlatformTarget>AnyCPU</PlatformTarget>
54+
<ErrorReport>prompt</ErrorReport>
55+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
56+
</PropertyGroup>
4857
<ItemGroup>
4958
<Reference Include="ICSharpCode.AvalonEdit">
5059
<HintPath>RequiredLibraries\AvalonEdit\ICSharpCode.AvalonEdit.dll</HintPath>
25.3 MB
Binary file not shown.
2.41 MB
Binary file not shown.

RevitPythonShell.sln

+8
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,27 @@ Global
2222
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2323
Debug 2014|Any CPU = Debug 2014|Any CPU
2424
Debug 2015|Any CPU = Debug 2015|Any CPU
25+
Debug 2016|Any CPU = Debug 2016|Any CPU
2526
EndGlobalSection
2627
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2728
{7E37F14E-D840-42F8-8CA6-90FFC5497972}.Debug 2014|Any CPU.ActiveCfg = Debug 2014|Any CPU
2829
{7E37F14E-D840-42F8-8CA6-90FFC5497972}.Debug 2014|Any CPU.Build.0 = Debug 2014|Any CPU
2930
{7E37F14E-D840-42F8-8CA6-90FFC5497972}.Debug 2015|Any CPU.ActiveCfg = Debug 2015|Any CPU
3031
{7E37F14E-D840-42F8-8CA6-90FFC5497972}.Debug 2015|Any CPU.Build.0 = Debug 2015|Any CPU
32+
{7E37F14E-D840-42F8-8CA6-90FFC5497972}.Debug 2016|Any CPU.ActiveCfg = Debug 2016|Any CPU
33+
{7E37F14E-D840-42F8-8CA6-90FFC5497972}.Debug 2016|Any CPU.Build.0 = Debug 2016|Any CPU
3134
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Debug 2014|Any CPU.ActiveCfg = Debug|Any CPU
35+
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Debug 2014|Any CPU.Build.0 = Debug|Any CPU
3236
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Debug 2015|Any CPU.ActiveCfg = Debug|Any CPU
3337
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Debug 2015|Any CPU.Build.0 = Debug|Any CPU
38+
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Debug 2016|Any CPU.ActiveCfg = Debug|Any CPU
39+
{F1152D68-346B-4F48-8DB7-BE67B5CB1F49}.Debug 2016|Any CPU.Build.0 = Debug|Any CPU
3440
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Debug 2014|Any CPU.ActiveCfg = Debug 2014|Any CPU
3541
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Debug 2014|Any CPU.Build.0 = Debug 2014|Any CPU
3642
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Debug 2015|Any CPU.ActiveCfg = Debug 2015|Any CPU
3743
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Debug 2015|Any CPU.Build.0 = Debug 2015|Any CPU
44+
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Debug 2016|Any CPU.ActiveCfg = Debug 2016|Any CPU
45+
{C8446636-C663-409F-82D0-72C0D55BBA1C}.Debug 2016|Any CPU.Build.0 = Debug 2016|Any CPU
3846
EndGlobalSection
3947
GlobalSection(SolutionProperties) = preSolution
4048
HideSolutionNode = FALSE

RevitPythonShell/DeployRpsAddinCommand.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,21 @@ private void CreateAssembly()
188188

189189
foreach (var xmlPushButton in _doc.Descendants("PushButton"))
190190
{
191-
var scriptFile = GetRootedPath(
192-
_rootFolder, xmlPushButton.Attribute("src").Value); // e.g. "C:\projects\helloworld\helloworld.py" or "..\helloworld.py"
191+
string scriptFileName;
192+
if (xmlPushButton.Attribute("src") != null)
193+
{
194+
scriptFileName = xmlPushButton.Attribute("src").Value;
195+
}
196+
else if (xmlPushButton.Attribute("script") != null) // Backwards compatibility
197+
{
198+
scriptFileName = xmlPushButton.Attribute("script").Value;
199+
}
200+
else
201+
{
202+
throw new ApplicationException("<PushButton/> tag missing a src attribute in addin manifest");
203+
}
204+
205+
var scriptFile = GetRootedPath(_rootFolder, scriptFileName); // e.g. "C:\projects\helloworld\helloworld.py" or "..\helloworld.py"
193206
var newScriptFile = Path.GetFileName(scriptFile); // e.g. "helloworld.py" - strip path for embedded resource
194207
var className = "ec_" + Path.GetFileNameWithoutExtension(newScriptFile); // e.g. "ec_helloworld", "ec" stands for ExternalCommand
195208

RevitPythonShell/RevitPythonShell.csproj

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug 2015</Configuration>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug 2016</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
66
<ProductVersion>9.0.30729</ProductVersion>
77
<SchemaVersion>2.0</SchemaVersion>
@@ -45,6 +45,9 @@
4545
<PropertyGroup Condition="'$(Configuration)' == 'Debug 2015'">
4646
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
4747
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)' == 'Debug 2016'">
49+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
50+
</PropertyGroup>
4851
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
4952
<DebugSymbols>true</DebugSymbols>
5053
<DebugType>full</DebugType>
@@ -80,6 +83,15 @@
8083
<ErrorReport>prompt</ErrorReport>
8184
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
8285
</PropertyGroup>
86+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 2016|AnyCPU'">
87+
<DebugSymbols>true</DebugSymbols>
88+
<OutputPath>bin\Debug 2016\</OutputPath>
89+
<DefineConstants>DEBUG;TRACE</DefineConstants>
90+
<DebugType>full</DebugType>
91+
<PlatformTarget>AnyCPU</PlatformTarget>
92+
<ErrorReport>prompt</ErrorReport>
93+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
94+
</PropertyGroup>
8395
<ItemGroup Condition="'$(Configuration)' == 'Debug 2014'">
8496
<Reference Include="RevitAPI">
8597
<HintPath>..\RequiredLibraries\Revit2014\RevitAPI.dll</HintPath>
@@ -96,6 +108,14 @@
96108
<HintPath>..\RequiredLibraries\Revit2015\RevitAPIUI.dll</HintPath>
97109
</Reference>
98110
</ItemGroup>
111+
<ItemGroup Condition="'$(Configuration)' == 'Debug 2016'">
112+
<Reference Include="RevitAPI">
113+
<HintPath>..\RequiredLibraries\Revit2016\RevitAPI.dll</HintPath>
114+
</Reference>
115+
<Reference Include="RevitAPIUI">
116+
<HintPath>..\RequiredLibraries\Revit2016\RevitAPIUI.dll</HintPath>
117+
</Reference>
118+
</ItemGroup>
99119
<ItemGroup>
100120
<Reference Include="ICSharpCode.AvalonEdit, Version=4.0.0.5949, Culture=neutral, PublicKeyToken=9cc39be672370310, processorArchitecture=MSIL">
101121
<HintPath>..\PythonConsoleControl\RequiredLibraries\AvalonEdit\ICSharpCode.AvalonEdit.dll</HintPath>
@@ -252,4 +272,4 @@
252272
<Target Name="AfterBuild">
253273
</Target>
254274
-->
255-
</Project>
275+
</Project>

RevitPythonShell/init.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,40 @@
66

77
uidoc = __revit__.ActiveUIDocument
88
doc = __revit__.ActiveUIDocument.Document
9-
selection = list(__revit__.ActiveUIDocument.Selection.Elements)
109

1110
from Autodesk.Revit.UI import TaskDialog
1211
from Autodesk.Revit.UI import UIApplication
12+
13+
1314
def alert(msg):
1415
TaskDialog.Show('RevitPythonShell', msg)
1516

17+
1618
def quit():
1719
__window__.Close()
1820
exit = quit
1921

22+
23+
def get_selected_elements(doc):
24+
"""API change in Revit 2016 makes old method throw an error"""
25+
try:
26+
# Revit 2016
27+
return [doc.GetElement(id)
28+
for id in __revit__.ActiveUIDocument.Selection.GetElementIds()]
29+
except:
30+
# old method
31+
return list(__revit__.ActiveUIDocument.Selection.Elements)
32+
selection = get_selected_elements(doc)
33+
34+
2035
# a fix for the __window__.Close() bug introduced with the non-modal console
2136
class WindowWrapper(object):
2237
def __init__(self, win):
2338
self.win = win
39+
2440
def Close(self):
2541
self.win.Dispatcher.Invoke(lambda *_: self.win.Close())
42+
2643
def __getattr__(self, name):
2744
return getattr(self.win, name)
28-
__window__ = WindowWrapper(__window__)
45+
__window__ = WindowWrapper(__window__)

RpsRuntime/RpsRuntime.csproj

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug 2015</Configuration>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug 2016</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
66
<ProductVersion>8.0.30703</ProductVersion>
77
<SchemaVersion>2.0</SchemaVersion>
@@ -24,6 +24,9 @@
2424
<PropertyGroup Condition="'$(Configuration)' == 'Debug 2015'">
2525
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
2626
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)' == 'Debug 2016'">
28+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
29+
</PropertyGroup>
2730
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2831
<DebugSymbols>true</DebugSymbols>
2932
<DebugType>full</DebugType>
@@ -59,6 +62,15 @@
5962
<ErrorReport>prompt</ErrorReport>
6063
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
6164
</PropertyGroup>
65+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 2016|AnyCPU'">
66+
<DebugSymbols>true</DebugSymbols>
67+
<OutputPath>bin\Debug 2016\</OutputPath>
68+
<DefineConstants>DEBUG;TRACE</DefineConstants>
69+
<DebugType>full</DebugType>
70+
<PlatformTarget>AnyCPU</PlatformTarget>
71+
<ErrorReport>prompt</ErrorReport>
72+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
73+
</PropertyGroup>
6274
<ItemGroup Condition="'$(Configuration)' == 'Debug 2014'">
6375
<Reference Include="RevitAPI">
6476
<HintPath>..\RequiredLibraries\Revit2014\RevitAPI.dll</HintPath>
@@ -75,6 +87,14 @@
7587
<HintPath>..\RequiredLibraries\Revit2015\RevitAPIUI.dll</HintPath>
7688
</Reference>
7789
</ItemGroup>
90+
<ItemGroup Condition="'$(Configuration)' == 'Debug 2016'">
91+
<Reference Include="RevitAPI">
92+
<HintPath>..\RequiredLibraries\Revit2016\RevitAPI.dll</HintPath>
93+
</Reference>
94+
<Reference Include="RevitAPIUI">
95+
<HintPath>..\RequiredLibraries\Revit2016\RevitAPIUI.dll</HintPath>
96+
</Reference>
97+
</ItemGroup>
7898
<ItemGroup>
7999
<Reference Include="IronPython, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
80100
<HintPath>..\RequiredLibraries\IronPython.dll</HintPath>
@@ -142,4 +162,4 @@
142162
<Target Name="AfterBuild">
143163
</Target>
144164
-->
145-
</Project>
165+
</Project>

Setup_RevitPythonShell_2016.iss

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[Files]
2+
Source: "RevitPythonShell\bin\Debug 2016\PythonConsoleControl.dll"; DestDir: "{app}"; Flags: replacesameversion
3+
Source: "RevitPythonShell\bin\Debug 2016\RevitPythonShell.dll"; DestDir: "{app}"; Flags: replacesameversion
4+
Source: "RevitPythonShell\bin\Debug 2016\RpsRuntime.dll"; DestDir: "{app}"; Flags: replacesameversion
5+
Source: "RequiredLibraries\ICSharpCode.AvalonEdit.dll"; DestDir: "{app}"
6+
Source: "RequiredLibraries\IronPython.dll"; DestDir: "{app}"
7+
Source: "RequiredLibraries\IronPython.Modules.dll"; DestDir: "{app}"
8+
Source: "RequiredLibraries\Microsoft.Scripting.Metadata.dll"; DestDir: "{app}"
9+
Source: "RequiredLibraries\Microsoft.Dynamic.dll"; DestDir: "{app}"
10+
Source: "RequiredLibraries\Microsoft.Scripting.dll"; DestDir: "{app}"
11+
Source: "RevitPythonShell\RevitPythonShell.xml"; DestDir: "{userappdata}\RevitPythonShell2016"; Flags: onlyifdoesntexist
12+
Source: "RevitPythonShell\init.py"; DestDir: "{userappdata}\RevitPythonShell2016"; Flags: onlyifdoesntexist
13+
Source: "RevitPythonShell\startup.py"; DestDir: "{userappdata}\RevitPythonShell2016"; Flags: onlyifdoesntexist
14+
15+
[code]
16+
{ HANDLE INSTALL PROCESS STEPS }
17+
procedure CurStepChanged(CurStep: TSetupStep);
18+
var
19+
AddInFilePath: String;
20+
AddInFileContents: String;
21+
begin
22+
23+
if CurStep = ssPostInstall then
24+
begin
25+
26+
{ GET LOCATION OF USER AppData (Roaming) }
27+
AddInFilePath := ExpandConstant('{userappdata}\Autodesk\Revit\Addins\2016\RevitPythonShell2016.addin');
28+
29+
{ CREATE NEW ADDIN FILE }
30+
AddInFileContents := '<?xml version="1.0" encoding="utf-16" standalone="no"?>' + #13#10;
31+
AddInFileContents := AddInFileContents + '<RevitAddIns>' + #13#10;
32+
AddInFileContents := AddInFileContents + ' <AddIn Type="Application">' + #13#10;
33+
AddInFileContents := AddInFileContents + ' <Name>RevitPythonShell</Name>' + #13#10;
34+
AddInFileContents := AddInFileContents + ' <Assembly>' + ExpandConstant('{app}') + '\RevitPythonShell.dll</Assembly>' + #13#10;
35+
AddInFileContents := AddInFileContents + ' <AddInId>3a7a1d24-51ed-462b-949f-1ddcca12008d</AddInId>' + #13#10;
36+
AddInFileContents := AddInFileContents + ' <FullClassName>RevitPythonShell.RevitPythonShellApplication</FullClassName>' + #13#10;
37+
AddInFileContents := AddInFileContents + ' <VendorId>RIPS</VendorId>' + #13#10;
38+
AddInFileContents := AddInFileContents + ' </AddIn>' + #13#10;
39+
AddInFileContents := AddInFileContents + '</RevitAddIns>' + #13#10;
40+
SaveStringToFile(AddInFilePath, AddInFileContents, False);
41+
42+
end;
43+
end;
44+
45+
46+
[Setup]
47+
AppName=RevitPythonShell for Autodesk Revit 2016
48+
AppVerName=RevitPythonShell for Autodesk Revit 2016
49+
RestartIfNeededByRun=false
50+
DefaultDirName={pf32}\RevitPythonShell2016
51+
OutputBaseFilename=Setup_RevitPythonShell_2016
52+
ShowLanguageDialog=auto
53+
FlatComponentsList=false
54+
UninstallFilesDir={app}\Uninstall
55+
UninstallDisplayName=RevitPythonShell for Autodesk Revit 2016
56+
AppVersion=2016.0
57+
VersionInfoVersion=2016.0
58+
VersionInfoDescription=RevitPythonShell for Autodesk Revit 2016
59+
VersionInfoTextVersion=RevitPythonShell for Autodesk Revit 2016

0 commit comments

Comments
 (0)