-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fdb374
commit 4faf2d8
Showing
14 changed files
with
412 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
source/FloorCreatorExample/Commands/FloorCreatorCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Autodesk.Revit.Attributes; | ||
using FloorCreatorExample.ViewModels; | ||
using FloorCreatorExample.Views; | ||
using Nice3point.Revit.Toolkit.External; | ||
|
||
namespace FloorCreatorExample.Commands | ||
{ | ||
/// <summary> | ||
/// External command entry point invoked from the Revit interface | ||
/// </summary> | ||
[UsedImplicitly] | ||
[Transaction(TransactionMode.Manual)] | ||
public class FloorCreatorCommand : ExternalCommand | ||
{ | ||
public override void Execute() | ||
{ | ||
var viewModel = new FloorCreatorExampleViewModel(); | ||
var view = new FloorCreatorExampleView(viewModel); | ||
viewModel.CloseRequest += (s, e) => view.Close(); | ||
viewModel.HideRequest += (s, e) => view.Hide(); | ||
viewModel.ShowRequest += (s, e) => view.ShowDialog(); | ||
view.ShowDialog(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Autodesk.Revit.DB.Architecture; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FloorCreatorExample.Core | ||
{ | ||
public static class FloorCreator | ||
{ | ||
public static void CreateFloors(ElementType floorType, Room[] rooms) | ||
{ | ||
var options = new SpatialElementBoundaryOptions() | ||
{ | ||
SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Finish, | ||
StoreFreeBoundaryFaces = true | ||
}; | ||
var ids = new List<ElementId>(); | ||
using var transaction = new Transaction(floorType.Document); | ||
transaction.Start("Create floors"); | ||
foreach (var room in rooms) | ||
{ | ||
var segments = room.GetBoundarySegments(options).First(); | ||
var loop = new CurveLoop(); | ||
foreach (var segment in segments) | ||
{ | ||
loop.Append(segment.GetCurve()); | ||
} | ||
var list = new List<CurveLoop>() { loop }; | ||
var floor = Floor.Create(floorType.Document, list, floorType.Id, room.LevelId); | ||
ids.Add(floor.Id); | ||
} | ||
transaction.Commit(); | ||
Context.ActiveUiDocument.Selection.SetElementIds(ids); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Autodesk.Revit.DB.Architecture; | ||
using Autodesk.Revit.UI.Selection; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FloorCreatorExample.Core | ||
{ | ||
public class RoomSelectionFilter : ISelectionFilter | ||
{ | ||
public bool AllowElement(Element elem) | ||
{ | ||
return elem is Room; | ||
} | ||
|
||
public bool AllowReference(Reference reference, XYZ position) | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<UseWPF>true</UseWPF> | ||
<LangVersion>latest</LangVersion> | ||
<PlatformTarget>x64</PlatformTarget> | ||
<ImplicitUsings>true</ImplicitUsings> | ||
<Configurations>Debug R20;Debug R21;Debug R22;Debug R23;Debug R24;Debug R25</Configurations> | ||
<Configurations>$(Configurations);Release R20;Release R21;Release R22;Release R23;Release R24;Release R25</Configurations> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="$(Configuration.Contains('R20'))"> | ||
<RevitVersion>2020</RevitVersion> | ||
<TargetFramework>net48</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(Configuration.Contains('R21'))"> | ||
<RevitVersion>2021</RevitVersion> | ||
<TargetFramework>net48</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(Configuration.Contains('R22'))"> | ||
<RevitVersion>2022</RevitVersion> | ||
<TargetFramework>net48</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(Configuration.Contains('R23'))"> | ||
<RevitVersion>2023</RevitVersion> | ||
<TargetFramework>net48</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(Configuration.Contains('R24'))"> | ||
<RevitVersion>2024</RevitVersion> | ||
<TargetFramework>net48</TargetFramework> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(Configuration.Contains('R25'))"> | ||
<RevitVersion>2025</RevitVersion> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Nice3point.Revit.Build.Tasks" Version="1.*" /> | ||
<PackageReference Include="Nice3point.Revit.Toolkit" Version="$(RevitVersion).*" /> | ||
<PackageReference Include="Nice3point.Revit.Extensions" Version="$(RevitVersion).*" /> | ||
<PackageReference Include="Nice3point.Revit.Api.RevitAPI" Version="$(RevitVersion).*" /> | ||
<PackageReference Include="Nice3point.Revit.Api.RevitAPIUI" Version="$(RevitVersion).*" /> | ||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Models" /> | ||
</ItemGroup> | ||
|
||
</Project> |
73 changes: 73 additions & 0 deletions
73
source/FloorCreatorExample/ViewModels/FloorCreatorExampleViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Autodesk.Revit.DB.Architecture; | ||
using Autodesk.Revit.UI.Selection; | ||
using FloorCreatorExample.Core; | ||
using System.Collections.ObjectModel; | ||
|
||
namespace FloorCreatorExample.ViewModels | ||
{ | ||
public sealed partial class FloorCreatorExampleViewModel : ObservableObject | ||
{ | ||
[ObservableProperty] private ElementType _selectedFloorType; | ||
[ObservableProperty] private ElementType[] _floorTypes; | ||
[ObservableProperty] private Room[] _rooms = []; | ||
|
||
public FloorCreatorExampleViewModel() | ||
{ | ||
FloorTypes = Context.ActiveDocument | ||
.EnumerateTypes<FloorType>() | ||
.ToArray(); | ||
} | ||
|
||
[RelayCommand] | ||
private void SelectRooms() | ||
{ | ||
RaiseHideRequest(); | ||
|
||
var references = Context.ActiveUiDocument.Selection.PickObjects(ObjectType.Element, | ||
new RoomSelectionFilter(), | ||
"Select rooms"); | ||
|
||
Rooms = references | ||
.Select(reference => (Room)Context.ActiveDocument.GetElement(reference)) | ||
.ToArray(); | ||
|
||
RaiseShowRequest(); | ||
} | ||
|
||
[RelayCommand] | ||
private void CreateFloors() | ||
{ | ||
try | ||
{ | ||
FloorCreator.CreateFloors(SelectedFloorType, Rooms); | ||
} | ||
finally | ||
{ | ||
RaiseCloseRequest(); | ||
} | ||
} | ||
|
||
|
||
public event EventHandler CloseRequest; | ||
|
||
private void RaiseCloseRequest() | ||
{ | ||
CloseRequest?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
public event EventHandler HideRequest; | ||
|
||
private void RaiseHideRequest() | ||
{ | ||
HideRequest?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
public event EventHandler ShowRequest; | ||
|
||
private void RaiseShowRequest() | ||
{ | ||
ShowRequest?.Invoke(this, EventArgs.Empty); | ||
} | ||
|
||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
source/FloorCreatorExample/Views/Converters/BoolVisibilityConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
using System.Windows.Markup; | ||
using Visibility = System.Windows.Visibility; | ||
|
||
namespace FloorCreatorExample.Views.Converters | ||
{ | ||
public class BoolVisibilityConverter : MarkupExtension, IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return (bool)value! ? Visibility.Visible : Visibility.Hidden; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return (Visibility)value! == Visibility.Visible; | ||
} | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
return this; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
source/FloorCreatorExample/Views/Converters/EnumVisibilityConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
using System.Windows.Markup; | ||
using Visibility = System.Windows.Visibility; | ||
|
||
namespace FloorCreatorExample.Views.Converters | ||
{ | ||
public class EnumVisibilityConverter<TEnum> : MarkupExtension, IValueConverter where TEnum : Enum | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is not TEnum valueEnum) | ||
{ | ||
throw new ArgumentException($"{nameof(value)} is not type: {typeof(TEnum)}"); | ||
} | ||
|
||
if (parameter is not TEnum parameterEnum) | ||
{ | ||
throw new ArgumentException($"{nameof(parameter)} is not type: {typeof(TEnum)}"); | ||
} | ||
|
||
return EqualityComparer<TEnum>.Default.Equals(valueEnum, parameterEnum) ? Visibility.Visible : Visibility.Hidden; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
return this; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
source/FloorCreatorExample/Views/Converters/InverseBoolConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
using System.Windows.Markup; | ||
|
||
namespace FloorCreatorExample.Views.Converters | ||
{ | ||
public class InverseBoolConverter : MarkupExtension, IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return !(bool)value!; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return !(bool)value!; | ||
} | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
return this; | ||
} | ||
} | ||
} |
Oops, something went wrong.