Setting the builtin parameter accessible thru the family editor?

Following my previous post any ideas in how to accomplish this?

Not available in project:

But available when family is edited:

Thanks,

1 Like

Hi, you could need to update the Omniclass taxonomy file directly for this, see here:

@Yna_Db, my objective is to set them first, not edit. Take a value from and excel sheet and plug it in the family with Dynamo instead of opening every family and doing it manually. A mega hospital (5in1) project is being upgraded from 2012 to 2017 and all the families will need to be updated…:cold_sweat:

@Konrad_K_Sobon any ideas to follow the previous post where we concluded that this was not possible directly thru the project?

I created a script for ungrouping groups in families here. You can try to edit it to make it set builtin parameters in stead.

I don’t have time to look at it right now, but for others with basic python and API skills it should be a nice and easy challenge to modify it!

In this case, see this video:

@Yna_Db
So this plugin does exactly what I’m looking do to with Dynamo/Excel. Except that it’s not writing in the existing parameters but creating new project parameters per category. It works and is customizable, so that’s great. I was looking for ways to fillout existing parameters, but this is a good workaround.

1 Like

@Einar_Raknes
I downloaded the DS above, but having no Python/API skills it’s like reading my Japanese kana, I can read the symbols but have no clue to meaning and much less how to modify it. Hopefully, other programmers will give it a try. Thanks again for your time and effort!

Hi Jonathan,

Maybe the new “Document.BackgroundOpen” node of @john_pierson/Rhythm/sixtysecondrevit can help you.
http://sixtysecondrevit.com/2016-11-07-open-revit-files-in-background-with/

Good luck

1 Like

I had a look at it now, but without any luck. It seems that the doc.EditFamily(f) doesn’t like to be called within Dynamo. I tested similar code in Revit Python Shell and it worked without problems. Strangly some very similar workflows for setting shared parameters in families seem to work:

Maybe @Mostafa_El_Ayoubi understand why? It’s probably something about how Dynamo handles transactions.


Here is the python script if you wold like to try:

import clr

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

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

doc = DocumentManager.Instance.CurrentDBDocument

class FamilyOption(IFamilyLoadOptions):
	def OnFamilyFound(self,familyInUse,overwriteParameterValues):
		overwriteParameterValues = True
		return True
		
	def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
		overwriteParameterValues = True
		return True
		
#Preparing input from dynamo to revit
f = UnwrapElement(IN[0])
o = IN[1]
OUT = []

famdoc = doc.EditFamily(f)

thisFamily = famdoc.OwnerFamily
parOmniclass = thisFamily.get_Parameter(BuiltInParameter.OMNICLASS_CODE)

TransactionManager.Instance.EnsureInTransaction(famdoc)
parOmniclass.Set(o)
TransactionManager.Instance.TransactionTaskDone()
TransactionManager.Instance.ForceCloseTransaction()

famdoc.LoadFamily(doc, FamilyOption())
famdoc.Close(False)
OUT = 0

Here is the code I used in Revit Python Shell:

import clr

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

app = __revit__.Application
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document

class FamilyOption(IFamilyLoadOptions):
	def OnFamilyFound(self,familyInUse,overwriteParameterValues):
		return True
		
	def OnSharedFamilyFound(self, sharedFamily, familyInUse, FamilySource, overwriteParameterValues):
		return True
		
#Preparing input from dynamo to revit
fec = FilteredElementCollector(doc).OfClass(Family)

for f1 in fec:
	if f1.Name == "NO_Column_CastInPlace_Round":
		f = f1
		break
o = "23.25.30.11.14.11"

famdoc = doc.EditFamily(f)

thisFamily = famdoc.OwnerFamily
parOmniclass = thisFamily.get_Parameter(BuiltInParameter.OMNICLASS_CODE)

t = Transaction(famdoc)
t.Start("Edit o")
parOmniclass.Set(o)
t.Commit()

print famdoc.LoadFamily(doc, FamilyOption())
print famdoc.Close(False)
2 Likes

Isn’t it true that Dynamo puts Revit in a read-only state when it’s run? That would explain why the EditFamily method doesn’t work, because that method can’t be used when Revit is in a read-only state.

1 Like

It might have something to do with Dynamo and Revits Dynamic Model Update (DMU)

From API docs:

This creates an independent copy of the family for editing. To apply the changes back to the family stored in the document, use the LoadFamily overload accepting IFamilyLoadOptions .
This method may not be called if the document is currently modifiable (has an open transaction) or is in a read-only state. The method may not be called during dynamic updates. To test the document’s current status, check the values of IsModifiable and IsReadOnly properties.

The results from IsModifiable and IsReadOnly looks fine to me.

3 Likes

Uhm… Yeah that’s what I meant :wink:

Hi everyone, thanks for racking your brains on this!
I read thru the thread and was wondering if the attemps you’ve made above also cover the suggestion made by @MJB-online regarding @john_pierson’s node?
If not, and by the description there doesn’t seem to be DS or Python needed, I’ll look into it and reply back with further development because I’d like participate and to do my part in the question/problem solving :wink:

My node should be able to get you started, point to the family with file path, background open, get/set data.

But as @Einar_Raknes pointed out, working between documents is a bit difficult in Dynamo.If you are using any python nodes to achieve this you will need to give the node a document input similar to what I have done with the clockwork node above.

1 Like

This should do the trick:

#Copyright(c) 2017, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

# Import Element wrapper extension methods
import clr
clr.AddReference("RevitNodes")
import Revit
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

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

paramName = IN[1]
value = IN[2]

class FamilyOption(IFamilyLoadOptions):
	def OnFamilyFound(self, familyInUse, overwriteParameterValues):
		overwriteParameterValues = True
		return True

	def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
		return True

def GetBuiltInParam(paramName):
	builtInParams = System.Enum.GetValues(BuiltInParameter)
	test = []
	for i in builtInParams:
		if i.ToString() == paramName:
			test.append(i)
			break
		else:
			continue
	if len(test) == 0:
		return None
	else:
		return test[0]

try:
	errorReport = None
	output = []
	uniqueFams = set()
	bip = GetBuiltInParam(paramName)
	for i in IN[0]:
		family = UnwrapElement(i).Symbol.Family
		if family not in uniqueFams:
			uniqueFams.add(family)
			famDoc = doc.EditFamily(family)
			if famDoc != None:
				ownerFamily = famDoc.OwnerFamily
				param = ownerFamily.get_Parameter(bip)
				TransactionManager.Instance.EnsureInTransaction(famDoc)
				param.Set(value)
				TransactionManager.Instance.TransactionTaskDone()
				output.append(famDoc.LoadFamily(doc, FamilyOption()))
except:
	# if error accurs anywhere in the process catch it
	import traceback
	errorReport = traceback.format_exc()

#Assign your output to the OUT variable
if errorReport == None:
	OUT = output
else:
	OUT = errorReport

14 Likes

What if it is not a builtin parameter? Seems that in family doc, parameter changed by FamilyManager.Set() function do not get updated when loaded back to a project environment.

@wzy816 That would be another topic of the day.

Just got in and saw all the replies! :open_mouth:
Since the “Solution” has already been checked and liked, I assume this solves the case! :joy:
Thanks @Konrad_K_Sobon for the final solution and everybody else who provided ideas to feed off from to help find the solution !
And from my understing of the node, it also provides a solution to other BIP, nice!

1 Like

The code by @Konrad_K_Sobon is almost the same as mine, and I get the same problems as with my code when trying to run it.

Traceback (most recent call last):
File “”, line 61, in
Exception: The document is currently modifiable! Close the transaction before calling EditFamily.

Maybe it’s my version of Dynamo causing the problem. Have anyone else tested the code?

Revit 2017 and

1 Like

Dynamo 2.0.0???