Set Assembly Code file

Does someone know how to set the Assembly Code file with Dynamo in Revit.
Only found the node how to get the file path…
http://dynamobim.org/forums/topic/get-assembly-code-settings-in-python/

I don’t even know what a Assembly Code Table is, but the
AssemblyCodeTable Class in the Revit API has only got one Method, and that’s the GetAssemblyCodeTable Method

http://www.revitapidocs.com/2016/26b23f25-ef12-5368-3f4b-6097f93ce312.htm

That makes me think it’s not possible to set it. Someone else might be able to give a more certain answer than me.

Assembly code is a UNIFORMAT classification (Alphanumeric string) for categorizing the built environment. Anything constructed can be classified by these codes.
@Jeremy_Tammik - Any suggestions on how to SET assembly code in PYHTON? (Thanks in advance : )

I am having a similar issue- ran across “UNIFORMAT_CODE” as a built in parameter - see section under:

if param.lower()=="assembly code":
    outSub.append("UNIFORMAT_CODE:")
     element.SetParameterByName(BuiltInParameter.UNIFORMAT_CODE,dat[hI])	#p=header/param name, dat[i]     corresponding data at index
     outSub.append("BuiltInParamSuccess!")

This is not working either (Correctly formatted code below).

# Default imports
import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitNodes")

elements = IN[0]	##Elements in the mode
headers = IN[1]		##Headers for reference
data = IN[2]		##Data LIST of values for PARAMS.

###Initialize
out=[]
outMain=[]
outSub=[]
found=0

##Find "MARK" Position from headers
for markPos, mark in enumerate(headers):
	if mark=='Mark':			##Found mark in headers proceed
		found=1
		break				##BREAK loop with current header index
		
if found==1:				##NEED better system of parameters to key-in on other than mark with a "+"
	for element in elements:								##Step through all the elements provided
	
		emark=element.GetParameterValueByName('Mark')		##Get the mark of the current element
		
		for dat in data:									##For each of the list(Data points) provided
			if dat[markPos]==emark:							##If the data in the [markpos] 
															##(Which is the mark we are looking for) matches the 
															##Current elements mark - we have a match to push data
															
				outMain=[]									##Reset the list collector for reporting
		
				for hI, param in enumerate(headers):		##hI count based on header Information to corresponding data 
															##-For parameters that are headers in the file		
															
					outSub=[]								##Reset the list collector for reporting
					
					try:
						outSub.append(param)				##Report parameter to push
						outSub.append(dat[hI])				##Report data psuhed to param
						
						element.SetParameterByName(param,dat[hI])	#p=header/param name, dat[i] corresponding data at index<<-##Does nothing for "Assembly Code"
						outSub.append("SetParam Success!")	##If it reaches here it was successful!
						
					except:									##Error occured above
						outSub.append("Checking BuiltInParameters:")
						try:								##Attempt to unwrap to set type param
							#outSub.append("Unwrap:")
							#element=UnwrapElement(eleent)[0]
							if param.lower()=="assembly code":
								outSub.append("UNIFORMAT_CODE:")
								element.SetParameterByName(BuiltInParameter.UNIFORMAT_CODE,dat[hI])	#p=header/param name, dat[i] corresponding data at index
								outSub.append("BuiltInParamSuccess!")
							
						except:
							outSub.append("ERROR in unwrap_set")		        #Add "error" to the return if it flakes
					##outMain.append(element)				##Append element to outMain
					outMain.append(outSub)					##Append Parameters success/fail
					
				out.append(outMain)
out.insert(0,[["****Tab must be 'Sheet1'***************\n****'Mark' in row 1 must be defined****"]])
OUT=out

I tried setting by name for “Assembly Code” in the 1st attempt to se in the code and it failed.

Got the idea for built-in parameters from:
https://forums.autodesk.com/t5/revit-api-forum/assembly-code-in-system-families/td-p/4790573
AND

really need to know how to set family TYPE parameters in Python- as well I suspect the “Assembly Code/Uniformat” is a special parameter.

Here is how to set a builtinparameter (typeparameter) with python. This is untested code.

import clr

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument

# Input
element = UnwrapElement(IN[0])
valueToSet = IN[1]

#Get the type
elementType = doc.GetElement(element.GetTypeId())

# Get the parameter
parameter = elementType.get_Parameter(BuiltInParameter.UNIFORMAT_CODE)

 #Set the parameter in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
parameter.Set(valueToSet)
TransactionManager.Instance.TransactionTaskDone()

OUT = 0
1 Like

Much Obliged!

Will test and debug it and then push it back to the forum.

Thanks!

Ron Allen | B+P BIM Manager - Rocky Mountain Area | Revit BIM ARCH.IV.NCARB.IDP | D 1-303-740-2716 | Ron.Allen@AECOM.commailto:Ron.Allen@AECOM.com | AECOM | www.AECOM.comhttp://www.aecom.com/ Denver
PPlease consider the environment before printing this e-mail.

Admittedly I don’t know how unwrap works… so I had to adapt the former part of the code and add the unwrap later- still errors out setting the parameter (Can you unwrap an element?)

in the 2nd TRY there is the ### Unifromat scan:

ele=UnwrapElement(element)	
#Get the type	##UNIFORMAT SET
elementType = doc.GetElement(ele.GetTypeId())
# Get the parameter								
parameter = elementType.get_Parameter(BuiltInParameter.UNIFORMAT_CODE)	##
#Set the parameter in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
parameter.Set(data[hI])
TransactionManager.Instance.TransactionTaskDone()

Entire code:

# Default imports
import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitNodes")


import Revit									#################################
clr.ImportExtensions(Revit.GeometryConversion)	#################################
clr.ImportExtensions(Revit.Elements)			#################################

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

doc = DocumentManager.Instance.CurrentDBDocument	#############################

elements = IN[0]	##Elements in the mode
headers = IN[1]		##Headers for reference
data = IN[2]			##Data

###Initialize
out=[]
outMain=[]
outSub=[]
found=0

##Find "MARK" Position from headers
for markPos, mark in enumerate(headers):
	if mark=='Mark':			##Found mark in headers proceed
		found=1
		break				##BREAK loop with current header index
		
if found==1:				##Consider adding additional parameters to key-in on other than mark
	for element in elements:
		emark=element.GetParameterValueByName('Mark')
		for dat in data:
			if dat[markPos]==emark:	
				outMain=[]
				for hI, param in enumerate(headers):		##hI count based on header to corresponding data For parameters that are headers in the file	
					outSub=[]
					try:
						outSub.append(param)
						outSub.append(dat[hI])
						element.SetParameterByName(param,dat[hI])	#p=header/param name, dat[i] corresponding data at index
						outSub.append("SetParam Success! \t")
					except:
						outSub.append("ERROR in element.SetParameterByName \t")		        #Add "error" to the return if it flakes
						try:	###################################################################### Unifromat scan
							ele=UnwrapElement(element)	##############################################
							#Get the type	########################################################## UNIFORMAT SET
							elementType = doc.GetElement(ele.GetTypeId())	######################
							# Get the parameter									######################
							parameter = elementType.get_Parameter(BuiltInParameter.UNIFORMAT_CODE)	##
							#Set the parameter in a Transaction
							TransactionManager.Instance.EnsureInTransaction(doc)
							parameter.Set(data[hI])
							TransactionManager.Instance.TransactionTaskDone()
						except:
							outSub.append("ERROR in set element.GetTypeId() (Uniformat) \t")	
					##outMain.append(element)				##Append element to outMain
					outMain.append(outSub)					##Append Parameters success/fail
				out.append(outMain)
out.insert(0,[["****Tab must be 'Sheet1'***************\n****'Mark' in row 1 must be defined****"]])
OUT=out

Your unwrapping looks fine. While troubleshooting, it would be better to remove the try-except blocks to see what error messages you get.

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 55, in
NameError: name ‘BuiltInParameter’ is not defined

Are you missing a reference?

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

Yep- Missed the import
Now it is a different error:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 58, in
TypeError: expected int, got list

    # Default imports
import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitNodes")


import Revit 								#################################
clr.ImportExtensions(Revit.GeometryConversion)	#################################
clr.ImportExtensions(Revit.Elements)			#################################

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

doc = DocumentManager.Instance.CurrentDBDocument	#############################

elements = IN[0]	##Elements in the mode
headers = IN[1]		##Headers for reference
data = IN[2]			##Data

###Initialize
out=[]
outMain=[]
outSub=[]
found=0

##Find "MARK" Position from headers
for markPos, mark in enumerate(headers):
	if mark=='Mark':			##Found mark in headers proceed
		found=1
		break				##BREAK loop with current header index
		
if found==1:				##Consider adding additional parameters to key-in on other than mark
	for element in elements:
		emark=element.GetParameterValueByName('Mark')
		for dat in data:
			if dat[markPos]==emark:	
				outMain=[]
				for hI, param in enumerate(headers):		##hI count based on header to corresponding data For parameters that are headers in the file	
					outSub=[]
					try:
						outSub.append(param)
						outSub.append(dat[hI])
						element.SetParameterByName(param,dat[hI])	#p=header/param name, dat[i] corresponding data at index
						outSub.append("SetParam Success! \t")
					except:
						outSub.append("ERROR in element.SetParameterByName \t")		        #Add "error" to the return if it flakes
						try:	###################################################################### Unifromat scan
							ele=UnwrapElement(element)	##############################################
							#Get the type	########################################################## UNIFORMAT SET
							elementType = doc.GetElement(ele.GetTypeId())	######################
							# Get the parameter									######################
							parameter = elementType.get_Parameter(BuiltInParameter.UNIFORMAT_CODE)	##
							#Set the parameter in a Transaction
							TransactionManager.Instance.EnsureInTransaction(doc)
							parameter.Set(data[hI])
							TransactionManager.Instance.TransactionTaskDone()
						except:
							outSub.append("ERROR in set element.GetTypeId() (Uniformat) \t")	
					##outMain.append(element)				##Append element to outMain
					outMain.append(outSub)					##Append Parameters success/fail
				out.append(outMain)
out.insert(0,[["****Tab must be 'Sheet1'***************\n****'Mark' in row 1 must be defined****"]])
OUT=out

Cleared the othe rmessage with:

parameter.Set(str(data[hI][0]))

for the data…

Almost have it- posting the wrong data to the assembly code but it is setting it …

Finally! Thanks for your help!

# Default imports
import clr
clr.AddReference("RevitAPI")
clr.AddReference("RevitNodes")
from Autodesk.Revit.DB import *					#################################

import Revit									#################################
clr.ImportExtensions(Revit.GeometryConversion)	#################################
clr.ImportExtensions(Revit.Elements)			#################################

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

doc = DocumentManager.Instance.CurrentDBDocument	#############################

elements = IN[0]	##Elements in the mode
headers = IN[1]		##Headers for reference
data = IN[2]			##Data

###Initialize
out=[]
outMain=[]
outSub=[]
found=0

##Find "MARK" Position from headers
for markPos, mark in enumerate(headers):
	if mark=='Mark':			##Found mark in headers proceed
		found=1
		break				##BREAK loop with current header index
		
if found==1:				##Consider adding additional parameters to key-in on other than mark
	for element in elements:
		emark=element.GetParameterValueByName('Mark')
		for dat in data:
			if dat[markPos]==emark:	
				outMain=[]
				for hI, param in enumerate(headers):		##hI count based on header to corresponding data For parameters that are headers in the file	
					outSub=[]
					try:
						outSub.append(param)						###ADD PARAMS TO Output list
						outSub.append(dat[hI])				###ADD TABS + Data to output list
						element.SetParameterByName(param,dat[hI])	###Attempt set data header/param name, dat[i] corresponding data at index
						outSub.append("SetParam Success!")	###If it succeedes report it
					except:											### If if failed...################################################
						if param == "Assembly Code":				##SPECIAL ODD-BALL CASE for SYSTEM TYPE PARAM (Assembly Code)####
							try:	##################################Assembly Code = Unifromat scan
								ele=UnwrapElement(element)	##########
								#Get the type	###################### (UNIFORMAT TYPE param)
								elementType = doc.GetElement(ele.GetTypeId())	######################
								# Get the parameter###################
								parameter = elementType.get_Parameter(BuiltInParameter.UNIFORMAT_CODE)
								#Set the parameter in a Transaction###
								TransactionManager.Instance.EnsureInTransaction(doc)
								parameter.Set(str(dat[hI]))			##FROM THE current DAT line of DATA return the data from the hI Index position in the list
								#Set the parameter end  Transaction###
								TransactionManager.Instance.TransactionTaskDone()
								outSub.append("Set ASSEMBLY CODE Param Success!")
							except:
								outSub.append("ERROR set element.GetTypeId() (Uniformat)")	
					outMain.append(outSub)					##Append Parameters success/fail
				out.append(outMain)
out.insert(0,[["****Tab must be 'Sheet1'***************\n****'Mark' in row 1 must be defined****"]])
OUT=out
2 Likes

Hello Ron. I really apprieciate your work, but can you make your script more understandable? What do you mean by the folowing parameters?

elements = IN[0] ##Elements in the mode
headers = IN[1] ##Headers for reference
data = IN[2] ##Data
Maybe you can add some printcreens from your Dynamo workaround to this post?
thanx!

elements = IN[0] ##Elements in the model - Elements to run the script with (1d List)
headers = IN[1] ##Headers for reference - The headers stripped out from the excel file (Also the Revit PARAMETER Names)(1d list)
data = IN[2] ##Data - The remaining excel rows of data.(List of list - 2d list)

thurevit3 , Did you solve the problem of the question? I would also like to set the Assembly Code with Dynamo in Revit

Create a Python Script with the following Code:
With a filepath as input, (referring to the location of the .txt file) this should do the work

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

filepath = UnwrapElement(IN[0])

p = ModelPathUtils.ConvertUserVisiblePathToModelPath(filepath)
s = ExternalResourceReference.CreateLocalResource(doc, ExternalResourceTypes.BuiltInExternalResourceTypes.AssemblyCodeTable, p, PathType.Absolute);

TransactionManager.Instance.EnsureInTransaction(doc)

AssemblyCodeTable.GetAssemblyCodeTable(doc).LoadFrom(s, KeyBasedTreeEntriesLoadResults());

TransactionManager.Instance.ForceCloseTransaction()

OUT = s.GetReferenceInformation()
6 Likes