Room centering location

dynamo

#1

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?


#2

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

#3

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.


#4

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


#5

Hi Jean,

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


#6

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