Skip to content

Commit

Permalink
feat(rvt): Adds Block to Family conversion (specklesystems#2884)
Browse files Browse the repository at this point in the history
* fix(rvt): Make revit converter Doc non-static

* feat(rvt): First run at Block->Family conversion

* temp: Commit to not loose current state

* fix(rvt): temp category assignment to family

* feat(rvt): New mapping option for blocks to family

* fix(rvt): Reformat block file

* feat(rvt): Magical Transform.Decompose fix. Pending cleanup

* fix(rvt): Use DirectShape in family document+ cleanup

* feat(rvt): Add Block template for 2023

* feat(rvt): 2022 and 2024 block templates. Kudos to Pavol

* feat(rvt): 2020 and 2021 Block template + extension correct for 23 and 24

* fix(rvt): Remove converter block suffix

* feat(rvt): Block converter docs + reshuffle
  • Loading branch information
AlanRynne authored Sep 5, 2023
1 parent 7bd5988 commit 49bcaf7
Show file tree
Hide file tree
Showing 22 changed files with 521 additions and 216 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
},
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableRoslynAnalyzers": true,
"omnisharp.defaultLaunchSolution": "SDK.slnf",
"[dotnet][xml]": {
"editor.defaultFormatter": "ms-dotnettools.csharp",
"editor.tabSize": 2
},
"xml.format.spaceBeforeEmptyCloseTag": false
"xml.format.spaceBeforeEmptyCloseTag": false,
"dotnet.defaultSolution": "SDK.slnf"
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ private List<Schema> GetObjectSchemas(RhinoObject obj)
result.Add(existingSchema);

if (obj is InstanceObject)
{
result.Add(new BlockDefinitionViewModel());
result.Add(new RevitFamilyInstanceViewModel());
}
else
switch (obj.Geometry)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ private void AddRevitInfoToSchema(List<Schema> schemas)
//no need to do extra stuff
if (
schema is DirectShapeFreeformViewModel
|| schema is BlockDefinitionViewModel
|| schema is RevitTopographyViewModel
|| schema is RevitDefaultWallViewModel
|| schema is RevitDefaultFloorViewModel
Expand Down
53 changes: 52 additions & 1 deletion DesktopUI2/DesktopUI2/ViewModels/MappingTool/Schemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.Serialization;
using Objects.BuiltElements;
using Objects.BuiltElements.Revit;
using Objects.Other;
using Objects.BuiltElements.Revit.RevitRoof;
using ReactiveUI;
using Speckle.Core.Api;
Expand Down Expand Up @@ -378,7 +379,6 @@ public DirectShapeFreeformViewModel()
.Select(x => x.ToString())
.OrderBy(x => x)
.ToList();
;
}

public override string Name => "DirectShape";
Expand Down Expand Up @@ -437,6 +437,57 @@ public override string GetSerializedSchema()
}
}

public class BlockDefinitionViewModel : Schema
{
private List<string> _categories;

private string _selectedCategory = RevitCategory.GenericModel.ToString();

public BlockDefinitionViewModel()
{
Categories = Enum.GetValues(typeof(RevitCategory))
.Cast<RevitCategory>()
.Select(x => x.ToString())
.OrderBy(x => x)
.ToList();
;
}

public override string Name => "New Revit Family";

public List<string> Categories
{
get => _categories;
set => this.RaiseAndSetIfChanged(ref _categories, value);
}

[DataMember]
public string SelectedCategory
{
get => _selectedCategory;
set
{
this.RaiseAndSetIfChanged(ref _selectedCategory, value);
this.RaisePropertyChanged(nameof(IsValid));
}
}
public override string Summary => $"New Revit Family - {SelectedCategory}";

public override bool IsValid => !string.IsNullOrEmpty(SelectedCategory);

public override string GetSerializedSchema()
{
var res = Enum.TryParse(SelectedCategory, out RevitCategory cat);
if (!res)
cat = RevitCategory.GenericModel;

var ds = new MappedBlockWrapper(); //don't use the constructor
ds.category = cat.ToString();

return Operations.Serialize(ds);
}
}

public class RevitDefaultWallViewModel : Schema
{
public override string Name => "Default Wall";
Expand Down
18 changes: 13 additions & 5 deletions DesktopUI2/DesktopUI2/Views/MappingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,25 @@
IsChecked="{Binding Freeform}" />-->
</StackPanel>
</DataTemplate>

<DataTemplate DataType="{x:Type s:BlockDefinitionViewModel}">
<StackPanel Orientation="Vertical" Spacing="5">
<ComboBox
assists:ComboBoxAssist.Label="Category"
Classes="Outline"
Items="{Binding Categories}"
SelectedItem="{Binding SelectedCategory, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>

</ContentControl.DataTemplates>
</ContentControl>

<!-- APPLY MAPPINGS -->
<Button
Command="{Binding SetMappingsCommand}"
Content="Apply Mappings"
IsEnabled="{Binding SelectedSchema.IsValid}"
ToolTip.Tip="Apply mappings to all the selected elements" />
Command="{Binding SetMappingsCommand}"
Content="Apply Mappings"
IsEnabled="{Binding SelectedSchema.IsValid}"
ToolTip.Tip="Apply mappings to all the selected elements" />



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,21 +634,20 @@ private Phase GetRevitPhase(DB.Document document, string phaseName)
if (applicationId == null || ReceiveMode == Speckle.Core.Kits.ReceiveMode.Create)
return null;

var cachedIds = PreviouslyReceivedObjectIds.GetCreatedIdsFromConvertedId(applicationId);
var cachedIds = PreviouslyReceivedObjectIds?.GetCreatedIdsFromConvertedId(applicationId);
// TODO: we may not want just the first one
return Doc.GetElement(cachedIds.First());
return cachedIds == null ? null : Doc.GetElement(cachedIds.First());
}

public IEnumerable<DB.Element?> GetExistingElementsByApplicationId(string applicationId)
{
if (applicationId == null || ReceiveMode == Speckle.Core.Kits.ReceiveMode.Create)
if (applicationId == null || ReceiveMode == ReceiveMode.Create)
yield break;

var cachedIds = PreviouslyReceivedObjectIds.GetCreatedIdsFromConvertedId(applicationId);
var cachedIds = PreviouslyReceivedObjectIds?.GetCreatedIdsFromConvertedId(applicationId);
if (cachedIds == null) yield break;
foreach (var id in cachedIds)
{
yield return Doc.GetElement(id);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Objects.BuiltElements.Revit;
using Objects.GIS;
using Objects.Organization;
using Objects.Other;
using Objects.Structural.Properties.Profiles;
using RevitSharedResources.Helpers;
using RevitSharedResources.Helpers.Extensions;
Expand Down Expand Up @@ -51,7 +52,7 @@ public partial class ConverterRevit : ISpeckleConverter

private const double TOLERANCE = 0.0164042; // 5mm in ft

public static Document Doc { get; private set; }
public Document Doc { get; private set; }

/// <summary>
/// <para>To know which other objects are being converted, in order to sort relationships between them.
Expand Down Expand Up @@ -444,6 +445,13 @@ private Base SwapGeometrySchemaObject(Base @object)
// item in the list.
ds.baseGeometries = new List<Base> { @object };
}
else if (speckleSchema is MappedBlockWrapper mbw)
{
if (@object is not BlockInstance bi)
throw new Exception($"{nameof(MappedBlockWrapper)} can only be used with {nameof(BlockInstance)} objects.");

mbw.instance = bi;
}
else
{
// find self referential prop and set value to @object if it is null (happens when sent from gh)
Expand All @@ -468,11 +476,11 @@ public object ConvertToNative(Base @base)
case ApplicationObject appObject:
if (appObject.Converted.Cast<Element>().ToList() is List<Element> typedList && typedList.Count >= 1)
{
receivedObjectsCache.AddConvertedObjects(@base, typedList);
receivedObjectsCache?.AddConvertedObjects(@base, typedList);
}
break;
case Element element:
receivedObjectsCache.AddConvertedObjects(@base, new List<Element> { element });
receivedObjectsCache?.AddConvertedObjects(@base, new List<Element> { element });
break;
}

Expand Down Expand Up @@ -502,9 +510,9 @@ public object ConvertToNativeObject(Base @object)
case ICurve o:
return ModelCurveToNative(o);
case Geometry.Brep o:
return FreeformElementToNativeFamily(o);
return TryDirectShapeToNative(o, ToNativeMeshSettingEnum.Default);
case Geometry.Mesh o:
return FreeformElementToNativeFamily(o);
return TryDirectShapeToNative(o, ToNativeMeshSettingEnum.Default);
case BER.FreeformElement o:
return FreeformElementToNative(o);
default:
Expand Down Expand Up @@ -694,6 +702,8 @@ public object ConvertToNativeObject(Base @object)
case Other.BlockInstance o:
return BlockInstanceToNative(o);

case Other.MappedBlockWrapper o:
return MappedBlockWrapperToNative(o);
// gis
case PolygonElement o:
return PolygonElementToNative(o);
Expand Down Expand Up @@ -846,6 +856,7 @@ public bool CanConvertToNative(Base @object)
STR.Geometry.Element1D _ => true,
STR.Geometry.Element2D _ => true,
Other.BlockInstance _ => true,
Other.MappedBlockWrapper => true,
Organization.DataTable _ => true,
// GIS
PolygonElement _ => true,
Expand Down
Loading

0 comments on commit 49bcaf7

Please sign in to comment.