Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating rooms from space

3 REPLIES 3
Reply
Message 1 of 4
jeroen.vanvlierden
577 Views, 3 Replies

Creating rooms from space

 

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.

 

jeroenvanvlierden_0-1638807935128.png

 

3 REPLIES 3
Message 2 of 4

And this workaround seems to work

jeroenvanvlierden_1-1638810143310.png

 

 

Message 3 of 4

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:

  

  • Do you have to go via the string representation of the parameter value?
  • What happens if you read or set the double value?

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 4 of 4

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.

Post to forums  

Autodesk Design & Make Report