Hi Jeremy,
Thanks for looking into this
to reproduce this: create a space with a LimitOffset of 2700.0 in mm => 8.85826772 feet and copy and paste the C# code in an ExternalCommand class
run this and you will see that I
- can copy and set the double value as a parameter
- can copy and set the string value as a parameter
- can not set the class property, I get the following exception message
{"Enter a value or a formula starting with \"=\"."}
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI;
using View = Autodesk.Revit.DB.View;
namespace Test
{
[Transaction(TransactionMode.Manual)]
class TestCommand : IExternalCommand
{
private UIDocument _uiDocument;
private Document _document;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
_uiDocument = commandData.Application.ActiveUIDocument;
_document = _uiDocument.Document;
Transaction transaction = new Transaction(_document, "testcommand");
transaction.Start();
var spaces = GetSpacesInActiveView(_uiDocument.ActiveView);
foreach (var space in spaces)
{
CreateRoomFromSpace(space);
}
transaction.Commit();
return Result.Succeeded;
}
private void CreateRoomFromSpace(Space space)
{
var locationPoint = (space.Location as LocationPoint)?.Point;
if (locationPoint == null) return;
var room = _document.Create.NewRoom(space.Level, new UV(locationPoint.X, locationPoint.Y));
room.UpperLimit = space.UpperLimit;
//works
var doubleValue = space.LookupParameter("Limit Offset").AsDouble();
room.LookupParameter("Limit Offset").Set(doubleValue);
//works
var stringValue = space.LookupParameter("Limit Offset").AsValueString();
room.LookupParameter("Limit Offset").SetValueString(stringValue);
//raises weird exception
room.LimitOffset = space.LimitOffset;
room.BaseOffset = space.BaseOffset;
room.Name = space.Name;
room.Number = space.Number;
}
private IEnumerable<Space> GetSpacesInActiveView(View activeView)
{
var getSpacesInActiveView = new FilteredElementCollector(_document, activeView.Id)
.OfClass(typeof(SpatialElement))
.WhereElementIsNotElementType()
.Where(e => e is Space && e.Location != null)
.Cast<Space>()
.Where(r => r.Area > 0)
.ToList();
return getSpacesInActiveView;
}
}
}