Skip to content

Commit

Permalink
some more improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
salaros committed Apr 27, 2023
1 parent 86a8bc3 commit 83111cc
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 64 deletions.
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project>

<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<NetStandardVersion>netstandard2.1</NetStandardVersion>
<NetCoreAppVersion>netcoreapp3.1</NetCoreAppVersion>
<NetCoreAppVersion>net6.0</NetCoreAppVersion>
</PropertyGroup>

<PropertyGroup>
<ResolveNuGetPackages>true</ResolveNuGetPackages>
<NetCorePackageVersion>3.1.3</NetCorePackageVersion>
<EFCorePackageVersion>3.1.3</EFCorePackageVersion>
<NetCorePackageVersion>6.0.*</NetCorePackageVersion>
<EFCorePackageVersion>6.0.*</EFCorePackageVersion>
</PropertyGroup>

<!-- Output-related settings -->
Expand Down
6 changes: 3 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<!-- FxCop Analyzer-related configuration -->
<ItemGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0*">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -49,15 +49,15 @@

<!-- Sonar Analyzer-related configuration -->
<ItemGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.6.*">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.0.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Code Analyzers for projects using xUnit.net that help find and fix frequent issues when writing tests -->
<ItemGroup Condition="'$(BuildingInsideVisualStudio)' == 'true' And '$(IsTestProject)' == 'true'">
<PackageReference Include="xunit.analyzers" Version="0.10.0">
<PackageReference Include="xunit.analyzers" Version="1.1.*">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 1 addition & 4 deletions src/Addin/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public sealed class App : IExternalApplication
/// </summary>
static App()
{
#if WINFORMS
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
#endif

}

/// <summary>
Expand Down
27 changes: 26 additions & 1 deletion src/Addin/CodeCave.Threejs.Revit.Exporter.Addin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
e.g. if you want to debug ONLY Revit 2019,
put net47 below and switch to 'Debug One' configuration
-->
<TargetFrameworks>net471</TargetFrameworks>
<TargetFrameworks>net48</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' ">
<RevitVersion>2014</RevitVersion>
Expand Down Expand Up @@ -98,6 +98,7 @@
<PackageReference Include="Autodesk.Revit.SDK" Version="2019.*" Condition=" '$(RevitVersion)' == '2019' " PrivateAssets="All" />
<PackageReference Include="Autodesk.Revit.SDK" Version="2020.*" Condition=" '$(RevitVersion)' == '2020' " PrivateAssets="All" />
<PackageReference Include="Autodesk.Revit.SDK" Version="2021.*" Condition=" '$(RevitVersion)' == '2021' " PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.*" />
</ItemGroup>
<Target Name="PreventRevitSDKCopyLocal" AfterTargets="ResolveReferences">
<ItemGroup>
Expand Down Expand Up @@ -126,6 +127,11 @@
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="AlwaysOverwriteFamilyLoadOptions.cs" />
<Compile Include="Extensions\DocumentExtension.cs" />
<Compile Include="FamilyExportEventArgs.cs" />
<Compile Include="FamilySymbolExportEventArgs.cs" />
<Compile Include="HeadlessExporter.cs" />
<Compile Include="RvtExporterCommand.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="RfaExporterCommand.cs" />
Expand All @@ -134,12 +140,31 @@
<Compile Include="Ribbon\RibbonHelper.cs" />
<Compile Include="App.cs" />
<Compile Include="ExternalCommand.cs" />
<Compile Include="Extensions\ColorExtensions.cs" />
<Compile Include="Extensions\DocumentTransactionExtension.cs" />
<Compile Include="Extensions\DoubleExtensions.cs" />
<Compile Include="Extensions\ElementCollectorExtension.cs" />
<Compile Include="Extensions\ElementExtensions.cs" />
<Compile Include="Extensions\EnumeratorExtensions.cs" />
<Compile Include="Extensions\ViewExtensions.cs" />
<Compile Include="StringLocalizer.cs" />
<Compile Include="SuppressErrorsFailureHandler.cs" />
<Compile Include="ZeroDocStateAvailability.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Exporter\CodeCave.Threejs.Revit.Exporter.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\ExportScene.rvt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Update="Resources\FamilyTemplate.rft">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Update="Resources\SpecifiLayersMap.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<PropertyGroup>
<RootNamespace>CodeCave.Threejs.Revit.Exporter.Addin</RootNamespace>
<AssemblyName>Threejs.Exporter.Addin</AssemblyName>
Expand Down
6 changes: 5 additions & 1 deletion src/Addin/Ribbon/RibbonButton{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ internal class RibbonButton<T> : RibbonButton
/// </summary>
public RibbonButton()
{
var thisNamespace = GetType().Namespace;
commandAssemly = typeof(T).Assembly;
rootNameSpace = typeof(T).Assembly.ManifestModule.GetTypes().Min(t => t.Namespace);
rootNameSpace = typeof(T).Assembly.ManifestModule
.GetTypes()
.Where(t => t.Namespace is not null && t.Namespace.StartsWith(thisNamespace, StringComparison.OrdinalIgnoreCase))
.Min(t => t.Namespace) ?? thisNamespace;
}

/// <inheritdoc />
Expand Down
32 changes: 11 additions & 21 deletions src/Exporter/CodeCave.Threejs.Revit.Exporter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,34 @@
2020 | net472
2021 | net48
-->
<TargetFrameworks>net48;net472;net471;net461</TargetFrameworks>
<TargetFrameworks>net48;net472;net471</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="$(Configuration.Contains('Debug'))">
<TargetFrameworks>net471</TargetFrameworks>
<TargetFrameworks>net48</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
<IsPackable>true</IsPackable>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>0.1.4</Version>
<FileVersion>0.1.4</FileVersion>
<AssemblyVersion>0.1.4</AssemblyVersion>
<Version>0.1.7</Version>
<FileVersion>0.1.7</FileVersion>
<AssemblyVersion>0.1.7</AssemblyVersion>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/CodeCavePro/threejs-revit-exporter.git</PackageProjectUrl>
<RepositoryUrl>https://github.com/CodeCavePro/threejs-revit-exporter.git</RepositoryUrl>
<PackageTags>nuget, package, library, three.js, revit, export</PackageTags>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net461' ">
<RevitVersion>2018</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net471' ">
<RevitVersion>2019</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net472' ">
<RevitVersion>2020</RevitVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net48' ">
<RevitVersion>2021</RevitVersion>
</PropertyGroup>

<PropertyGroup>
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
<DefineConstants>RVT$(RevitVersion)</DefineConstants>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CodeCave.Threejs.Entities" Version="[0.7.*, 0.8)" />
<PackageReference Include="Newtonsoft.Json" Version="[10.0.1, 13.1)" />
<PackageReference Include="Newtonsoft.Json" Version="[12.0.*, 13.1)" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net40' ">
Expand Down Expand Up @@ -90,7 +76,11 @@
<PackageReference Include="Autodesk.Revit.SDK" Version="2018.*" Condition=" '$(RevitVersion)' == '2018' " />
<PackageReference Include="Autodesk.Revit.SDK" Version="2019.*" Condition=" '$(RevitVersion)' == '2019' " />
<PackageReference Include="Autodesk.Revit.SDK" Version="2020.*" Condition=" '$(RevitVersion)' == '2020' " />
<PackageReference Include="Autodesk.Revit.SDK" Version="2021.*" Condition=" '$(RevitVersion)' == '2021' " />
<PackageReference Include="Autodesk.Revit.SDK" Version="(2021.*, 2025]" Condition=" '$(RevitVersion)' == '2021' " />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\threejs-entities\src\CodeCave.Threejs.Entities.csproj" />
</ItemGroup>

</Project>
89 changes: 72 additions & 17 deletions src/Exporter/FamilyExporter/FamilyExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ public void ExportRfaFile(Document docWrapper, View3D view3d, string rfaFilePath

if (family is null)
{
using var t = new Transaction(docWrapper, $"Load the family '{familyName}'");
t.Start();
using var tr = new Transaction(docWrapper, $"Load the family '{familyName}'");
tr.Start();

if (!docWrapper.LoadFamily(rfaFilePath, out family))
throw new InvalidOperationException();
t.Commit();

tr.Commit();
}

foreach (var typElementId in family.GetFamilySymbolIds())
Expand All @@ -95,8 +97,8 @@ public void ExportRfaFile(Document docWrapper, View3D view3d, string rfaFilePath
var familyTypeExportArgs = new FamilySymbolExportEventArgs { FamilyFilePath = rfaFilePath, Symbol = familySymbol?.Name, OutputFilePath = outputFilePath };
this?.OnSymbolExportStarted(familyTypeExportArgs);

if (string.IsNullOrWhiteSpace(outputFilePath) || File.Exists(outputFilePath))
continue;
if (string.IsNullOrWhiteSpace(outputFilePath))
throw new InvalidDataException();

using (var t = new Transaction(docWrapper, $"Placing family instance '{familySymbol.Name}'"))
{
Expand All @@ -109,6 +111,7 @@ public void ExportRfaFile(Document docWrapper, View3D view3d, string rfaFilePath
familySymbol,
StructuralType.NonStructural);

docWrapper.Regenerate();
t.Commit();
}

Expand All @@ -128,26 +131,78 @@ public void ExportRfaFile(Document docWrapper, View3D view3d, string rfaFilePath

this?.OnSymbolExportEnded(familyTypeExportArgs);

using (var t = new Transaction(docWrapper, $"Remove family symbol '{familyInstance.Name}'"))
{
t.Start();
docWrapper.Delete(familySymbol.Id);
t.Commit();
}
using var tr2 = new Transaction(docWrapper, $"Remove family symbol '{familyInstance.Name}'");
tr2.Start();
docWrapper.Delete(familySymbol.Id);
tr2.Commit();

familyInstance.Dispose();
}

this?.OnExportEnded(familyExportArgs);

using (var t = new Transaction(docWrapper, $"Remove family '{family.Name}'"))
using var td = new Transaction(docWrapper, $"Remove family '{family.Name}'");
td.Start();
docWrapper.Delete(family.Id);
td.Commit();

family.Dispose();
}

private void HideClearances(View3D view3D)
{
var specialtyEquipmentCategory = view3D.Document.Settings.Categories.get_Item(BuiltInCategory.OST_SpecialityEquipment);
var specialtySubcats = specialtyEquipmentCategory.SubCategories.Cast<Category>().ToList();
var clearanceSubCategories = specialtySubcats.Where(s => s.Name.ToUpperInvariant().Contains("CLEARANCE")).ToArray();

if (clearanceSubCategories.Any())
{
t.Start();
docWrapper.Delete(family.Id);
t.Commit();
using var subTransaction = new SubTransaction(view3D.Document);
subTransaction.Start();

try
{
foreach (Category category in clearanceSubCategories.OfType<Category>())
{
if (category.get_AllowsVisibilityControl(view3D))
category.set_Visible(view3D, false);
}
}
catch (Exception ex)
{
// TODO add logging
}

subTransaction.Commit();
}

family.Dispose();
foreach (var specialtySubCategory in specialtySubcats)
specialtySubCategory.Dispose();

specialtyEquipmentCategory?.Dispose();
}

private FamilyInstance InsertFamilySymbol(FamilySymbol familySymbol)
{
// TODO add logging
// logger.LogInformation($"Placing family instance '{familySymbol.Name}' in XYZ(0,0,0)");

var docWrapper = familySymbol.Family.Document;
using var subTransaction = new SubTransaction(docWrapper);
subTransaction.Start();

if (!familySymbol.IsActive)
familySymbol.Activate();

var familyInstance = docWrapper.Create.NewFamilyInstance(
XYZ.Zero,
familySymbol,
StructuralType.NonStructural
);

subTransaction.Commit();

return familyInstance;
}

public void ExportRvtFile(UIApplication uiapp, string projectPath)
Expand Down Expand Up @@ -176,8 +231,8 @@ public void ExportRvtFile(UIApplication uiapp, string projectPath)
{
TaskDialog.Show("Error", $"Failed to export '{projectPath}'");
}
var objectSceneJson = objectScene.ToString();

var objectSceneJson = objectScene.ToString();
var outputFilePath = Path.ChangeExtension(projectPath, ".json");
File.WriteAllText(outputFilePath, objectSceneJson);
}
Expand Down
11 changes: 4 additions & 7 deletions src/Exporter/Helpers/ObjectSceneExportContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Lighting;
using CodeCave.Threejs.Entities;
using CodeCave.Threejs.Revit.Exporter.Helpers;

Expand Down Expand Up @@ -128,7 +127,8 @@ public void OnViewEnd(ElementId elementId)
current.Element.AddChild(obj);
}

outputScene.Object.AddChild(current.Element);
if (current.Element is not null)
outputScene.Object.AddChild(current.Element);
}
catch (Exception ex)
{
Expand All @@ -153,9 +153,6 @@ public RenderNodeAction OnElementBegin(ElementId elementId)
if (element is null || string.IsNullOrWhiteSpace(uid))
throw new InvalidDataException();

//if (element is Autodesk.Revit.DB.Group || element is Level)
// return RenderNodeAction.Skip;

Debug.WriteLine($"OnElementBegin: id {elementId.IntegerValue} category {element.Category?.Name} name {element.Name}");

if (outputScene.Object.HasChild(uid))
Expand Down Expand Up @@ -212,8 +209,8 @@ public void OnElementEnd(ElementId elementId)
if (element is null || string.IsNullOrWhiteSpace(uid))
throw new InvalidDataException();

//if (element is Autodesk.Revit.DB.Group || element is Level)
// return;
if (element is Level) // Skip levels
return;

Debug.WriteLine($"OnElementEnd: id {elementId.IntegerValue} category {element.Category.Name} name {element.Name}");

Expand Down
7 changes: 1 addition & 6 deletions src/Exporter/Helpers/ObjectSceneExporter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.IO;
using System.Linq;
using Autodesk.Revit.DB;
using CodeCave.Threejs.Entities;

Expand Down Expand Up @@ -67,14 +66,10 @@ public bool TryExport(View3D viewToExport, out ObjectScene outputScene, bool thr
outputScene = this.context.GetResult();
return outputScene?.Object != null;
}
catch (Exception) when (!throwException)
catch when (!throwException)
{
return false;
}
catch
{
throw;
}
}
}
}

0 comments on commit 83111cc

Please sign in to comment.