Urgent Python Script Help Needed

Hi all

So I’m pretty much a novice when it comes to dynamo and certainly haven’t a clue when it comes to Python unfortunately so any help would be very much appreciated, particularly if you can explain why I am going wrong and where.

I have tried to follow the below link from archi-lab, Konrad is ace with his explanations btw:

But even after rebuilding it from scratch with the updated nodes to reflect the later releases I am still getting the below error.

Please please help.

I have attached the script fyi.

wiprenamerooms.dyn (73.7 KB)

In past versions of the Revit API you could feed a string as a parameter name to get_Parameter but now it either expects a GUID (as per the error message) or you can use a builtin parameter in this case. Try this on line 65:
if to_room == None or f == to_room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()

For the subsequent lines you’ll need to replace "Name" with BuiltInParameter.ROOM_NAME and "Number" with BuiltInParameter.ROOM_NUMBER

1 Like

I had a go at the GUID version…

#Copyright(c) 2015, Konrad Sobon
#@arch_laboratory, http://archi-lab.net
#updated by MKA, thanks ADieckmann & TCorrie

import clr
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

import System
 
doc = DocumentManager.Instance.CurrentDBDocument

#get all built in parameters
bips = System.Enum.GetValues(BuiltInParameter)

pdata = list()
#loop through the built in parameter list
for bip in bips:
    try:
        # append the bips to a list as position 0, along with their id at position 1
        pdata.append(bip,ElementId(bip))
    except:
        pass

rmNum = []
rmName = []
# look through the built in parameter list 
for p in pdata:
    # compare the bip (as a string) at position 0, to ROOM_NAME
    if str(p[0]) == 'ROOM_NAME':
        # if the bip matches ROOM_NAME add the GUID (at position 1) to the 'list' (we add position 0, so instead of a list containing the GUID, we get the GUID)
        rmNum.append(p[1][0])
        #if the name matches ROOM_NUMBER, add that as above
    elif str(p[0]) == 'ROOM_NUMBER':
        rmName.append(p[1][0])

filter_1 = IN[1]
fam_inst = IN[0]

elements = []
for i in IN[0]:
	elements.append(UnwrapElement(i))

def TryGetToRoom(room, phase):
	try:
		toRoom = room.get_ToRoom(phase)
	except:
		toRoom = None
		pass
	return toRoom

def TryGetFromRoom(room, phase):
	try:
		fromRoom = room.get_FromRoom(phase)
	except:
		fromRoom = None
		pass
	return fromRoom

room_number, room_name, doors, room = [], [], [], []
for i in elements:
	for phase in doc.Phases:
		if i.CreatedPhaseId == phase.Id:
			for phase2 in doc.Phases:
				if TryGetToRoom(i, phase2) != None:
					to_room = TryGetToRoom(i, phase2)
					break
				else:
					to_room = None
			for phase3 in doc.Phases:
				if TryGetFromRoom(i, phase3) != None:
					from_room = TryGetFromRoom(i, phase3)
					break
				else:
					from_room = None
			filter = 0
			for f in filter_1:
			    #rmName is a GUID
				if to_room == None or f == to_room.get_Parameter(rmName).AsString():
					filter += 1
			if filter > 0:
				if from_room == None and to_room == None:
					room_number.append("No to or from room")
					room_name.append("No to or from room")
					doors.append("No to or from room")
				elif from_room == None:
					#rmNum is a GUID
					room_number.append(to_room.get_Parameter(rmNum).AsString())
					#rmName is a GUID
					room_name.append(to_room.get_Parameter(rmName).AsString())
					doors.append(i)
					room.append(to_room)
				else:
					#rmNum is a GUID
					room_number.append(from_room.get_Parameter(rmNum).AsString())
					#rmName is a GUID
					room_name.append(from_room.get_Parameter(rmName).AsString())
					doors.append(i)
					room.append(from_room)
			else:
			    #rmNum is a GUID
				room_number.append(to_room.get_Parameter(rmNum).AsString())
				#rmName is a GUID
				room_name.append(to_room.get_Parameter(rmName).AsString())
				doors.append(i)
				room.append(to_room)
					
#Assign your output to the OUT variable
OUT = room_number, room_name, doors, room