├── .gitignore
├── RevitPlugin
├── Resources
│ ├── Images
│ │ └── Icons
│ │ │ ├── ifc_icon.jpg
│ │ │ ├── pushbutton.png
│ │ │ └── tooltipimage.png
│ └── ResourceImage.cs
├── Models
│ ├── Enums
│ │ └── ErrorType.cs
│ └── Error.cs
├── RevitPlugin.csproj.user
├── PluginAssembly.cs
├── UI
│ ├── Revit
│ │ ├── PushButtonDataModel.cs
│ │ └── RevitPushButton.cs
│ ├── MainWindow.xaml.cs
│ └── MainWindow.xaml
├── App.cs
├── Services
│ ├── Messenger
│ │ ├── IMessenger.cs
│ │ └── Messenger.cs
│ └── DocumentManager.cs
├── SetupInterface.cs
├── Properties
│ └── AssemblyInfo.cs
├── Utilities
│ └── Extensions
│ │ └── ExpressionExtensions.cs
├── Commands
│ ├── JoinElements.cs
│ └── ImportIfcCommand.cs
├── packages.config
├── app.config
├── Base
│ ├── RelayCommand.cs
│ └── ViewModelBase.cs
├── RevitPlugin.csproj
└── ViewModels
│ ├── MainWindowViewModel.cs
│ └── MainWindowViewModel.Helpers.cs
├── IFCLoader
├── Data Model
│ ├── Point.cs
│ ├── Column.cs
│ ├── FloorSlab.cs
│ ├── Inclined.cs
│ ├── Beam.cs
│ ├── ColumnSt.cs
│ ├── Brace.cs
│ └── BeamSt.cs
├── Properties
│ └── AssemblyInfo.cs
├── LoaderWin.cs
├── packages.config
├── App.config
├── src
│ ├── IFC_Loader.cs
│ └── Adapter.cs
├── LoaderWin.resx
├── Program.cs
├── IFC_Loader.csproj
└── LoaderWin.Designer.cs
├── IFCtoREVIT.addin
├── README.md
└── IFCtoREVIT.sln
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs/
2 | packages/
3 | IFCLoader/.vs/
4 | IFCLoader/bin/
5 | IFCLoader/obj/
6 | RevitPlugin/.vs/
7 | RevitPlugin/bin/
8 | RevitPlugin/obj/
--------------------------------------------------------------------------------
/RevitPlugin/Resources/Images/Icons/ifc_icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ibrahim5aad/ifc-to-revit-using-named-pipes/HEAD/RevitPlugin/Resources/Images/Icons/ifc_icon.jpg
--------------------------------------------------------------------------------
/RevitPlugin/Resources/Images/Icons/pushbutton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ibrahim5aad/ifc-to-revit-using-named-pipes/HEAD/RevitPlugin/Resources/Images/Icons/pushbutton.png
--------------------------------------------------------------------------------
/RevitPlugin/Resources/Images/Icons/tooltipimage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ibrahim5aad/ifc-to-revit-using-named-pipes/HEAD/RevitPlugin/Resources/Images/Icons/tooltipimage.png
--------------------------------------------------------------------------------
/RevitPlugin/Models/Enums/ErrorType.cs:
--------------------------------------------------------------------------------
1 | namespace IFCtoRevit.Models
2 | {
3 | ///
4 | /// Enum ErrorType
5 | ///
6 | public enum ErrorType
7 | {
8 | Error,
9 | Warning,
10 | Info
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/RevitPlugin/RevitPlugin.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ProjectFiles
5 |
6 |
--------------------------------------------------------------------------------
/IFCLoader/Data Model/Point.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace IFCtoRevit.IFCLoader
8 | {
9 | [Serializable()]
10 | public struct Point
11 | {
12 | public double X;
13 | public double Y;
14 | public double Z;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/IFCLoader/Data Model/Column.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IFCtoRevit.IFCLoader
4 | {
5 | [Serializable()]
6 | public class Column
7 | {
8 |
9 | public Point Location { get; set; }
10 |
11 | public string Name { get; set; }
12 |
13 | public double BottomLevel { get; set; }
14 |
15 | public double TopLevel { get; set; }
16 |
17 | public double Width { get; set; }
18 |
19 | public double Depth { get; set; }
20 |
21 | public Point RefDirection { get; set; }
22 |
23 |
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/IFCLoader/Data Model/FloorSlab.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows.Media.Media3D;
4 |
5 |
6 | namespace IFCtoRevit.IFCLoader
7 | {
8 | [Serializable()]
9 | public class FloorSlab
10 | {
11 | public string Name { get; set; }
12 | public double Level { get; set; }
13 | public List Profile { get; set; }
14 |
15 | public Matrix3D Mat { get; set; }
16 |
17 | public Point RefDirection { get; set; }
18 |
19 | public Point Location { get; set; }
20 | public double Depth { get; set; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/IFCLoader/Data Model/Inclined.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IFCtoRevit.IFCLoader
4 | {
5 | [Serializable()]
6 | public class Inclined
7 | {
8 | public Point Location { get; set; }
9 | public Point RefDirection { get; set; }
10 | public Point Axis { get; set; }
11 | public double Length { get; set; }
12 | public string Name { get; set; }
13 | public double BottomLevel { get; set; }
14 | public double Width { get; set; }
15 | public double Depth { get; set; }
16 |
17 | // public double TopLevel { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/IFCLoader/Data Model/Beam.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace IFCtoRevit.IFCLoader
8 | {
9 | [Serializable()]
10 | public class Beam
11 | {
12 |
13 | public string Name { get; set; }
14 | public double H { get; set; }
15 | public double B { get; set; }
16 | public double Length { get; set; }
17 | public Point Location { get; set; }
18 | public Point RefDirection { get; set; }
19 | public Point Axis { get; set; }
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/IFCLoader/Data Model/ColumnSt.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 |
4 | namespace IFCtoRevit.IFCLoader
5 | {
6 | [Serializable()]
7 | public class ColumnSt
8 | {
9 | public Point Location { get; set; }
10 | public Point RefDirection { get; set; }
11 | public string Name { get; set; }
12 | public double BottomLevel { get; set; }
13 | public double TopLevel { get; set; }
14 | public double Width { get; set; }
15 | public double Depth { get; set; }
16 | public double FlangeTh { get; set; }
17 | public double WebTh { get; set; }
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/IFCtoREVIT.addin:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Import IFC Files
5 | IFCtoREVIT\RevitPlugin.dll
6 | 4BB49F2D-A774-4818-BEB8-EF95BB2CEA1F
7 | IFCtoRevit.App
8 | By: Marwa Mohamed and Ibrahim Saad
9 | AlwaysVisible
10 | Unknown
11 |
12 | Properly open IFC files exported from Etabs...
13 |
14 |
15 |
--------------------------------------------------------------------------------
/IFCLoader/Data Model/Brace.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IFCtoRevit.IFCLoader
4 | {
5 | [Serializable()]
6 | public class Brace
7 | {
8 | public Point Location { get; set; }
9 | public Point RefDirection { get; set; }
10 | public Point Axis { get; set; }
11 | public double Length { get; set; }
12 | public string Name { get; set; }
13 | public double BottomLevel { get; set; }
14 | public double Width { get; set; }
15 | public double Depth { get; set; }
16 | public double Thickness { get; set; }
17 |
18 | // public double TopLevel { get; set; }
19 | }
20 | }
--------------------------------------------------------------------------------
/RevitPlugin/PluginAssembly.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 |
4 | namespace IFCtoRevit
5 | {
6 | public static class PluginAssembly
7 | {
8 |
9 | public static Assembly GetAssembly()
10 | {
11 | return Assembly.GetExecutingAssembly();
12 | }
13 |
14 | // Assembly Location
15 | public static string GetAssemblyLocation()
16 | {
17 | return Assembly.GetExecutingAssembly().Location;
18 | }
19 |
20 | //Assembly Namespace
21 | public static string GetNamespace()
22 | {
23 | return typeof(PluginAssembly).Namespace + ".";
24 | }
25 |
26 |
27 | }
28 | }
--------------------------------------------------------------------------------
/IFCLoader/Data Model/BeamSt.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace IFCtoRevit.IFCLoader
8 | {
9 | [Serializable()]
10 | public class BeamSt
11 | {
12 |
13 | public Point Location { get; set; }
14 | public Point RefDirection { get; set; }
15 | public Point Axis { get; set; }
16 | public string Name { get; set; }
17 | public double Length { get; set; }
18 | public double Width { get; set; }
19 | public double Depth { get; set; }
20 | public double FlangeTh { get; set; }
21 | public double WebTh { get; set; }
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/RevitPlugin/Resources/ResourceImage.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Media.Imaging;
2 |
3 |
4 | namespace IFCtoRevit
5 | {
6 |
7 | public static class ResourceImage
8 | {
9 |
10 | public static BitmapImage GetIcon(string name)
11 | {
12 | // Create the resource reader stream.
13 | var stream = PluginAssembly.GetAssembly().GetManifestResourceStream(PluginAssembly.GetNamespace() + "Resources.Images.Icons." + name);
14 |
15 | var image = new BitmapImage();
16 |
17 | // Construct and return image.
18 | image.BeginInit();
19 | image.StreamSource = stream;
20 | image.EndInit();
21 |
22 | // Return constructed BitmapImage.
23 | return image;
24 | }
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/RevitPlugin/UI/Revit/PushButtonDataModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Autodesk.Revit.UI;
3 |
4 |
5 |
6 | namespace IFCtoRevit.UI
7 | {
8 |
9 | ///
10 | /// Represents Revit push button data model.
11 | ///
12 | public class RevitPushButtonDataModel
13 | {
14 | #region public methods
15 |
16 | public string Label { get; set; }
17 |
18 |
19 | public RibbonPanel Panel { get; set; }
20 |
21 | public string CommandNamespacePath { get; set; }
22 |
23 | public string Tooltip { get; set; }
24 |
25 | public string IconImageName { get; set; }
26 |
27 |
28 | public string TooltipImageName { get; set; }
29 |
30 | #endregion
31 |
32 | #region constructor
33 |
34 |
35 | public RevitPushButtonDataModel()
36 | {
37 |
38 | }
39 |
40 | #endregion
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IFC to Revit using Named Pipes
2 |
3 | This is a sample application demonstrating how to use named pipes to establish a communication between a Revit plugin and a console application.
4 | The console application is an IFC files loader that is built on top of xBIM toolkit. Although this is a great demo how to use Named Pipe
5 | to establish a two-way communication with a Revit context, there was a technical necessity to follow this design. The necessity arises from
6 | a DLL collision that occurs when trying to use the xBIM toolkit inside Revit context directly; Microsoft.Extensions.Logging DLL is a common
7 | dependency between Revit and xBIM but each ecosystem has a different incompatible version. So, the solution was to run the IFC parsing/loading
8 | operations out-of-process with Revit and establish the communication through named pipes.
9 |
10 | ### Vidoe tutorial:
11 | [](https://www.youtube.com/watch?v=sGKHa4ep-xE)
12 |
--------------------------------------------------------------------------------
/RevitPlugin/UI/Revit/RevitPushButton.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Autodesk.Revit.UI;
3 |
4 | namespace IFCtoRevit.UI
5 | {
6 |
7 | public static class RevitPushButton
8 | {
9 | #region public methods
10 |
11 | public static PushButton Create(RevitPushButtonDataModel data)
12 | {
13 | // The button name based on unique identifier.
14 | var btnDataName = Guid.NewGuid().ToString();
15 |
16 | // Sets the button data.
17 | var btnData = new PushButtonData(btnDataName, data.Label, PluginAssembly.GetAssemblyLocation(), data.CommandNamespacePath)
18 | {
19 | ToolTip = data.Tooltip,
20 | LargeImage = ResourceImage.GetIcon(data.IconImageName),
21 | ToolTipImage = ResourceImage.GetIcon(data.TooltipImageName)
22 | };
23 |
24 | // Return created button and host it on panel provided in required data model.
25 | return data.Panel.AddItem(btnData) as PushButton;
26 | }
27 |
28 | #endregion
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/RevitPlugin/App.cs:
--------------------------------------------------------------------------------
1 | using Autodesk.Revit.UI;
2 |
3 | namespace IFCtoRevit
4 | {
5 | public class App : IExternalApplication
6 | {
7 | ///
8 | /// Will execute your tasks when Autodesk Revit starts.
9 | ///
10 | /// A handle to the application being started.
11 | ///
12 | /// Indicates if the external application completes its work successfully.
13 | ///
14 | public Result OnStartup(UIControlledApplication application)
15 | {
16 | SetupInterface
17 | .Initialize(application);
18 | return Result.Succeeded;
19 | }
20 |
21 |
22 | ///
23 | /// Will excute your tasks when Autodesk Revit shuts down.
24 | ///
25 | /// A handle to the application being shut down.
26 | ///
27 | /// Indicates if the external application completes its work successfully.
28 | ///
29 | public Result OnShutdown(UIControlledApplication application)
30 | {
31 | return Result.Succeeded;
32 |
33 | }
34 |
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/RevitPlugin/UI/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using IFCtoRevit.ViewModels;
2 | using System.Windows;
3 |
4 | namespace IFCtoRevit.UI.Windows
5 | {
6 | ///
7 | /// Interaction logic for MainWindow.xaml
8 | ///
9 | public partial class MainWindow : Window
10 | {
11 |
12 | ///
13 | /// Initializes a new instance of the class.
14 | ///
15 | public MainWindow()
16 | {
17 | DataContext = new MainWindowViewModel();
18 | InitializeComponent();
19 | }
20 |
21 |
22 | ///
23 | /// Gets or sets the current window.
24 | ///
25 | /// The current window.
26 | public static MainWindow CurrentWindow { get; set; }
27 |
28 |
29 | ///
30 | /// Handles the Click event of the btnClose control.
31 | ///
32 | /// The source of the event.
33 | /// The instance containing the event data.
34 | private void btnClose_Click(object sender, RoutedEventArgs e)
35 | {
36 | DataContext = null;
37 | Close();
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/RevitPlugin/UI/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
23 |
28 |
35 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/RevitPlugin/Services/Messenger/IMessenger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Sanveo.Common.Services
4 | {
5 | ///
6 | /// Interface IMessenger exposes the required functionality for a Messenger
7 | /// class to implement.
8 | ///
9 | public interface IMessenger
10 | {
11 |
12 |
13 | ///
14 | /// Subscribes the specified subscriber.
15 | ///
16 | /// The type of message to subscribe to.
17 | /// The subscriber.
18 | /// The notification action.
19 | /// The context.
20 | void Subscribe(object subscriber, Action action, object context);
21 |
22 |
23 |
24 | ///
25 | /// Unsubscribes the specified subscriber.
26 | ///
27 | /// The type of message to unsubscribe from.
28 | /// The subscriber.
29 | /// The context.
30 | void Unsubscribe(object subscriber, object context);
31 |
32 |
33 |
34 | ///
35 | /// Publishes the specified message to the subscribers.
36 | ///
37 | /// The type of message to publish.
38 | /// The message.
39 | /// The context.
40 | void Publish(T message, object context);
41 |
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/RevitPlugin/SetupInterface.cs:
--------------------------------------------------------------------------------
1 | using Autodesk.Revit.UI;
2 | using IFCtoRevit.UI;
3 |
4 | namespace IFCtoRevit
5 | {
6 |
7 | ///
8 | /// Setup whole plugins interface with tabs, panels, buttons,...
9 | ///
10 | public class SetupInterface
11 | {
12 | #region Methods
13 |
14 | ///
15 | /// Initializes the specified application.
16 | ///
17 | /// The application.
18 | public static void Initialize(UIControlledApplication app)
19 | {
20 | // Create ribbon tab.
21 | string tabName = "IFC to Revit";
22 | app.CreateRibbonTab(tabName);
23 |
24 | // Create the ribbon panels.
25 | var annotateCommandsPanel = app.CreateRibbonPanel(tabName, "IFC");
26 |
27 | // Populate button data model.
28 | var TagWallButtonData = new RevitPushButtonDataModel
29 | {
30 | Label = "Import IFC",
31 | Panel = annotateCommandsPanel,
32 | Tooltip = "Import IFC files exported from CSI ETABS...",
33 | CommandNamespacePath = ImportIfcCommand.GetPath(),
34 | IconImageName = "pushbutton.png",
35 | TooltipImageName = "tooltipimage.png"
36 | };
37 |
38 | // Create button from provided data.
39 | var TagWallButton = RevitPushButton.Create(TagWallButtonData);
40 |
41 | }
42 |
43 | #endregion
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/IFCLoader/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("IFCBuilder")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("IFCBuilder")]
13 | [assembly: AssemblyCopyright("Copyright © 2020")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("7110d893-4795-49b2-b27f-ade60b20d05c")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/RevitPlugin/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RevitPlugin")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("RevitPlugin")]
13 | [assembly: AssemblyCopyright("Copyright © 2020")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("39422482-b026-4ac2-83cd-7b18ed3c9d9a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/RevitPlugin/Utilities/Extensions/ExpressionExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq.Expressions;
3 | using System.Reflection;
4 |
5 | namespace IFCtoRevit.Utilities.Extensions
6 | {
7 |
8 | ///
9 | /// Class ExpressionExtensions.
10 | ///
11 | public static class ExpressionExtensions
12 | {
13 |
14 | ///
15 | /// Compiles an Expression and get function return value
16 | ///
17 | /// type of return value
18 | /// Expression to compile
19 | /// T.
20 | public static T GetPropertyValue(this Expression> lambda)
21 | {
22 | return lambda.Compile().Invoke();
23 | }
24 |
25 |
26 | ///
27 | /// Sets the underlying property value to the given value
28 | /// from and expression that contains the property.
29 | ///
30 | /// >type of return value
31 | /// Expression.
32 | /// The value.
33 | public static void SetPropertyValue(this Expression> lambda, T value)
34 | {
35 | //converts a lambda [() => some.Property], to [some.Property] "get red of lambda"
36 | var expression = (lambda as LambdaExpression).Body as MemberExpression;
37 |
38 | //Get the property information
39 | var propertyInfo = (PropertyInfo)expression.Member;
40 |
41 | //get the view model that carry the property
42 | var target = Expression.Lambda(expression.Expression).Compile().DynamicInvoke();
43 |
44 | //set the property value
45 | propertyInfo.SetValue(target, value);
46 |
47 | }
48 | }
49 |
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/RevitPlugin/Commands/JoinElements.cs:
--------------------------------------------------------------------------------
1 | using Autodesk.Revit.Attributes;
2 | using Autodesk.Revit.DB;
3 | using Autodesk.Revit.UI;
4 |
5 | namespace IFCtoRevit
6 | {
7 | [Transaction(TransactionMode.Manual)]
8 | [Regeneration(RegenerationOption.Manual)]
9 | class JoinElements : IExternalCommand
10 | {
11 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
12 | {
13 | UIApplication uiapp = commandData.Application;
14 | UIDocument uidoc = uiapp.ActiveUIDocument;
15 | //Application app = uiapp.Application;
16 | Document doc = uidoc.Document;
17 |
18 | // get all walls on the active view
19 | FilteredElementCollector floors =
20 | new FilteredElementCollector(doc, doc.ActiveView.Id);
21 | floors.OfClass(typeof(Floor));
22 |
23 | foreach (Floor w in floors)
24 | {
25 | // get columns on the active view
26 | FilteredElementCollector beams = new FilteredElementCollector(doc, doc.ActiveView.Id)
27 | .OfClass(typeof(FamilyInstance))
28 | .OfCategory(BuiltInCategory.OST_StructuralFraming);
29 |
30 | // as we don't want all columns, let's filter
31 | // by the wall bounding box (intersect)
32 | BoundingBoxXYZ bb = w.get_BoundingBox(doc.ActiveView);
33 | Outline outline = new Outline(bb.Min, bb.Max);
34 | BoundingBoxIntersectsFilter bbfilter =
35 | new BoundingBoxIntersectsFilter(outline);
36 |
37 | beams.WherePasses(bbfilter);
38 |
39 |
40 | using (Transaction t = new Transaction(doc, "Join Elements"))
41 | {
42 | t.Start();
43 | foreach (FamilyInstance b in beams)
44 | {
45 | JoinGeometryUtils.JoinGeometry(doc, w, b);
46 | }
47 | t.Commit();
48 | }
49 | }
50 | return Result.Succeeded;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/RevitPlugin/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/RevitPlugin/Models/Error.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IFCtoRevit.Models
4 | {
5 |
6 | ///
7 | /// Class Error.
8 | /// Implements the
9 | ///
10 | ///
11 | public class Error : IEquatable
12 | {
13 |
14 | #region Constructor
15 |
16 | ///
17 | /// Initialize a new object of the error class.
18 | ///
19 | /// The message.
20 | /// Type of the error.
21 | public Error(string message, ErrorType errorType = ErrorType.Error)
22 | {
23 | Message = message;
24 | ErrorType = errorType;
25 | }
26 |
27 |
28 | ///
29 | /// Initialize a new object of the error class.
30 | ///
31 | public Error() { }
32 |
33 | #endregion
34 |
35 | #region Properties
36 |
37 | ///
38 | /// Get or set the error type.
39 | ///
40 | public ErrorType ErrorType { get; set; }
41 |
42 |
43 | ///
44 | /// Get or set the error message.
45 | ///
46 | public string Message { get; set; }
47 |
48 | #endregion
49 |
50 | #region Methods
51 |
52 | ///
53 | /// Returns a that represents this instance.
54 | ///
55 | /// A that represents this instance.
56 | public override string ToString()
57 | {
58 | return ErrorType.ToString() + "\n" + Message;
59 | }
60 |
61 | ///
62 | /// Indicates whether the current object is equal to another object of the same type.
63 | ///
64 | /// An object to compare with this object.
65 | /// if the current object is equal to the parameter; otherwise, .
66 | public bool Equals(Error other)
67 | {
68 | if (this == null || other == null) return false;
69 | if (ReferenceEquals(this, other)) return true;
70 | return ToString().Equals(other.ToString());
71 | }
72 |
73 | #endregion
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/IFCLoader/LoaderWin.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | namespace IFCtoRevit.IFCLoader
12 | {
13 | public partial class LoaderWin : Form
14 | {
15 | public static bool isCancelled = false;
16 |
17 | OpenFileDialog ofd;
18 |
19 | public static string FilePath;
20 | public LoaderWin()
21 | {
22 | InitializeComponent();
23 | }
24 |
25 | private void button1_Click(object sender, EventArgs e)
26 | {
27 |
28 | ofd = new OpenFileDialog();
29 | ofd.Filter = "IFC files (*.ifc)|*.ifc|All files (*.*)|*.*";
30 |
31 | if (ofd.ShowDialog() == DialogResult.OK)
32 | {
33 | FilePath = ofd.FileName;
34 | textBox1.Text = ofd.FileName;
35 | }
36 |
37 | }
38 |
39 | private void LoaderWin_Load(object sender, EventArgs e)
40 | {
41 | checkBox1.Checked = false;
42 | checkBox2.Checked = false;
43 | checkBox3.Checked = false;
44 | checkBox4.Checked = false;
45 | }
46 |
47 | private void button2_Click(object sender, EventArgs e)
48 | {
49 | Application.Exit();
50 | }
51 |
52 | private void checkBox2_CheckedChanged(object sender, EventArgs e)
53 | {
54 | Program.incsImport = checkBox2.Checked ? true : false;
55 |
56 | }
57 |
58 | private void checkBox1_CheckedChanged(object sender, EventArgs e)
59 | {
60 | Program.colsImport = checkBox1.Checked ? true : false;
61 | }
62 |
63 | private void checkBox3_CheckedChanged(object sender, EventArgs e)
64 | {
65 | Program.beamsImport = checkBox3.Checked ? true : false;
66 | }
67 |
68 | private void checkBox4_CheckedChanged(object sender, EventArgs e)
69 | {
70 | Program.floorsImport = checkBox4.Checked ? true : false;
71 |
72 | }
73 |
74 | private void button3_Click(object sender, EventArgs e)
75 | {
76 | this.Close();
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/IFCLoader/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/RevitPlugin/Commands/ImportIfcCommand.cs:
--------------------------------------------------------------------------------
1 | using Autodesk.Revit.Attributes;
2 | using Autodesk.Revit.DB;
3 | using Autodesk.Revit.UI;
4 | using IFCtoRevit.Services;
5 | using IFCtoRevit.UI.Windows;
6 | using IFCtoRevit.ViewModels;
7 | using System;
8 | using System.Linq;
9 | using System.Windows;
10 |
11 | namespace IFCtoRevit
12 | {
13 |
14 | [Transaction(TransactionMode.Manual)]
15 | public partial class ImportIfcCommand : IExternalCommand
16 | {
17 |
18 | ///
19 | /// Gets the path of the command.
20 | ///
21 | ///
22 | public static string GetPath()
23 | {
24 | return typeof(ImportIfcCommand).Namespace + "." + nameof(ImportIfcCommand);
25 | }
26 |
27 |
28 | ///
29 | /// Executes the external command within Revit.
30 | ///
31 | /// An ExternalCommandData object which contains reference to Application and View
32 | /// needed by external command.
33 | /// Error message can be returned by external command. This will be displayed only if the command status
34 | /// was "Failed". There is a limit of 1023 characters for this message; strings longer than this will be truncated.
35 | /// Element set indicating problem elements to display in the failure dialog. This will be used
36 | /// only if the command status was "Failed".
37 | ///
38 | /// The result indicates if the execution fails, succeeds, or was canceled by user. If it does not
39 | /// succeed, Revit will undo any changes made by the external command.
40 | ///
41 | public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
42 | {
43 |
44 | UIDocument uidoc = commandData.Application.ActiveUIDocument;
45 | Document doc = uidoc.Document;
46 | MainWindowViewModel.RevitVersion = Convert.ToInt32(doc.Application.VersionName.Split(' ').Last());
47 |
48 | if (MainWindow.CurrentWindow == null)
49 | {
50 | MainWindow.CurrentWindow = new MainWindow();
51 | DocumentManager.Instance.Init(commandData.Application);
52 | MainWindow.CurrentWindow.Show();
53 | }
54 | else
55 | {
56 | if (MainWindow.CurrentWindow.WindowState == WindowState.Minimized)
57 | MainWindow.CurrentWindow.WindowState = WindowState.Normal;
58 | else
59 | MainWindow.CurrentWindow.Focus();
60 | }
61 | return Result.Succeeded;
62 | }
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/RevitPlugin/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/IFCLoader/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/RevitPlugin/Services/DocumentManager.cs:
--------------------------------------------------------------------------------
1 | using Autodesk.Revit.DB;
2 | using Autodesk.Revit.UI;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace IFCtoRevit.Services
10 | {
11 | ///
12 | /// Class DocumentManager.
13 | /// Implements the
14 | ///
15 | ///
16 | public class DocumentManager : IDisposable
17 | {
18 |
19 | #region Fields
20 |
21 | private Document _doc;
22 | private UIDocument _uidoc;
23 | private static DocumentManager _instance;
24 | private UIApplication _uiapp;
25 |
26 | #endregion
27 |
28 | #region Constructor
29 |
30 | ///
31 | /// Prevents a default instance of the class from being created.
32 | ///
33 | private DocumentManager()
34 | {
35 | }
36 |
37 | #endregion
38 |
39 | #region properties
40 |
41 | ///
42 | /// Gets the singleton instance.
43 | ///
44 | /// The instance.
45 | public static DocumentManager Instance
46 | {
47 | get
48 | {
49 | if (_instance == null)
50 | _instance = new DocumentManager();
51 | return _instance;
52 | }
53 | }
54 |
55 |
56 | ///
57 | /// Gets or sets the current document.
58 | ///
59 | /// The current document.
60 | public Document CurrentDocument
61 | {
62 | get { return _doc; }
63 | set
64 | {
65 | _doc = value;
66 | }
67 | }
68 |
69 |
70 | ///
71 | /// Gets the active view.
72 | ///
73 | /// The active view.
74 | public View ActiveView => CurrentDocument.ActiveView;
75 |
76 |
77 | ///
78 | /// Gets or sets the current UI document.
79 | ///
80 | /// The current UI document.
81 | public UIDocument CurrentUIDocument
82 | {
83 | get { return _uidoc; }
84 | set
85 | {
86 | _uidoc = value;
87 | }
88 | }
89 |
90 |
91 | ///
92 | /// Gets or sets the application.
93 | ///
94 | /// The application.
95 | public UIApplication Application
96 | {
97 | get { return _uiapp; }
98 | set
99 | {
100 | _uiapp = value;
101 | }
102 | }
103 |
104 |
105 | ///
106 | /// Gets the version number.
107 | ///
108 | /// The version number.
109 | public string VersionNumber => Application.Application.VersionNumber;
110 |
111 | #endregion
112 |
113 | #region Methods
114 |
115 | ///
116 | /// Initializes the specified application.
117 | ///
118 | /// The application.
119 | public void Init(UIApplication application)
120 | {
121 | _uiapp = application;
122 | _uidoc = application.ActiveUIDocument;
123 | _doc = _uidoc.Document;
124 | }
125 |
126 |
127 | ///
128 | /// Changes the document.
129 | ///
130 | /// The document.
131 | public void ChangeDocument(Document doc)
132 | {
133 | _doc = doc;
134 | }
135 |
136 |
137 | ///
138 | /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
139 | ///
140 | public void Dispose()
141 | {
142 | _uiapp = null;
143 | _uidoc = null;
144 | _doc = null;
145 | _instance = null;
146 | }
147 |
148 | #endregion
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/IFCLoader/src/IFC_Loader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Xbim.Ifc;
5 | using Xbim.Ifc4.Interfaces;
6 |
7 |
8 | namespace IFCtoRevit.IFCLoader
9 | {
10 | public static class IFC_Loader
11 | {
12 | static IfcStore _ifcModel;
13 |
14 | static List _columns;
15 | static List _inclines;
16 | static List _beams;
17 | static List _floors;
18 | static List _bStoreys;
19 |
20 | static List _columnsSt;
21 | static List _braces;
22 | static List _beamsSt;
23 |
24 | public static bool LoadFile(string filePath, string fileName)
25 | {
26 | _ifcModel = IfcStore.Open($"{filePath}{fileName}.ifc");
27 | if (_ifcModel != null) return true; else return false;
28 | }
29 |
30 | public static bool LoadFile(string fileLocation)
31 | {
32 | _ifcModel = IfcStore.Open($"{fileLocation}");
33 | if (_ifcModel != null) return true; else return false;
34 | }
35 |
36 | public static void GetIFCElements()
37 | {
38 | _bStoreys = _ifcModel.Instances.OfType().ToList();
39 |
40 | _floors = _ifcModel.Instances.OfType().ToList();
41 |
42 | _columns = _ifcModel.Instances.OfType().Where(col => {
43 | if ((col.Representation.Representations.FirstOrDefault()
44 | .Items.FirstOrDefault() as IIfcExtrudedAreaSolid)
45 | .SweptArea is IIfcRectangleProfileDef) return true; else return false; }).ToList();
46 |
47 |
48 | _columnsSt = _ifcModel.Instances.OfType().Where(col => {
49 | if ((col.Representation.Representations.FirstOrDefault()
50 | .Items.FirstOrDefault() as IIfcExtrudedAreaSolid)
51 | .SweptArea is IIfcIShapeProfileDef) return true; else return false; }).ToList();
52 |
53 |
54 | _beams = _ifcModel.Instances.OfType().Where(beam => {
55 | if ((beam.Representation.Representations.FirstOrDefault()
56 | .Items.FirstOrDefault() as IIfcExtrudedAreaSolid)
57 | .SweptArea is IIfcRectangleProfileDef) return true; else return false; }).ToList();
58 |
59 | _beamsSt = _ifcModel.Instances.OfType().Where(beam => {
60 | if ((beam.Representation.Representations.FirstOrDefault()
61 | .Items.FirstOrDefault() as IIfcExtrudedAreaSolid)
62 | .SweptArea is IIfcIShapeProfileDef) return true; else return false;}).ToList();
63 |
64 | _inclines = _ifcModel.Instances.OfType().Where(inc => {
65 | if ((inc.Representation.Representations.FirstOrDefault()
66 | .Items.FirstOrDefault() as IIfcExtrudedAreaSolid)
67 | .SweptArea is IIfcRectangleProfileDef) return true; else return false; }).ToList();
68 |
69 |
70 | _braces = _ifcModel.Instances.OfType().Where(brace => {
71 | if ((brace.Representation.Representations.FirstOrDefault()
72 | .Items.FirstOrDefault() as IIfcExtrudedAreaSolid)
73 | .SweptArea is IIfcLShapeProfileDef) return true; else return false; }).ToList();
74 |
75 | }
76 |
77 | public static List Storeys
78 | {
79 | get { return _bStoreys; }
80 | }
81 |
82 | public static List Floors
83 | {
84 | get { return _floors; }
85 | }
86 |
87 | public static List Columns
88 | {
89 | get { return _columns; }
90 | }
91 |
92 | public static List Beams
93 | {
94 | get { return _beams; }
95 | }
96 |
97 | public static List Inclines
98 | {
99 | get { return _inclines; }
100 | }
101 |
102 | public static List ColumnsSt
103 | {
104 | get { return _columnsSt; }
105 | }
106 |
107 | public static List BeamsSt
108 | {
109 | get { return _beamsSt; }
110 | }
111 |
112 | public static List Braces
113 | {
114 | get { return _braces; }
115 | }
116 |
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/RevitPlugin/Base/RelayCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 |
4 | namespace IFCtoRevit.Base
5 | {
6 | ///
7 | /// Class RelayCommand.
8 | /// Implements the
9 | ///
10 | ///
11 | ///
12 | public class RelayCommand : ICommand
13 | {
14 |
15 | #region Fields
16 |
17 | private readonly Action _execute;
18 | private readonly Predicate _canExecute;
19 |
20 | #endregion
21 |
22 | #region Constructor
23 |
24 |
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | /// The execute action.
29 | /// The can execute predicate.
30 | /// execute
31 | public RelayCommand(Action execute, Predicate canExecute = null)
32 | {
33 | _execute = execute ?? throw new NullReferenceException(nameof(execute));
34 | _canExecute = canExecute ?? (_ => true);
35 | }
36 |
37 | #endregion
38 |
39 | #region Events
40 |
41 | ///
42 | /// Occurs when changes occur that affect whether or not the command should execute.
43 | ///
44 | public event EventHandler CanExecuteChanged
45 | {
46 | add => CommandManager.RequerySuggested += value;
47 | remove => CommandManager.RequerySuggested -= value;
48 | }
49 |
50 | #endregion
51 |
52 | #region Methods
53 |
54 | ///
55 | /// Defines the method that determines whether the command can execute in its current state.
56 | ///
57 | /// Data used by the command. If the command does not require data to be passed, this object can be set to .
58 | /// if this command can be executed; otherwise, .
59 | public bool CanExecute(object parameter) => _canExecute((T)parameter);
60 |
61 |
62 | ///
63 | /// Defines the method to be called when the command is invoked.
64 | ///
65 | /// Data used by the command. If the command does not require data to be passed, this object can be set to .
66 | public void Execute(object parameter) => _execute((T)parameter);
67 |
68 | #endregion
69 |
70 | }
71 |
72 | ///
73 | /// Class RelayCommand.
74 | /// Implements the
75 | ///
76 | ///
77 | public class RelayCommand : ICommand
78 | {
79 |
80 | #region Fields
81 |
82 | private readonly Action _execute;
83 | private readonly Predicate