Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c594112ff |
+1
@@ -32,6 +32,7 @@ public static class Civil3dConnectorModule
|
||||
// additional classes
|
||||
serviceCollection.AddScoped<PropertySetDefinitionHandler>();
|
||||
serviceCollection.AddScoped<PropertySetBaker>();
|
||||
serviceCollection.AddScoped<CutFillHelper>();
|
||||
|
||||
// automatically detects the Class:IClass interface pattern to register all generated interfaces
|
||||
serviceCollection.AddMatchingInterfacesAsTransient(Assembly.GetExecutingAssembly());
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
using Autodesk.AutoCAD.DatabaseServices;
|
||||
using Autodesk.Civil.ApplicationServices;
|
||||
using Autodesk.Civil.DatabaseServices;
|
||||
using Speckle.Converters.Civil3dShared;
|
||||
using Speckle.Converters.Common;
|
||||
using Speckle.Sdk.Common;
|
||||
using Surface = Autodesk.Civil.DatabaseServices.Surface;
|
||||
|
||||
namespace Speckle.Connectors.Civil3dShared.HostApp;
|
||||
|
||||
public class CutFillHelper
|
||||
{
|
||||
private readonly IConverterSettingsStore<Civil3dConversionSettings> _settingsStore;
|
||||
|
||||
public CutFillHelper(IConverterSettingsStore<Civil3dConversionSettings> settingsStore)
|
||||
{
|
||||
_settingsStore = settingsStore;
|
||||
}
|
||||
|
||||
public Dictionary<string, double> GetVolumesFromVolumeSurface(string surfaceName)
|
||||
{
|
||||
Database db = _settingsStore.Current.Document.Database;
|
||||
var results = new Dictionary<string, double>();
|
||||
|
||||
using Transaction tr = db.TransactionManager.StartTransaction();
|
||||
|
||||
var volumeSurfaceId = GetVolumeSurfaceByName(db, surfaceName);
|
||||
|
||||
if (volumeSurfaceId == ObjectId.Null)
|
||||
{
|
||||
tr.Commit();
|
||||
return results;
|
||||
}
|
||||
|
||||
var volSurface = tr.GetObject(volumeSurfaceId, OpenMode.ForRead) as TinVolumeSurface;
|
||||
VolumeSurfaceProperties props = volSurface.NotNull().GetVolumeProperties();
|
||||
// var props = volSurface?.Analysis.;
|
||||
|
||||
Units.GetConversionFactor(Units.Millimeters, _settingsStore.Current.SpeckleUnits);
|
||||
results["CutVolume"] = props.AdjustedCutVolume / 27.0;
|
||||
results["FillVolume"] = props.AdjustedFillVolume / 27.0;
|
||||
results["NetVolume"] = props.AdjustedNetVolume / 27.0;
|
||||
|
||||
tr.Commit();
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<string> GetAllVolumeSurfaceNames(Database db)
|
||||
{
|
||||
var volumeSurfaceNames = new List<string>();
|
||||
|
||||
using Transaction tr = db.TransactionManager.StartTransaction();
|
||||
|
||||
var civilDoc = CivilApplication.ActiveDocument;
|
||||
|
||||
foreach (ObjectId surfaceId in civilDoc.GetSurfaceIds())
|
||||
{
|
||||
var volSurface = tr.GetObject(surfaceId, OpenMode.ForRead) as TinVolumeSurface;
|
||||
|
||||
if (volSurface != null)
|
||||
{
|
||||
volumeSurfaceNames.Add(volSurface.Name);
|
||||
}
|
||||
}
|
||||
|
||||
tr.Commit();
|
||||
|
||||
return volumeSurfaceNames;
|
||||
}
|
||||
|
||||
private ObjectId GetVolumeSurfaceByName(Database db, string surfaceName)
|
||||
{
|
||||
using Transaction tr = db.TransactionManager.StartTransaction();
|
||||
|
||||
var civilDoc = CivilApplication.ActiveDocument;
|
||||
|
||||
foreach (ObjectId surfaceId in civilDoc.GetSurfaceIds())
|
||||
{
|
||||
var surface = tr.GetObject(surfaceId, OpenMode.ForRead) as Surface;
|
||||
|
||||
if (surface is TinVolumeSurface && surface.Name == surfaceName)
|
||||
{
|
||||
tr.Commit();
|
||||
return surfaceId;
|
||||
}
|
||||
}
|
||||
|
||||
tr.Commit();
|
||||
|
||||
return ObjectId.Null;
|
||||
}
|
||||
}
|
||||
+5
@@ -2,6 +2,7 @@ using Autodesk.AutoCAD.DatabaseServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Speckle.Connectors.Autocad.HostApp;
|
||||
using Speckle.Connectors.Autocad.Operations.Send;
|
||||
using Speckle.Connectors.Civil3dShared.HostApp;
|
||||
using Speckle.Connectors.Common.Caching;
|
||||
using Speckle.Connectors.Common.Operations;
|
||||
using Speckle.Converters.Autocad;
|
||||
@@ -16,10 +17,12 @@ public sealed class Civil3dRootObjectBuilder : AutocadRootObjectBaseBuilder
|
||||
{
|
||||
private readonly AutocadLayerUnpacker _layerUnpacker;
|
||||
private readonly PropertySetDefinitionHandler _propertySetDefinitionHandler;
|
||||
private readonly CutFillHelper _cutFillHelper;
|
||||
|
||||
public Civil3dRootObjectBuilder(
|
||||
AutocadLayerUnpacker layerUnpacker,
|
||||
PropertySetDefinitionHandler propertySetDefinitionHandler,
|
||||
CutFillHelper cutFillHelper,
|
||||
IRootToSpeckleConverter converter,
|
||||
IConverterSettingsStore<AutocadConversionSettings> converterSettings,
|
||||
ISendConversionCache sendConversionCache,
|
||||
@@ -44,6 +47,7 @@ public sealed class Civil3dRootObjectBuilder : AutocadRootObjectBaseBuilder
|
||||
{
|
||||
_layerUnpacker = layerUnpacker;
|
||||
_propertySetDefinitionHandler = propertySetDefinitionHandler;
|
||||
_cutFillHelper = cutFillHelper;
|
||||
}
|
||||
|
||||
public override (Collection, LayerTableRecord?) CreateObjectCollection(Entity entity, Transaction tr)
|
||||
@@ -55,6 +59,7 @@ public sealed class Civil3dRootObjectBuilder : AutocadRootObjectBaseBuilder
|
||||
|
||||
public override void AddAdditionalProxiesToRoot(Collection rootObject)
|
||||
{
|
||||
rootObject["cutFill"] = _cutFillHelper.GetVolumesFromVolumeSurface("Surface02");
|
||||
rootObject[ProxyKeys.PROPERTYSET_DEFINITIONS] = _propertySetDefinitionHandler.Definitions;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -11,6 +11,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bindings\Civil3dReceiveBinding.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DependencyInjection\Civil3dConnectorModule.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HostApp\CutFillHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HostApp\PropertySetBaker.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Operations\Receive\Civil3dHostObjectBuilder.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Operations\Send\Civil3dRootObjectBuilder.cs" />
|
||||
@@ -18,7 +19,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="$(MSBuildThisFileDirectory)DependencyInjection\" />
|
||||
<Folder Include="$(MSBuildThisFileDirectory)HostApp\" />
|
||||
<Folder Include="$(MSBuildThisFileDirectory)Operations\Receive\" />
|
||||
<Folder Include="$(MSBuildThisFileDirectory)Operations\Send\" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user