Room centering location

Hi all,

I know package Modelical has the node called “room and tag location centering”
but i did change the phase name as shown in the image like “XX_EXIST” and “XX_NEW” then the script doesn’t work. it will work when there isn’t “XX_” as prefix infront. Does anyone know where to fix in the python script?

hi @dylanpeng, you can try this;

center-room

# dynamo version - 1.3.x, 2,x,x

import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference("RevitNodes")

import System,Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Autodesk.DesignScript.Geometry import (Geometry,
Point as pt)
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

elems = IN[0];

# make list
if not isinstance(elems,list):
	elems = UnwrapElement([elem])
else:
	elems = UnwrapElement(elems)

# output
res = []
# start transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# loop elements
for e in elems:
	# level elevation - unit millimeter 
	elevation = e.Level.Elevation * 304.8
	# get geo-objects of the element
	geoelem = e.GetGeometryObjectFromReference(Reference(e))
	# get enumerator to loop geo-objects
	geoobj = geoelem.GetEnumerator()
	# loop geo-objector
	for obj in geoobj:
		# convert to dynamo type
		room_geometry = obj.ToProtoType()
		# get the centroid of the element
		point = room_geometry.Centroid()
		# create location point with level elevation
		center = pt.ByCoordinates(point.X,point.Y,elevation)
		# current element location
		current = e.Location.Point
		# point convert to revit and minus from current location
		newloc = center.ToXyz() - current
		# move to new location
		e.Location.Move(newloc)

# transaction done
TransactionManager.Instance.TransactionTaskDone()

# output
OUT = elems
5 Likes

Hi Jean,

Thank you very much. It works for " XX_ " but when I start to change the prefix say AB_, it dosent work again.

image

I couldn’t find in your python script which part relate the prefix.

hi @dylanpeng, the underlying issue is room status. You can try this way again.

2 Likes

Hi Jean,

it works! fantastic! Is it possible to do the same thing for area?

Was trying to fix something similar, this is working for me:

4 Likes

seems Python script is not always working, either crash or never stop running, maybe something wrong w/ model like bad room elements.

what package to use in order to get outer boundary of area/room?

edit: never mind, i’ll use MEPover package instead

i love this ! always try to develop out of basic nodes in dynamo even tho it could be a little more complex is my goal. since i am not so good with writing python … yet. Thanks

Can anyone tell me where did it go wrong ? Please help

You are trying to move the Location Point of the Room, that input needs to be the Room elements themselves.

1 Like

OH MY BUDDHA ! It works ! thank you! somehow this afternoon, i tried to connect room elements there it didnt move! :frowning: so happy ! thank you very much for your advice

Can you post the final script? It would be very helpful!
thank you!

Here you go ^^
Move room coordination point to center.dyn (25.5 KB)

2 Likes

Thank you!!!

I have tried with some package and found your script. You are the best.

1 Like

Hi @Bjorn_Keulemans1, which package Areas.OuterBoundary node belongs to? thanks

Rhythm.

The selection Node used there is from archi-lab.

I did learn to annotate my custom node usage in the meantime.

Seems the center is not the actual center?!?
What am i missing? @Qnguyen2688
Revit 2020.2

Any idea why? @jean

hi @bvs1982 , frankly speaking, i have no idea. Better consult with ADSK team …