Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
I have a command that creates a room from a given space
When i set the room.LimitOffset = space.LimitOffset; I get an exception
even when i do in the debugger: space.LimitOffset = space.LimitOffset; I get the same exception
when I set it to an integer value it works, but setting it to any kind of double precision value raises this weird exception.
Interesting.
What exactly does your source code look like that produces this exception?
Can you produce a minimal reproducible case, optimally a macro in a model containing one single space?
https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b
Regarding your workaround:
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;
}
}
}
Can't find what you're looking for? Ask the community or share your knowledge.