Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Images/devenv_9FXen0L47z.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/devenv_E5MD6kiAQC.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions NavisPythonShell/IronPythonConsoleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using Microsoft.Scripting;
using System.Threading;
using System.Windows.Interop;
using System.Windows.Threading;
using NavisPythonShell.NpsRuntime;
using Forms = System.Windows.Forms;
Expand Down Expand Up @@ -97,6 +98,9 @@ public override int Execute(params string[] parameters)
}
});
});
WindowInteropHelper helper = new WindowInteropHelper(gui);
IntPtr hander = Application.Gui.MainWindow.Handle;
helper.Owner = hander;
gui.ShowDialog();
return 0;
}
Expand Down
13 changes: 11 additions & 2 deletions NavisPythonShell/NavisPythonShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<NoWin32Manifest>False</NoWin32Manifest>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<OutputPath>bin\$(Configuration)\</OutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<!-- see: http://thebuildingcoder.typepad.com/blog/2013/06/processor-architecture-mismatch-warning.html -->
Expand Down Expand Up @@ -87,8 +88,8 @@
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autodesk.Navisworks.Api">
<HintPath>C:\Program Files\Autodesk\Navisworks Manage 2020\Autodesk.Navisworks.Api.dll</HintPath>
<Reference Include="Autodesk.Navisworks.Api, Version=19.0.1374.1, Culture=neutral, PublicKeyToken=d85e58fa5af9b484">
<HintPath>C:\Program Files\Autodesk\Navisworks Manage 2022\Autodesk.Navisworks.Api.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ICSharpCode.AvalonEdit, Version=5.0.3.0, Culture=neutral, PublicKeyToken=9cc39be672370310, processorArchitecture=MSIL">
Expand Down Expand Up @@ -271,6 +272,14 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>xcopy $(TargetDir)*.* "C:\Program Files\Autodesk\Navisworks Manage 2022\Plugins\NavisPythonShell\" /Y /I /E /EXCLUDE:$(SolutionDir)exclude.txt
xcopy $(TargetDir)*.* "C:\Program Files\Autodesk\Navisworks Manage 2022\Dependencies\" /Y /I /E /EXCLUDE:$(SolutionDir)noexclude.txt</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
68 changes: 34 additions & 34 deletions NavisPythonShell/NavisPythonShellApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@ public static void OnLoaded()
{
try
{
applicationLoaded = true;
var dllfolder = GetSettingsFolder();
settingsFolder = dllfolder;
var settings = GetSettings();
applicationLoaded = true;
var dllfolder = GetSettingsFolder();
settingsFolder = dllfolder;

var settings = GetSettings();

//var assemblyName = "CommandLoaderAssembly";
//var dllfullpath = Path.Combine(dllfolder, assemblyName + ".dll");
//CreateCommandLoaderAssembly(settings, dllfolder, assemblyName);
//seems like I need to pre-load my dependencies
AppDomain.CurrentDomain.Load(typeof(NpsConfig).Assembly.GetName());

//seems like I need to pre-load my dependencies
AppDomain.CurrentDomain.Load(typeof(NpsConfig).Assembly.GetName() );

ExecuteStartupScript();
return;
}
Expand All @@ -56,8 +55,8 @@ private static void ExecuteStartupScript()
var startupScript = GetStartupScript();
if (startupScript != null)
{
var executor = new ScriptExecutor(GetConfig() );
var result = executor.ExecuteScript(startupScript, GetStartupScriptPath() );
var executor = new ScriptExecutor(GetConfig());
var result = executor.ExecuteScript(startupScript, GetStartupScriptPath());
if (result == -1)
{
Forms.MessageBox.Show(executor.Message, "NavisPythonShell - StartupScript");
Expand Down Expand Up @@ -117,10 +116,10 @@ public static void OnUnloading()
// FIXME: deallocate the python shell...
return;
}

public static IRpsConfig GetConfig()
{
return new NpsConfig(GetSettingsFile() );
{
return new NpsConfig(GetSettingsFile());
}

/// <summary>
Expand All @@ -145,12 +144,12 @@ private static string GetSettingsFile()
/// </summary>
private static string GetSettingsFolder()
{
if (!string.IsNullOrEmpty(settingsFolder) )
{
return settingsFolder;
}
//return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NavisPythonShell" + versionNumber);
return Path.GetDirectoryName(typeof(NavisPythonShellApplication).Assembly.Location);
if (!string.IsNullOrEmpty(settingsFolder))
{
return settingsFolder;
}
//return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NavisPythonShell" + versionNumber);
return Path.GetDirectoryName(typeof(NavisPythonShellApplication).Assembly.Location);
}

/// <summary>
Expand All @@ -166,7 +165,7 @@ public static IEnumerable<Command> GetCommands(XDocument repository)
var commandName = commandNode.Attribute("name").Value;
var commandSrc = commandNode.Attribute("src").Value;
var group = commandNode.Attribute("group") == null ? "" : commandNode.Attribute("group").Value;

ImageSource largeImage = null;
if (IsValidPath(commandNode.Attribute("largeImage")))
{
Expand All @@ -188,14 +187,15 @@ public static IEnumerable<Command> GetCommands(XDocument repository)
{
smallImage = GetEmbeddedPng(addinAssembly, "NavisPythonShell.Resources.PythonScript16x16.png");
}

yield return new Command {
Name = commandName,
Source = commandSrc,
Group = group,
LargeImage = largeImage,
SmallImage = smallImage,
Index = i++

yield return new Command
{
Name = commandName,
Source = commandSrc,
Group = group,
LargeImage = largeImage,
SmallImage = smallImage,
Index = i++
};
}
}
Expand Down Expand Up @@ -334,7 +334,7 @@ public static string GetStartupScript()
/// </summary>
public static void WriteSettings(
IEnumerable<Command> commands,
IEnumerable<string> searchPaths,
IEnumerable<string> searchPaths,
IEnumerable<KeyValuePair<string, string>> variables,
string initScript,
string startupScript)
Expand Down Expand Up @@ -368,13 +368,13 @@ public static void WriteSettings(
foreach (var command in commands)
{
xmlCommands.Add(new XElement(
"Command",
new XAttribute("name", command.Name),
"Command",
new XAttribute("name", command.Name),
new XAttribute("src", command.Source),
new XAttribute("group", command.Group)));

}
doc.Root.Add(xmlCommands);
doc.Root.Add(xmlCommands);

// add search paths
var xmlSearchPaths = new XElement("SearchPaths");
Expand Down Expand Up @@ -423,7 +423,7 @@ internal class Command
public string Source;
public int Index;
public ImageSource LargeImage;
public ImageSource SmallImage;
public ImageSource SmallImage;

public override string ToString()
{
Expand Down
2 changes: 1 addition & 1 deletion NavisPythonShell/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions NavisPythonShell/init.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# these commands get executed in the current scope
# of each new shell (but not for canned commands)
from Autodesk.Navisworks.Api import *

doc = Application.ActiveDocument
from Autodesk.Navisworks.Api.Clash import *
app = Application
doc = app.ActiveDocument
selection = doc.CurrentSelection.SelectedItems

docclash = DocumentExtensions.GetClash(doc)
def quit():
__window__.Close()
exit = quit
Expand Down
10 changes: 6 additions & 4 deletions NpsRuntime/NpsRuntime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<WarningLevel>4</WarningLevel>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<OutputPath>bin\$(Configuration)\</OutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<!-- see: http://thebuildingcoder.typepad.com/blog/2013/06/processor-architecture-mismatch-warning.html -->
Expand Down Expand Up @@ -64,10 +65,11 @@
<Prefer32Bit />
</PropertyGroup>
<ItemGroup>
<Reference Include="Autodesk.Navisworks.Api">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Autodesk\Navisworks Manage 2020\Autodesk.Navisworks.Api.dll</HintPath>
<Private>False</Private>
<Reference Include="Autodesk.Navisworks.Api, Version=19.0.1374.1, Culture=neutral, PublicKeyToken=d85e58fa5af9b484">
<HintPath>C:\Program Files\Autodesk\Navisworks Manage 2022\Autodesk.Navisworks.Api.dll</HintPath>
</Reference>
<Reference Include="Autodesk.Navisworks.Clash, Version=19.0.1374.1, Culture=neutral, PublicKeyToken=d85e58fa5af9b484">
<HintPath>C:\Program Files\Autodesk\Navisworks Manage 2022\Autodesk.Navisworks.Clash.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.AvalonEdit, Version=5.0.3.0, Culture=neutral, PublicKeyToken=9cc39be672370310, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
6 changes: 3 additions & 3 deletions NpsRuntime/ScriptExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Scripting.Hosting;
using System.Collections.Generic;
using Autodesk.Navisworks.Api;

using Autodesk.Navisworks.Api.Clash;
namespace NavisPythonShell.NpsRuntime
{
/// <summary>
Expand Down Expand Up @@ -141,9 +141,9 @@ public void SetupEnvironment(ScriptEngine engine, ScriptScope scope)
AddSearchPaths(engine);
AddEmbeddedLib(engine);

// reference RevitAPI and RevitAPIUI
// reference Navisworks Api Document and Application
engine.Runtime.LoadAssembly(typeof(Autodesk.Navisworks.Api.Document).Assembly);

engine.Runtime.LoadAssembly(typeof(Autodesk.Navisworks.Api.Clash.ClashTest).Assembly);
// also, allow access to the RPS internals
engine.Runtime.LoadAssembly(typeof(NavisPythonShell.NpsRuntime.ScriptExecutor).Assembly);
}
Expand Down
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ The biggest limitation is that you can't deploy DLLs with custom scripts at this

- Reference the version of "Autodesk.Navisworks.Api.dll" that you'd like to target.
- Compile the solution.
- Go to the "%APPDATA%\Autodesk Navisworks Manage 2020\" (or the version that you'd like to target)
- Go to the "C:\Program Files\Autodesk\Navisworks Manage {version}\Plugins" (with version a version current of navisworks)
- If there is no "Plugins" foler, create it
- In the "Plugins" folder create a "NavisPythonShell" folder
- Copy the contents of the build folder (usually ".\NavisPythonShell\NavisPythonShell\bin\$(Configuration)\" ) to the "\Plugins\NavisPythonShell\" folder
- The final plugin directory should be similar to "%APPDATA%\Autodesk Navisworks Manage 2020\Plugins\NavisPythonShell"
- Change Permisstions of two folder `Plugins` and `Dependencies` in properties

![](Images/devenv_9FXen0L47z.png)

![](Images/devenv_E5MD6kiAQC.png)

- Build Solution(if you change `version` of navisworks, please change number version in post build event)
```
xcopy $(TargetDir)*.* "C:\Program Files\Autodesk\Navisworks Manage {version}\Plugins\NavisPythonShell\" /Y /I /E /EXCLUDE:$(SolutionDir)exclude.txt

xcopy $(TargetDir)*.* "C:\Program Files\Autodesk\Navisworks Manage {version}\Dependencies\" /Y /I /E /EXCLUDE:$(SolutionDir)noexclude.txt

```

OR

- Download a valid [release zip](https://github.com/dimven/NavisPythonShell/releases) for your version of Navisworks.
- Extract the zip to "%APPDATA%\Autodesk Navisworks Manage 2020\Plugins" (or whichever version of Navisworks you're targeting)
- Download a valid [release zip](https://github.com/dimven/NavisPythonShell/releases) for your `version` of Navisworks.
- Extract the zip to two folder:
- "C:\Program Files\Autodesk\Autodesk Navisworks Manage {version}\Plugins" : include all file in noexclude.txt and folder icon
- "C:\Program Files\Autodesk\Autodesk Navisworks Manage {version}\Dependencies" : include all file in exclude.txt

## Contribute

Expand Down
Binary file added Script Examples/ClashTest.nwd
Binary file not shown.
7 changes: 7 additions & 0 deletions Script Examples/GetClashTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
testdata = docclash.TestsData
tests = testdata.Tests
for test in tests:
SavedItemCollection = test.Children
for saveitem in SavedItemCollection:
print(saveitem.DisplayName)
print(saveitem.Center)
16 changes: 16 additions & 0 deletions exclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Autodesk.Navisworks.Api.dll
Autodesk.Navisworks.Api.xml
ICSharpCode.AvalonEdit.dll
IronPython.dll
IronPython.Modules.dll
IronPython.SQLite.dll
IronPython.Wpf.dll
Microsoft.Dynamic.dll
Microsoft.Scripting.dll
Microsoft.Scripting.Metadata.dll
NpsRuntime.dll
NpsRuntime.pdb
PythonConsoleControl.dll
PythonConsoleControl.pdb
System.Windows.Controls.WpfPropertyGrid.dll
WPG.dll
5 changes: 5 additions & 0 deletions noexclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
init.py
NavisPythonShell.dll
NavisPythonShell.pdb
NavisPythonShell.xml
startup.py