Skip to content

addin for Navisworks #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions docs/Navisworks connector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# OpenProject BIM

## Revit <-> Navisworks

![demo](images/demo.gif)

## Future ideas

- [x] Revit
- [x] Navisworks
- [ ] Tekla Structures

![roadmap](images/roadmap2.png)
Binary file added docs/images/demo.gif
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 docs/images/roadmap.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 docs/images/roadmap2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
269 changes: 237 additions & 32 deletions openproject-revit-add-in.sln

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions src/OpenProject.Navisworks/Application/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Autodesk.Navisworks.Api.Plugins;
using OpenProjectNavisworks.Command;
using OpenProjectNavisworks.Properties;
using Serilog;
using Test = OpenProjectNavisworks.Command.Test;
using OpenProject.Shared.Logging;
using System;


namespace OpenProjectNavisworks.Application;

[Plugin("IDP", "PavelNedviga,TachkovMaksim", DisplayName = "IDP-ViewPoint")]
[RibbonLayout("AddinManagerRibbon.xaml")]
[RibbonTab("ID_AddinManager_TAB", DisplayName = "IDP")]
[Command("IDE_ButtonConnectOpenProject",
DisplayName = "IDP-ViewPoint",
Icon = "Resources\\OpenProjectLogo16.png",
LargeIcon = "Resources\\OpenProjectLogo32.png",
ToolTip = "Plugin IDP-ViewPoint")]


public class App : CommandHandlerPlugin
{
public override int ExecuteCommand(string name, params string[] parameters)
{


// Buttons
switch (name)
{
case "ID_ButtonAddinManagerManual":
AddInManagerManual addInManagerManual = new AddInManagerManual();
addInManagerManual.Execute();
break;
case "ID_ButtonAddinManagerFaceless":
AddInManagerFaceLess addInManagerFaceless = new AddInManagerFaceLess();
addInManagerFaceless.Execute();
break;
case "ID_ButtonDockPanelCommand":
DockPanelCommand dockPanelCommand = new DockPanelCommand();
dockPanelCommand.Execute();
break;
case "ID_ButtonTest":
Test test = new Test();
test.Execute();
break;
case "IDE_ButtonConnectOpenProject":
ConnectOpenProject connOP = new ConnectOpenProject();
connOP.Execute();
break;
case "IDE_ButtonSettingsOpenProject":
ConnectSettingsOpenProject connSetOP = new ConnectSettingsOpenProject();
connSetOP.Execute();
break;
case "IDE_ButtonGuide":
Guide guide = new Guide();
guide.Execute();
break;
case "IDE_ButtonInfo":
Info info = new Info();
info.Execute();
break;
}

return 0;
}
}
107 changes: 107 additions & 0 deletions src/OpenProject.Navisworks/Command/AddInManagerCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System.Data.Common;
using System.Diagnostics;
using System.IO;
using System.Windows;
using Autodesk.Navisworks.Api.Plugins;
using OpenProjectNavisworks.Model;
using OpenProjectNavisworks.Entry;
using MessageBox = System.Windows.MessageBox;

namespace OpenProjectNavisworks.Command;

public abstract class IAddinCommand
{
public abstract int Action(params string[] parameters);

public void Execute(params string[] parameters)
{
try
{
Action(parameters);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
/// <summary>
/// Executer the command Addin Manager Manual
/// </summary>
public class AddInManagerManual : IAddinCommand
{
public override int Action(params string[] parameters)
{
Debug.Listeners.Clear();
Trace.Listeners.Clear();
CodeListener codeListener = new CodeListener();
Debug.Listeners.Add(codeListener);
return AddinManagerBase.Instance.ExecuteCommand(false, parameters);
}
}

/// <summary>
/// Execute the command Addin Manager Faceless
/// </summary>
public class AddInManagerFaceLess : IAddinCommand
{
public override int Action(params string[] parameters)
{
return AddinManagerBase.Instance.ExecuteCommand(true, parameters);
}
}


/// <summary>
/// Execute the command for connection to project
/// </summary>
public class ConnectOpenProject : IAddinCommand
{
public override int Action(params string[] parameters)
{
Model.NavisworksWrapper.Document = Autodesk.Navisworks.Api.Application.ActiveDocument;
//Model.NavisworksWrapper.Document Autodesk.Navisworks.Api.Application;
return CmdMain.ExecuteCommand(true, parameters);
}
}


/// <summary>
/// Execute the command for connection settings to project
/// </summary>
public class ConnectSettingsOpenProject : IAddinCommand
{
public override int Action(params string[] parameters)
{
Model.NavisworksWrapper.Document = Autodesk.Navisworks.Api.Application.ActiveDocument;
return CmdMainSettings.ExecuteCommand(true, parameters);
}
}


public class Test : IAddinCommand
{
public override int Action(params string[] parameters)
{
MessageBox.Show("Hello World");
return 0;
}
}

public class Guide : IAddinCommand
{
public override int Action(params string[] parameters)
{
Process.Start("http://books.ide-spb.com/books/autodesk-revit/page/idp-viewpoint");
return 0;
}
}

public class Info : IAddinCommand
{
public override int Action(params string[] parameters)
{
Process.Start("https://gitlab.ide-spb.com/Nedviga.Pavel/openprojectnavisbcf/-/releases");
return 0;
}
}
159 changes: 159 additions & 0 deletions src/OpenProject.Navisworks/Command/AddinManagerBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using System.IO;
using System.Windows;
using Autodesk.Navisworks.Api.Plugins;
using OpenProjectNavisworks.Model;
using OpenProjectNavisworks.View;
using OpenProjectNavisworks.ViewModel;
using MessageBox = System.Windows.MessageBox;

namespace OpenProjectNavisworks.Command;

public sealed class AddinManagerBase
{
public int ExecuteCommand(bool faceless, params string[] parameters)
{
var vm = new AddInManagerViewModel();
if (_activeCmd != null && faceless)
{
return RunActiveCommand(vm, parameters);
}
var FrmAddInManager = new FrmAddInManager(vm);
FrmAddInManager.WindowStartupLocation = WindowStartupLocation.CenterScreen;
FrmAddInManager.SetNavisAsWindowOwner();
FrmAddInManager.ShowDialog();
return 0;
}

public string ActiveTempFolder
{
get => _activeTempFolder;
set => _activeTempFolder = value;
}

public int RunActiveCommand(AddInManagerViewModel vm, params string[] parameters)
{
var filePath = _activeCmd.FilePath;
if (!File.Exists(filePath))
{
MessageBox.Show("File not found: " + filePath,DefaultSetting.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
return 0;
}
int result;
try
{
vm.AssemLoader.HookAssemblyResolve();
var assembly = vm.AssemLoader.LoadAddinsToTempFolder(filePath, false);
if (null == assembly)
{
result = 0;
}
else
{
_activeTempFolder = vm.AssemLoader.TempFolder;
if (assembly.CreateInstance(_activeCmdItem.FullClassName) is not AddInPlugin AddInPlugin)
{
result = 0;
}
else
{
_activeEc = AddInPlugin;
return _activeEc.Execute(parameters);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
result = 0;
}
finally
{
vm.AssemLoader.UnhookAssemblyResolve();
vm.AssemLoader.CopyGeneratedFilesBack();
}

return result;
}

public static AddinManagerBase Instance
{
get
{
if (_instance == null)
{
#pragma warning disable RCS1059 // Avoid locking on publicly accessible instance.
lock (typeof(AddinManagerBase))
{
if (_instance == null)
{
_instance = new AddinManagerBase();
}
}
#pragma warning restore RCS1059 // Avoid locking on publicly accessible instance.
}

return _instance;
}
}

private AddinManagerBase()
{
_addinManager = new AddinManager();
_activeCmd = null;
_activeCmdItem = null;
_activeApp = null;
_activeAppItem = null;
}

public AddInPlugin ActiveEC
{
get => _activeEc;
set => _activeEc = value;
}

public Addin ActiveCmd
{
get => _activeCmd;
set => _activeCmd = value;
}

public AddinItem ActiveCmdItem
{
get => _activeCmdItem;
set => _activeCmdItem = value;
}

public Addin ActiveApp
{
get => _activeApp;
set => _activeApp = value;
}

public AddinItem ActiveAppItem
{
get => _activeAppItem;
set => _activeAppItem = value;
}

public AddinManager AddinManager
{
get => _addinManager;
set => _addinManager = value;
}

private string _activeTempFolder = string.Empty;

private static volatile AddinManagerBase _instance;

private AddInPlugin _activeEc;

private Addin _activeCmd;

private AddinItem _activeCmdItem;

private Addin _activeApp;

private AddinItem _activeAppItem;

private AddinManager _addinManager;
}
35 changes: 35 additions & 0 deletions src/OpenProject.Navisworks/Command/DocpanelCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Autodesk.Navisworks.Api.ApplicationParts;
using Autodesk.Navisworks.Api.Plugins;
using OpenProjectNavisworks.Model;

namespace OpenProjectNavisworks.Command;

public class DockPanelCommand : IAddinCommand
{
public override int Action(params string[] parameters)
{
string PluginId = $"OpenProjectNavisworks.ShowHidePanel.ChuongMep";
if (Autodesk.Navisworks.Api.Application.IsAutomated)
{
throw new InvalidOperationException("Invalid when running using Automation");
}
ApplicationPlugins applicationPlugins = Autodesk.Navisworks.Api.Application.Plugins;
PluginRecord pr = applicationPlugins.FindPlugin(PluginId);
if (pr != null && pr is DockPanePluginRecord && pr.IsEnabled)
{
//check if it needs loading
if (pr.LoadedPlugin == null)
{
pr.LoadPlugin();
}

if (pr.LoadedPlugin is DockPanePlugin dpp)
{
//switch the Visible flag
dpp.Visible = !dpp.Visible;
}
}

return 0;
}
}
Loading