Skip to content

Commit

Permalink
fix not copy config solution
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Jun 27, 2022
1 parent d0d4f53 commit 53f5312
Show file tree
Hide file tree
Showing 8 changed files with 743 additions and 717 deletions.
1,237 changes: 619 additions & 618 deletions ...ythonShell/RevitPythonShellApplication.cs → RevitPythonShell/App.cs

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions RevitPythonShell/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
"Revit 2021": {
"commandName": "Executable",
"executablePath": "%ProgramW6432%\\Autodesk\\Revit 2021\\Revit.exe"
} ,
"Revit 2022": {
"commandName": "Executable",
"executablePath": "%ProgramW6432%\\Autodesk\\Revit 2022\\Revit.exe"
} ,
"Revit 2023": {
"commandName": "Executable",
"executablePath": "%ProgramW6432%\\Autodesk\\Revit 2023\\Revit.exe"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,63 @@
using System;
using System.IO;
using Autodesk.Revit;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using RpsRuntime;

namespace RevitPythonShell
{
/// <summary>
/// Starts up a ScriptOutput window for a given canned command.
///
/// It is expected that this will be inherited by dynamic types that have the field
/// _scriptSource set to point to a python file that will be executed in the constructor.
/// </summary>
[Regeneration(RegenerationOption.Manual)]
[Transaction(TransactionMode.Manual)]
public abstract class CommandLoaderBase : IExternalCommand
{
protected string _scriptSource = "";

public CommandLoaderBase(string scriptSource)
{
_scriptSource = scriptSource;
}

/// <summary>
/// Overload this method to implement an external command within Revit.
/// </summary>
/// <returns>
/// The result indicates if the execution fails, succeeds, or was canceled by user. If it does not
/// succeed, Revit will undo any changes made by the external command.
/// </returns>
/// <param name="commandData">An ExternalCommandData object which contains reference to Application and View
/// needed by external command.</param><param name="message">Error message can be returned by external command. This will be displayed only if the command status
/// was "Failed". There is a limit of 1023 characters for this message; strings longer than this will be truncated.</param><param name="elements">Element set indicating problem elements to display in the failure dialog. This will be used
/// only if the command status was "Failed".</param>
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// FIXME: somehow fetch back message after script execution...
var executor = new ScriptExecutor(RevitPythonShellApplication.GetConfig(), commandData, message, elements);

string source;
using (var reader = File.OpenText(_scriptSource))
{
source = reader.ReadToEnd();
}

var result = executor.ExecuteScript(source, _scriptSource);
message = executor.Message;
switch (result)
{
case (int)Result.Succeeded:
return Result.Succeeded;
case (int)Result.Cancelled:
return Result.Cancelled;
case (int)Result.Failed:
return Result.Failed;
default:
return Result.Succeeded;
}
}
}
}
using System.IO;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using RpsRuntime;

namespace RevitPythonShell.RevitCommands
{
/// <summary>
/// Starts up a ScriptOutput window for a given canned command.
///
/// It is expected that this will be inherited by dynamic types that have the field
/// _scriptSource set to point to a python file that will be executed in the constructor.
/// </summary>
[Regeneration(RegenerationOption.Manual)]
[Transaction(TransactionMode.Manual)]
public abstract class CommandLoaderBase : IExternalCommand
{
protected string _scriptSource = "";

public CommandLoaderBase(string scriptSource)
{
_scriptSource = scriptSource;
}

/// <summary>
/// Overload this method to implement an external command within Revit.
/// </summary>
/// <returns>
/// The result indicates if the execution fails, succeeds, or was canceled by user. If it does not
/// succeed, Revit will undo any changes made by the external command.
/// </returns>
/// <param name="commandData">An ExternalCommandData object which contains reference to Application and View
/// needed by external command.</param><param name="message">Error message can be returned by external command. This will be displayed only if the command status
/// was "Failed". There is a limit of 1023 characters for this message; strings longer than this will be truncated.</param><param name="elements">Element set indicating problem elements to display in the failure dialog. This will be used
/// only if the command status was "Failed".</param>
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
// FIXME: somehow fetch back message after script execution...
var executor = new ScriptExecutor(App.GetConfig(), commandData, message, elements);

string source;
using (var reader = File.OpenText(_scriptSource))
{
source = reader.ReadToEnd();
}

var result = executor.ExecuteScript(source, _scriptSource);
message = executor.Message;
switch (result)
{
case (int)Result.Succeeded:
return Result.Succeeded;
case (int)Result.Cancelled:
return Result.Cancelled;
case (int)Result.Failed:
return Result.Failed;
default:
return Result.Succeeded;
}
}
}
}
4 changes: 2 additions & 2 deletions RevitPythonShell/RevitCommands/IronPythonConsoleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
{
// now that the console is created and initialized, the script scope should
// be accessible...
new ScriptExecutor(RevitPythonShellApplication.GetConfig(), commandData, messageCopy, elements)
new ScriptExecutor(App.GetConfig(), commandData, messageCopy, elements)
.SetupEnvironment(host.Engine, host.Console.ScriptScope);

host.Console.ScriptScope.SetVariable("__window__", gui);

// run the initscript
var initScript = RevitPythonShellApplication.GetInitScript();
var initScript = App.GetInitScript();
if (initScript != null)
{
var scriptSource = host.Engine.CreateScriptSourceFromString(initScript, SourceCodeKind.Statements);
Expand Down
4 changes: 2 additions & 2 deletions RevitPythonShell/RevitCommands/NonModalConsoleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
{
// now that the console is created and initialized, the script scope should
// be accessible...
new ScriptExecutor(RevitPythonShellApplication.GetConfig(), commandData, messageCopy, elements)
new ScriptExecutor(App.GetConfig(), commandData, messageCopy, elements)
.SetupEnvironment(host.Engine, host.Console.ScriptScope);

host.Console.ScriptScope.SetVariable("__window__", gui);

// run the initscript
var initScript = RevitPythonShellApplication.GetInitScript();
var initScript = App.GetInitScript();
if (initScript != null)
{
var scriptSource = host.Engine.CreateScriptSourceFromString(initScript, SourceCodeKind.Statements);
Expand Down
11 changes: 11 additions & 0 deletions RevitPythonShell/RevitPythonShell.addin
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Application">
<FullClassName>RevitPythonShell.App</FullClassName>
<ClientId>3a7a1d24-51ed-462b-949f-1ddcca12008d</ClientId>
<Name>RevitPythonShell</Name>
<Assembly>RevitPythonShell/RevitPythonShell.dll</Assembly>
<VendorId>3a7a1d24-51ed-462b-949f-1ddcca12008d</VendorId>
<VendorDescription>RIPS, RIPS, </VendorDescription>
</AddIn>
</RevitAddIns>
54 changes: 31 additions & 23 deletions RevitPythonShell/RevitPythonShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CommandLoaderBase.cs" />
<Compile Include="RevitCommands\CommandLoaderBase.cs" />
<Compile Include="Views\CompletionToolTip.cs" />
<Compile Include="RevitCommands\ConfigureCommand.cs" />
<Compile Include="Views\ConfigureCommandsForm.cs">
Expand All @@ -102,7 +102,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="RevitPythonShellApplication.cs" />
<Compile Include="App.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Views\ConfigureCommandsForm.resx">
Expand All @@ -114,6 +114,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="RevitPythonShell.addin" />
<None Include="Manifests\AddinTemplate.addin">
<Generator>MSDataSetGenerator</Generator>
<LastGenOutput>AddinTemplate.Designer.cs</LastGenOutput>
Expand All @@ -133,14 +134,10 @@
<EmbeddedResource Include="Resources\Python-32.png" />
<EmbeddedResource Include="Resources\Settings-16.png" />
<EmbeddedResource Include="Resources\Settings-32.png" />
<Content Include="DefaultConfig\startup.py">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="DefaultConfig\startup.py" />
<Content Include="Properties\launchSettings.json" />
<None Include="Examples\HelloWorld.iss" />
<Content Include="DefaultConfig\init.py">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="DefaultConfig\init.py" />
<EmbeddedResource Include="Resources\CreateWall.png" />
<Content Include="Examples\helloworld.py" />
<Content Include="Examples\HelloWorld.xml">
Expand All @@ -153,10 +150,9 @@
<Resource Include="Resources\Theme\Open.png" />
<Resource Include="Resources\Theme\Paragraph.png" />
<Resource Include="Resources\Theme\Paste.png" />
<Content Include="DefaultConfig\RevitPythonShell.xml">
<None Include="DefaultConfig\RevitPythonShell.xml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</None>
<EmbeddedResource Include="Resources\Python.xshd" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -233,19 +229,31 @@
]]></Code>
</Task>
</UsingTask>
<Target Name="CopyFiles" AfterTargets="CoreBuild" Condition="$(Configuration.Contains('Debug'))">
<!-- Copy newly compiled add-in files to AppData folder (before starting the debugger) -->
<Message Importance="high" Text="Copying addin file into Revit Addin folder" />
<ItemGroup>
<AddinFiles Include="$(OutputPath)\..\**\*.addin" />
</ItemGroup>
<Copy SourceFiles="@(AddinFiles)" DestinationFolder="$(AppData)\Autodesk\Revit\Addins\%(RecursiveDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Retries="3" RetryDelayMilliseconds="300" />
</Target>
<Target Name="CleanAddinsInAppData" AfterTargets="AfterClean">
<!-- Delete previously deployed to AppData folder add-in files -->
<!-- <Target Name="CopyFiles" AfterTargets="CoreBuild" Condition="$(Configuration.Contains('Debug'))">-->
<!-- &lt;!&ndash; Copy newly compiled add-in files to AppData folder (before starting the debugger) &ndash;&gt;-->
<!-- <Message Importance="high" Text="Copying addin file into Revit Addin folder" />-->
<!-- <ItemGroup>-->
<!-- <AddinFiles Include="$(OutputPath)\..\**\*.addin" />-->
<!-- </ItemGroup>-->
<!-- <Copy SourceFiles="@(AddinFiles)" DestinationFolder="$(AppData)\Autodesk\Revit\Addins\%(RecursiveDir)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Retries="3" RetryDelayMilliseconds="300" />-->
<!-- </Target>-->
<!-- <Target Name="CleanAddinsInAppData" AfterTargets="AfterClean">-->
<!-- &lt;!&ndash; Delete previously deployed to AppData folder add-in files &ndash;&gt;-->
<!-- <ItemGroup>-->
<!-- <AddinFiles Include="$(AppData)\Autodesk\Revit\Addins\**\$(AssemblyName).*" />-->
<!-- </ItemGroup>-->
<!-- <Delete Files="@(AddinFiles)" />-->
<!-- </Target>-->
<Target Name="CopyFile" AfterTargets="CoreBuild">
<Message Importance="high" Text="Start Copy File To Addins Folder" />
<ItemGroup>
<AddinFiles Include="$(AppData)\Autodesk\Revit\Addins\**\$(AssemblyName).*" />
<RootItem Include="$(ProjectDir)*.addin" />
<ConfigItem Include="$(ProjectDir)DefaultConfig\*.*" />
<AddinItem Include="$(TargetDir)*.*" />
</ItemGroup>
<Delete Files="@(AddinFiles)" />
<Copy SourceFiles="@(RootItem)" DestinationFolder="$(AppData)\Autodesk\Revit\Addins\$(RevitVersion)\%(RecursiveDir)" Condition="$(Configuration.Contains('Debug'))" />
<Copy SourceFiles="@(AddinItem)" DestinationFolder="$(AppData)\Autodesk\Revit\Addins\$(RevitVersion)\$(AssemblyName)\%(RecursiveDir)" Condition="$(Configuration.Contains('Debug'))" />
<Copy SourceFiles="@(ConfigItem)" DestinationFolder="$(AppData)\Autodesk\Revit\Addins\$(RevitVersion)\$(AssemblyName)\%(RecursiveDir)" Condition="$(Configuration.Contains('Debug'))" />
<Message Importance="high" Text="@(AddinItem)" />
</Target>
</Project>
14 changes: 7 additions & 7 deletions RevitPythonShell/Views/ConfigureCommandsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ private void btnCancel_Click(object sender, EventArgs e)
/// </summary>
private void ConfigureCommandsForm_Load(object sender, EventArgs e)
{
_commands = RevitPythonShellApplication.GetCommands(
RevitPythonShellApplication.GetSettings()).ToList();
_commands = App.GetCommands(
App.GetSettings()).ToList();
lstCommands.DataSource = _commands;

_searchPaths = RevitPythonShellApplication.GetConfig().GetSearchPaths().ToList();
_searchPaths = App.GetConfig().GetSearchPaths().ToList();
lstSearchPaths.DataSource = _searchPaths;

_variables = RevitPythonShellApplication.GetConfig().GetVariables().AsEnumerable().ToList();
_variables = App.GetConfig().GetVariables().AsEnumerable().ToList();
lstVariables.DataSource = _variables;
lstVariables.DisplayMember = "Key";

string initScriptPath = RevitPythonShellApplication.GetInitScriptPath();
string initScriptPath = App.GetInitScriptPath();
txtInitScript.Text = initScriptPath;

string startupScriptPath = RevitPythonShellApplication.GetStartupScriptPath();
string startupScriptPath = App.GetStartupScriptPath();
txtStartupScript.Text = startupScriptPath;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ private void btnCommandMoveDown_Click(object sender, EventArgs e)
/// </summary>
private void btnCommandSave_Click(object sender, EventArgs e)
{
RevitPythonShellApplication.WriteSettings(_commands, _searchPaths, _variables, txtInitScript.Text, txtStartupScript.Text);
App.WriteSettings(_commands, _searchPaths, _variables, txtInitScript.Text, txtStartupScript.Text);
Close();
}

Expand Down

0 comments on commit 53f5312

Please sign in to comment.