Skip to content

Commit

Permalink
Feat(Revit): add length prop to materialQuantities (#2025)
Browse files Browse the repository at this point in the history
* length added to material quantities

* conversion factor updated

* don't hardcode units

Co-authored-by: Kilian Speiser <[email protected]>
Co-authored-by: Connor Ivy <[email protected]>
  • Loading branch information
3 people authored Dec 21, 2022
1 parent 54061bb commit 2a925eb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ public void GetAllRevitParamsAndIds(Base speckleElement, DB.Element revitElement
}
}

//NOTE: adds the quantities of all materials to an element
var qs = MaterialQuantitiesToSpeckle(revitElement, speckleElement["units"] as string);
if (qs != null)
speckleElement["materialQuantities"] = qs;
}

//private List<string> alltimeExclusions = new List<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,6 @@ public Base ConvertToSpeckle(object @object)
}
}

//NOTE: adds the quantities of all materials to an element
if (returnObject != null && !(returnObject is Model))
{
try
{
var qs = MaterialQuantitiesToSpeckle(@object as DB.Element);
if (qs != null)
{
returnObject["materialQuantities"] = new List<Base>();
(returnObject["materialQuantities"] as List<Base>).AddRange(qs);
}
else returnObject["materialQuantities"] = null;
}
catch (System.Exception e)
{
notes.Add(e.Message);
}
}

// log
var reportObj = Report.GetReportObject(id, out int index) ? Report.ReportObjects[index] : null;
if (reportObj != null && notes.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,48 @@ public partial class ConverterRevit
/// <param name="element"></param>
/// <param name="material"></param>
/// <returns></returns>
public Objects.Other.MaterialQuantity MaterialQuantityToSpeckle(DB.Element element, DB.Material material)
public Objects.Other.MaterialQuantity MaterialQuantityToSpeckle(DB.Element element, DB.Material material, string units)
{
if (material == null || element == null) return null;
if (material == null || element == null)
return null;

//Get quantities
double volume = element.GetMaterialVolume(material.Id);
double area = element.GetMaterialArea(material.Id, false); //To-Do: Do we need Paint-Materials

//Convert Feet to meters
string units = Speckle.Core.Kits.Units.Meters;
double factor = Speckle.Core.Kits.Units.GetConversionFactor(Speckle.Core.Kits.Units.Feet, units);
// Convert revit interal units to speckle commit units
double factor = ScaleToSpeckle(1);
volume *= factor * factor * factor;
area *= factor * factor;

//Create and return materialquantity
var speckleMaterial = ConvertAndCacheMaterial(material.Id, material.Document);
return new Objects.Other.MaterialQuantity(speckleMaterial, volume, area, units);
var materialQuantity = new Objects.Other.MaterialQuantity(speckleMaterial, volume, area, units);

if (LocationToSpeckle(element) is ICurve curve)
materialQuantity["length"] = curve.length;

return materialQuantity;
}

#endregion

#region MaterialQuantities
public IEnumerable<Objects.Other.MaterialQuantity> MaterialQuantitiesToSpeckle(DB.Element element)
public IEnumerable<Objects.Other.MaterialQuantity> MaterialQuantitiesToSpeckle(DB.Element element, string units)
{
var matIDs = element?.GetMaterialIds(false);
if (matIDs == null || matIDs.Count() == 0)
return null;

var materials = matIDs.Select(material => element.Document.GetElement(material) as DB.Material);
return MaterialQuantitiesToSpeckle(element, materials);
return MaterialQuantitiesToSpeckle(element, materials, units);
}
public IEnumerable<Objects.Other.MaterialQuantity> MaterialQuantitiesToSpeckle(DB.Element element, IEnumerable<DB.Material> materials)
public IEnumerable<Objects.Other.MaterialQuantity> MaterialQuantitiesToSpeckle(DB.Element element, IEnumerable<DB.Material> materials, string units)
{
if (materials == null || materials.Count() == 0) return null;
List<Objects.Other.MaterialQuantity> quantities = new List<Objects.Other.MaterialQuantity>();

foreach (var material in materials)
quantities.Add(MaterialQuantityToSpeckle(element, material));
quantities.Add(MaterialQuantityToSpeckle(element, material, units));

return quantities;
}
Expand Down
3 changes: 2 additions & 1 deletion Objects/Objects/Other/MaterialQuantity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Objects.Other
{
public class MaterialQuantity : Base
{
[DetachProperty]
public Objects.Other.Material material { get; set; }
public double volume { get; set; }

Expand All @@ -18,7 +19,7 @@ public class MaterialQuantity : Base
public double area { get; set; }

/// <summary>
/// UnitMeasure of the quantity,e.g meters implies aquaremeters for area and cubicmeters for the volume
/// UnitMeasure of the quantity,e.g meters implies squaremeters for area and cubicmeters for the volume
/// </summary>
public string units { get; set; }

Expand Down

0 comments on commit 2a925eb

Please sign in to comment.