using Autodesk.Revit.DB;
namespace Speckle.Converters.RevitShared.Helpers;
///
/// Helper class for working with transform data coming from reference point setting
/// This allows preserving the reference point information between operations.
///
public static class ReferencePointHelper
{
public const string REFERENCE_POINT_TRANSFORM_KEY = "referencePointTransform";
///
/// Changes Revit Transform to a double array.
/// Uses a 16-element column-major matrix representation. See https://speckle.guide/dev/objects.html
///
public static Dictionary CreateTransformDataForRootObject(Transform transform)
{
return new Dictionary
{
{
"transform", // TODO: it would also be nice to include the key-value pair for reference point type as a string
new[]
{
transform.BasisX.X,
transform.BasisX.Y,
transform.BasisX.Z,
0,
transform.BasisY.X,
transform.BasisY.Y,
transform.BasisY.Z,
0,
transform.BasisZ.X,
transform.BasisZ.Y,
transform.BasisZ.Z,
0,
transform.Origin.X,
transform.Origin.Y,
transform.Origin.Z,
1
}
}
};
}
///
/// Extracts and reconstructs a transform from the matrix data stored on root object
///
public static Transform? GetTransformFromRootObject(object? matrixDataObj)
{
double[]? matrixData = null;
// NOTE: why all these if checks? We send double[] but get List