Skip to content

Commit

Permalink
Jrm/parameter extraction (#365)
Browse files Browse the repository at this point in the history
* follow pattern from receive for async

* category can be null

* optimization for try get

* fmt

* Optimised Revit Parameter extraction

* returned the basic solid invalid check

---------

Co-authored-by: Adam Hathcock <adam@hathcock.uk>
Co-authored-by: Adam Hathcock <adamhathcock@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 7, 2024
1 parent dd53b70 commit 6ba70a7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ private RootObjectBuilderResult BuildSync(
var idsAndSubElementIds = _elementUnpacker.GetElementsAndSubelementIdsFromAtomicObjects(atomicObjects);
var materialProxies = _revitToSpeckleCacheSingleton.GetRenderMaterialProxyListForObjects(idsAndSubElementIds);
rootObject[ProxyKeys.RENDER_MATERIAL] = materialProxies;
// NOTE: these are currently not used anywhere, so we could even skip them (?).
rootObject[ProxyKeys.PARAMETER_DEFINITIONS] = _parameterDefinitionHandler.Definitions;

// NOTE: these are currently not used anywhere, we'll skip them until someone calls for it back
// rootObject[ProxyKeys.PARAMETER_DEFINITIONS] = _parameterDefinitionHandler.Definitions;

return new RootObjectBuilderResult(rootObject, results);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void SortGeometry(DB.Element element, List<DB.Solid> solids, List<DB.Mes
{
case DB.Solid solid:
// skip invalid solid
if (solid.Faces.Size == 0 || Math.Abs(solid.SurfaceArea) == 0)
if (solid.Faces.Size == 0)
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,30 @@ DB.Parameter parameter
{
var definition = parameter.Definition;
var internalDefinitionName = definition.Name; // aka real, internal name
var humanReadableName = definition.Name;
var humanReadableName = internalDefinitionName;
var isShared = parameter.IsShared;

if (parameter.IsShared)
if (isShared)
{
internalDefinitionName = parameter.GUID.ToString(); // Note: unsure it's needed
}

if (
definition is DB.InternalDefinition internalDefinition
&& internalDefinition.BuiltInParameter != DB.BuiltInParameter.INVALID
)
if (definition is DB.InternalDefinition internalDefinition)
{
internalDefinitionName = internalDefinition.BuiltInParameter.ToString();
var builtInParameter = internalDefinition.BuiltInParameter;
if (builtInParameter != DB.BuiltInParameter.INVALID)
{
internalDefinitionName = builtInParameter.ToString();
}
}

if (Definitions.TryGetValue(internalDefinitionName, out var def))
{
return (
internalDefinitionName,
humanReadableName,
def["group"]! as string ?? "unknown group",
def["units"]! as string
def["group"] as string ?? "unknown group",
def["units"] as string
);
}

Expand All @@ -53,14 +55,14 @@ definition is DB.InternalDefinition internalDefinition
units = DB.LabelUtils.GetLabelForUnit(parameter.GetUnitTypeId());
}

var group = DB.LabelUtils.GetLabelForGroup(parameter.Definition.GetGroupTypeId());
var group = DB.LabelUtils.GetLabelForGroup(definition.GetGroupTypeId());

Definitions[internalDefinitionName] = new Dictionary<string, object?>()
{
["definitionName"] = internalDefinitionName,
["name"] = humanReadableName,
["units"] = units,
["isShared"] = parameter.IsShared,
["isShared"] = isShared,
["isReadOnly"] = parameter.IsReadOnly,
["group"] = group
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ILogger<ParameterExtractor> logger
_parameterDefinitionHandler.HandleDefinition(parameter);

// NOTE: ids don't really have much meaning; if we discover the opposite, we can bring them back. See [CNX-556: All ID Parameters are send as Name](https://linear.app/speckle/issue/CNX-556/all-id-parameters-are-send-as-name)
if (internalDefinitionName.Contains("_ID"))
if (internalDefinitionName.EndsWith("_ID") || internalDefinitionName.EndsWith("_PARAM_ID"))
{
continue;
}
Expand Down Expand Up @@ -199,9 +199,17 @@ ILogger<ParameterExtractor> logger
case DB.StorageType.Double:
return _scalingServiceToSpeckle.Scale(parameter.AsDouble(), parameter.GetUnitTypeId());
case DB.StorageType.Integer:
return parameter.AsInteger().ToString() == parameter.AsValueString()
? parameter.AsInteger()
: parameter.AsValueString();
var integer = parameter.AsInteger();
var valueString = parameter.AsValueString();
if (integer.ToString() == valueString)
{
return integer;
}
else
{
return valueString;
}

case DB.StorageType.ElementId:
var elId = parameter.AsElementId()!;
if (elId == DB.ElementId.InvalidElementId)
Expand Down

0 comments on commit 6ba70a7

Please sign in to comment.