Family document add shared parameter

Does anyone have an idea how too add a shared parameter inside a family document. Families comes as a list, open in the background (http://sixtysecondrevit.com/2016-10-26-bulk-upgrade-revit-files-with-dynamobim/)
it seams to be problems with the “TransactionManager”

My code so far:

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

docs = IN[0] #document list
spfile = IN[1] #shared parameter file as string
group_name = IN[2] #group in shared parameter file
param_name = IN[3] #parameter name in shared parameter file
_param_group = IN[4] #BuiltInParameterGroup (PRO TEM. NOT IN USE)
instance = IN[5] #boolean value for instance

#hardcoded BuiltInParameterGroup
param_group = BuiltInParameterGroup.INVALID

result = [] #test list

#ExternalDefinition
def defFile(file, group, param) :
	file = app.OpenSharedParameterFile()
	defGroup = file.Groups.get_Item(group)
	return defGroup.Definitions.get_Item(param)

"""
eDef = defFile(spfile, group_name, param_name)
result.append(eDef)
result.append(spfile)
result.append(group_name)
result.append(param_name)
result.append(param_group)
result.append(instance)
OUT = result
"""

for doc in docs :
#	TransactionManager.Instance.EnsureInTransaction(doc)
	try :
		TransactionManager.Instance.EnsureInTransaction(doc)
		eDef = defFile(spfile, group_name, param_name)
		doc.FamilyManager.AddParameter(eDef, param_group, instance)
		result.append('Success')
		TransactionManager.Instance.ForceCloseTransaction()
	except :
		result.append('Failed')
#	TransactionManager.Instance.ForceCloseTransaction()
OUT = docs, result

Thanks, Erik

Hi @Erik_Falck_Jorgensen ,

This is not the exact answer to your question but I’m pretty sure this thread can help you :

This part more particularly:

Hi @Erik_Falck_Jorgensen

Could you please show watch node for Document.BackgroundOpen.

Hi @Kulkul ,

It is a Rythm node, having several nodes inside. but the essential is

typelist = list()
for i in items:
	try:
		typelist.append(app.OpenDocumentFile(i))
	except:
		typelist.append(list())
OUT = typelist 

meaning you will get a list of “Autodesk.Revit.DB.Document” open in the background.

@Erik_Falck_Jorgensen i know it is rhythm node. I want to see if your getting family.documents or not.

I just gave your code a go. Good news is that it works, bad news is I’m not sure why it doesn’t work for you… I tried with Revit 2017 and dynamo 1.2.1:

2 Likes

@Erik_Falck_Jorgensen Try removing “1:” from your code block and just type “Sheet and Project”. See if that helps!

The code is not working, an Error: endline expected error appears :sweat_smile:

@fablabolbia Show us your complete graph with errors expanded.

Hi Kulkul,
I’m using the @Mostafa_El_Ayoubi code without results. (the @erfajo code gave me an error)
with reference to mostafa code, a “false” appear in the OUT watch.
NO changes have been applied to the families stored in the called folder (read only flag has been removed).
The shared parameter file is also attached.
SP.txt (810 Bytes)

ADDING SHARED PARAMETERS_TEST___erfajo.dyn (10.7 KB)
ADDING SHARED PARAMETERS_TEST__mostafa.dyn (10.8 KB)

Thank you in advance !
Anton

@fablabolbia
you need to feed the right data from your Shared Parameter file. I have no idea what “Group 3” and “Group 1” is, these “items” is not a part of the SP file you have uploaded.

And… please try to see this post, use the nodes in DanEDU Dynamo package instead.

1 Like

HI @erfajo, already tested and not working…I’m going to try again, but it gave me an error: the Run in progress never disappear

Never reaches a stop…

image

Also continous crashes…

image

Hi @fablabolbia ,
could you share dummy files (revit and .txt) that cause the same issues?

i’m having pretty much same issues with it crashing… not sure if it’s because of the same problem as you fablobolbia but i would really appreciate if you could update once you find a solution as i’ve tried to search so much for one that i got headaches and had to take drugs for them, i can’t search further anymore. Mostafa also thanks for answering that guy’s questions. you seem to have some good knowledge… would you mind if i am going to have some questions either? thanks!

At the moment I can not find a solution…I’m not sure if I’m a stupid or if there’s no real working code in the forum but just “suggestions” for people (not me :sweat_smile::sweat_smile::sweat_smile: ) with higher programming skills…

Thank you very much @Mostafa_El_Ayoubi

ADDING SHARED PARAMETERS_TEST___erfajo.dyn (10.7 KB)
ADDING SHARED PARAMETERS_TEST__mostafa.dyn (12.3 KB)
shapa.txt (552 Bytes)
Project2.rvt (2.8 MB)

in your attemps, you replaced these values with your own right?


I see from your shared parameter file that the group is called sp1 and the parameter A1

1 Like

yes…too much confusion… :open_mouth::open_mouth::open_mouth:
Anton