Skip to content

Commit

Permalink
fix(rvt): Modify signature of RevitConverter.UpdateParameter to ret…
Browse files Browse the repository at this point in the history
…urn AppObj (#3019)

* fix(rvt): Modify signature of `RevitConverter.UpdateParameter` to return AppObj

* fix: leftover formatting changes

* fix: No need for Report logging if we return AppObject

* fix: Remove unnecessary new Exception type
  • Loading branch information
AlanRynne authored Nov 3, 2023
1 parent c22fec2 commit e0ca359
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ public void GetAllRevitParamsAndIds(Base speckleElement, DB.Element revitElement

speckleElement["worksetId"] = revitElement.WorksetId.ToString();


// assign the category if it is null
// WARN: DirectShapes have a `category` prop of type `RevitCategory` (enum), NOT `string`. This is the only exception as of 2.16.
// In all other cases this should be the display value string (localized name) of the catogory
Expand All @@ -271,8 +270,6 @@ public void GetAllRevitParamsAndIds(Base speckleElement, DB.Element revitElement
BuiltInCategory builtInCategory = Categories.GetBuiltInCategory(category);
speckleElement["builtInCategory"] = builtInCategory.ToString();



//NOTE: adds the quantities of all materials to an element
var qs = MaterialQuantitiesToSpeckle(revitElement, speckleElement["units"] as string);
if (qs != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void SetContextDocument(object doc)
const string DetailLevelMedium = "Medium";
const string DetailLevelFine = "Fine";
public ViewDetailLevel DetailLevelSetting => GetDetailLevelSetting() ?? ViewDetailLevel.Fine;

private ViewDetailLevel? GetDetailLevelSetting()
{
if (!Settings.TryGetValue("detail-level", out string detailLevel))
Expand Down Expand Up @@ -648,8 +649,7 @@ public object ConvertToNativeObject(Base @object)
return RailingToNative(o);

case BER.ParameterUpdater o:
UpdateParameter(o);
return null;
return UpdateParameter(o);

case BE.View3D o:
return ViewToNative(o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,53 @@
using Objects.Geometry;
using System.Collections.Generic;
using System.Linq;

using Speckle.Core.Helpers;
using Speckle.Core.Models;

namespace Objects.Converter.Revit
{
public partial class ConverterRevit
{
public void UpdateParameter(ParameterUpdater paramUpdater)
public ApplicationObject UpdateParameter(ParameterUpdater paramUpdater)
{
//the below does not work because ApplicationIds are stored within a stream
//try to get element using ApplicationId
//this will only work if the element has been successfully been received in Revit before
//var element = GetExistingElementByApplicationId(paramUpdater.revitId);

var appObj = new ApplicationObject(paramUpdater.id, paramUpdater.speckle_type)
{
applicationId = paramUpdater.applicationId
};
Element element = null;

//try to get element using ElementId
int intId;

if (int.TryParse(paramUpdater.elementId, out intId))
if (int.TryParse(paramUpdater.elementId, out int intId))
{
var elemId = new ElementId(intId);
element = Doc.GetElement(elemId);
}

//try to get element using UniqueId
if (element == null)
element ??= Doc.GetElement(paramUpdater.elementId);

if (element != null)
{
element = Doc.GetElement(paramUpdater.elementId);
SetInstanceParameters(element, paramUpdater);
appObj.Update(
status: ApplicationObject.State.Updated,
logItem: $"Successfully updated instance parameters for element {paramUpdater.elementId}"
);
}

if (element == null)
else
{
Report.LogConversionError(new System.Exception($"Could not find element to update: Element Id = {paramUpdater.elementId}"));
return;
appObj.Update(
status: ApplicationObject.State.Failed,
logItem: $"Could not find element to update: Element Id = {paramUpdater.elementId}"
);
}

SetInstanceParameters(element, paramUpdater);
return appObj;
}

}
}
}

0 comments on commit e0ca359

Please sign in to comment.