Skip to content

Commit

Permalink
Support shared parameter in schedules (#3585)
Browse files Browse the repository at this point in the history
* add check for shared parameter - to Speckle

* update FieldType metadata logic

* formatting

* correctly assign isReadOnly parameter

---------

Co-authored-by: Eduardo Di Loreto <[email protected]>
Co-authored-by: Connor Ivy <[email protected]>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 536941b commit af53b70
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Element firstElement

var columnMetadata = new Base();
columnMetadata["BuiltInParameterInteger"] = info.field.ParameterId.IntegerValue;
columnMetadata["FieldType"] = info.field.FieldType.ToString();
string fieldType = info.field.FieldType.ToString();

Parameter param;
if (info.field.FieldType == ScheduleFieldType.ElementType)
Expand All @@ -257,10 +257,26 @@ Element firstElement
}
else if (info.field.FieldType == ScheduleFieldType.Instance)
{
// All shared parameters also use this type, regardless of whether they are instance or type parameters.
// ref: https://www.revitapidocs.com/2024/9888db7d-00d0-4fd7-a1a9-cdd1fb5fce16.htm
if (firstElement != null)
{
param = firstElement.get_Parameter(builtInParameter);
columnMetadata["IsReadOnly"] = param?.IsReadOnly;

// if the parameter is shared, we need to check the type parameterer too
if (firstType != null)
{
Parameter typeParam = firstType.get_Parameter(builtInParameter);

// If the parameter is readonly in the element but not in the type, is a type parameter
if (typeParam != null && !typeParam.IsReadOnly && param != null && param.IsReadOnly)
{
columnMetadata["IsReadOnly"] = false;
fieldType = ScheduleFieldType.ElementType.ToString();
}
}

columnMetadata["IsReadOnly"] ??= param?.IsReadOnly ?? true;
}
}
else
Expand All @@ -273,6 +289,8 @@ Element firstElement
info.field.FieldType.ToString()
);
}

columnMetadata["FieldType"] = fieldType;
speckleTable.DefineColumn(columnMetadata);
}

Expand Down

0 comments on commit af53b70

Please sign in to comment.