Create Spaces by Rooms


#1

Hello!
Maybe, I create this topic not first, but I’ve a problem: I need to create spaces by architects rooms, and I tired) I finded a dynamo script (whith Python), but it’s work only on small project. As example: if you have 2 linked files (AR) in HVAQ’s model and AR’s models insert in consolidated file by shared coordinates - this script doesn’t work. My python is not so good to create code, but I can find a problem in existing code. Author of this script used coordinates XYZ to finded rooms, but all of linked files (AR model) create at point 0.0.0 (I mean intersection point of axis A and 1).
Maybe someone have working script??? Or someone can help me with this code??? Please, help!!!


#2

import clr
from math import *
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
import Autodesk
clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
from System.Collections.Generic import *
links = FilteredElementCollector(doc).OfClass(Autodesk.Revit.DB.RevitLinkInstance).ToElements()
linkdocs = []
for i in links:
linkdocs.append(i.GetLinkDocument())
linkrooms = []
for linkdoc in linkdocs:
try:
linkrooms.append(FilteredElementCollector(linkdoc).OfCategory(BuiltInCategory.OST_Rooms).WhereElementIsNotElementType().ToElements())
except:
0
levels = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
old_spaces = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_MEPSpaces).WhereElementIsNotElementType().ToElements()

rooms=[]
for g_rooms in linkrooms:
for room in g_rooms:
if room.Area>0:

TransactionManager.Instance.EnsureInTransaction(doc)
list=[]
message=[]
for room in rooms:
pt = room.Location.Point
i=0
for space in old_spaces:
y = space.IsPointInSpace(XYZ(pt.X,pt.Y,pt.Z+1))
if y:
i=1
message.append(y)
if i==0:
uv = UV(pt.X,pt.Y)
elev = round(room.Level.Elevation)
level2 = None

	for level in levels:
		elev2 = round(level.Elevation)
		if elev==elev2:
			level2=level
	if level2 is not None:
		name = room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
		number = room.get_Parameter(BuiltInParameter.ROOM_NUMBER).AsString()
		height = room.get_Parameter(BuiltInParameter.ROOM_UPPER_OFFSET).AsDouble()
		space = doc.Create.NewSpace(level2,uv)
		space.get_Parameter(BuiltInParameter.ROOM_NAME).Set(name)
		space.get_Parameter(BuiltInParameter.ROOM_NUMBER).Set(number)
		space.get_Parameter(BuiltInParameter.ROOM_UPPER_OFFSET).Set(height)
		list.append(space)

TransactionManager.Instance.TransactionTaskDone()
OUT = list


#3

Code.txt (2.4 KB)


#4

You can do it with custom nodes in packages.


#6

It’s doesn’t worked(
If you look at my file (picture), you can see, that I select model “ПУШ31_АГО_АР_К3…”. The script does work whith Rooms (in picture - “Помещения”) - it select rooms from model “ПУШ31_АГО_АР_К3…” but it create points (location) on model “ПУШ31_АГО_АР_К1…” (K1).


#7

Maybe we inserted models not by the rules?


#8

it is working
you are missing the node Space.byPoint


#9

Hi,

Look at this topic to transform the “origin” coordinates in shared coordinates.


#10

I was show you, that node “Room.Location” gives to us points not in “true” model


#11

yes, i see it now, sorry


#12

Alban, you give me a good idea! I think, I did samething wrong. I uploaded 2 version of my script. Any ideas???


#13

It’s hard to know without your revit files.
I think the internal origin must be different in the host and linked Revit file.

You can try this :

Get locations of rooms.dyn (21.6 KB)


#14

Alban, it’s doesn’t worked(
Script created space by rooms from model AR_2 on model AR_1. I can’t uploaded my projects - after cleaning revit model, it size - 53 mb).
I just uploaded model AR_2 to AR_1 and gived to AR_2 coordinates (Shared Site)
On picture - work result of your script:


#15

You can you upload your models with a third party sharing site such as onedrive, google drive, dropbox, wetransfer…

For which model do you want to create spaces AR_1 or AR_2 ? Because your rooms come from the AR2 model.


#17

I want to create spaces in all models. In AR_1 it’s creating - I upload it first (base point to base point). Then, I gives coordinates from AR_1, inserted AR_2 and tranfer to this model coordinates.

https://drive.google.com/open?id=1_vXxCNJYlMbNWnw1XpKe_r5FhzSSdNhb


#18

AR_1 model is missing.


#19

Oh, I’m sorry. Try it now


#20

That’s exactly what I thought. The internal origin is different in your in the host and in the linked Revit file.
You must transform the location of your room points.


#21

Alban, who created node “springs.collector.linkedinstanselements”?) I can’t find it


#22

It’s in package Springs :blush: