feat: adds method to run action wihtout transaction
This commit is contained in:
Родитель
ab34af95bb
Коммит
e0903c7869
|
@ -349,3 +349,4 @@ MigrationBackup/
|
|||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
xUnitRevit/config.json
|
||||
.idea/
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
<Reference Include="RevitAPI, Version=21.0.0.0, Culture=neutral, processorArchitecture=AMD64">
|
||||
<HintPath>..\packages\ModPlus.Revit.API.2021.1.0.0\lib\RevitAPI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RevitAPIIFC">
|
||||
<HintPath>..\..\..\..\Program Files\Autodesk\Revit 2021\RevitAPIIFC.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RevitAPIUI, Version=21.0.0.0, Culture=neutral, processorArchitecture=AMD64">
|
||||
<HintPath>..\packages\ModPlus.Revit.API.2021.1.0.0\lib\RevitAPIUI.dll</HintPath>
|
||||
</Reference>
|
||||
|
@ -64,9 +67,6 @@
|
|||
<Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xUnitRevitUtils, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xUnitRevitUtils.2021.1.0.1\lib\netstandard2.0\xUnitRevitUtils.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="SampleTest.cs" />
|
||||
|
@ -80,6 +80,12 @@
|
|||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\xUnitRevitUtils2021\xUnitRevitUtils2021.csproj">
|
||||
<Project>{977e0b63-5706-4c2b-9c01-3c02d9ebe377}</Project>
|
||||
<Name>xUnitRevitUtils2021</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.DB.IFC;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using xUnitRevitUtils;
|
||||
|
||||
|
@ -20,7 +23,7 @@ namespace SampleLibrary
|
|||
|
||||
var walls = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
|
||||
|
||||
foreach(var wall in walls)
|
||||
foreach (var wall in walls)
|
||||
{
|
||||
var volumeParam = wall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED);
|
||||
Assert.NotNull(volumeParam);
|
||||
|
@ -35,6 +38,37 @@ namespace SampleLibrary
|
|||
Assert.Equal(5, feet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetWallGrossAreaAndRollBack()
|
||||
{
|
||||
var testModel = Utils.GetTestModel("walls.rvt");
|
||||
var doc = xru.OpenDoc(testModel);
|
||||
var walls = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements();
|
||||
var wall = walls[0] as Wall;
|
||||
double grossArea = 0;
|
||||
|
||||
var inserts = wall.FindInserts(true, true, true, true);
|
||||
xru.Run(() =>
|
||||
{
|
||||
using (Transaction transaction = new Transaction(doc, "Temporary - only to get gross area"))
|
||||
{
|
||||
transaction.Start();
|
||||
foreach (ElementId insertId in inserts) { doc.Delete(insertId); }
|
||||
doc.Regenerate();
|
||||
var wallFaceReference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior);
|
||||
var face = doc.GetElement(wallFaceReference.First()).GetGeometryObjectFromReference(wallFaceReference.First()) as PlanarFace;
|
||||
var wallFaceEdges = face.GetEdgesAsCurveLoops();
|
||||
grossArea = ExporterIFCUtils.ComputeAreaOfCurveLoops(wallFaceEdges);
|
||||
transaction.RollBack();
|
||||
|
||||
}
|
||||
}, doc).Wait();
|
||||
|
||||
|
||||
|
||||
Assert.True(grossArea > 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace xUnitRevitUtils
|
|||
public static SynchronizationContext UiContext { get; set; }
|
||||
|
||||
public static void Initialize(UIApplication uiapp, SynchronizationContext uiContext, ExternalEvent eventHandler, List<Action> queue)
|
||||
{
|
||||
{
|
||||
Uiapp = uiapp;
|
||||
UiContext = uiContext;
|
||||
EventHandler = eventHandler;
|
||||
|
@ -99,15 +99,15 @@ namespace xUnitRevitUtils
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Runs an Action in a Revit transaction, uses TaskCompletionSource to communicate when done
|
||||
/// </summary>
|
||||
/// <param name="action">Action to run</param>
|
||||
/// <param name="doc">Revit Document</param>
|
||||
/// <param name="transactionName">Transaction Name</param>
|
||||
/// <param name="ignoreWarnings">Enable to swallow all warnings generated by the transaction and prevent them from being raised within Revit</param>
|
||||
/// <returns></returns>
|
||||
public static Task RunInTransaction(Action action, Document doc, string transactionName = "transaction", bool ignoreWarnings = false)
|
||||
/// <summary>
|
||||
/// Runs an Action in a Revit transaction, uses TaskCompletionSource to communicate when done
|
||||
/// </summary>
|
||||
/// <param name="action">Action to run</param>
|
||||
/// <param name="doc">Revit Document</param>
|
||||
/// <param name="transactionName">Transaction Name</param>
|
||||
/// <param name="ignoreWarnings">Enable to swallow all warnings generated by the transaction and prevent them from being raised within Revit</param>
|
||||
/// <returns></returns>
|
||||
public static Task RunInTransaction(Action action, Document doc, string transactionName = "transaction", bool ignoreWarnings = false)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<string>();
|
||||
Queue.Add(new Action(() =>
|
||||
|
@ -118,12 +118,12 @@ namespace xUnitRevitUtils
|
|||
{
|
||||
transaction.Start();
|
||||
|
||||
if (ignoreWarnings)
|
||||
{
|
||||
var options = transaction.GetFailureHandlingOptions();
|
||||
options.SetFailuresPreprocessor(new IgnoreAllWarnings());
|
||||
transaction.SetFailureHandlingOptions(options);
|
||||
}
|
||||
if (ignoreWarnings)
|
||||
{
|
||||
var options = transaction.GetFailureHandlingOptions();
|
||||
options.SetFailuresPreprocessor(new IgnoreAllWarnings());
|
||||
transaction.SetFailureHandlingOptions(options);
|
||||
}
|
||||
|
||||
action.Invoke();
|
||||
transaction.Commit();
|
||||
|
@ -142,6 +142,34 @@ namespace xUnitRevitUtils
|
|||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs an Action, uses TaskCompletionSource to communicate when done
|
||||
/// </summary>
|
||||
/// <param name="action">Action to run</param>
|
||||
/// <param name="doc">Revit Document</param>
|
||||
/// <returns></returns>
|
||||
public static Task Run(Action action, Document doc)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<string>();
|
||||
Queue.Add(new Action(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
tcs.TrySetException(e);
|
||||
}
|
||||
tcs.TrySetResult("");
|
||||
}));
|
||||
|
||||
EventHandler.Raise();
|
||||
|
||||
return tcs.Task;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A failures preprocesser that clears any failures that occur within a transaction
|
||||
/// </summary>
|
||||
|
@ -150,17 +178,17 @@ namespace xUnitRevitUtils
|
|||
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
|
||||
{
|
||||
var failList = failuresAccessor.GetFailureMessages();
|
||||
|
||||
|
||||
foreach (FailureMessageAccessor failure in failList)
|
||||
{
|
||||
failuresAccessor.DeleteWarning(failure);
|
||||
}
|
||||
|
||||
|
||||
return FailureProcessingResult.Continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче