Add Shared Parameter to Project

Hi guys, do you solved the problem? The other mentioned solutions dont work for me in the other Thread, i dont have the necessary nodes, i only get a null or with the excel sheet my dynamo crush. I want to create parameter groups and parameters into System families. Is the dll up to date? Should i Go on with this Thread here? I am working with revit 2017. thanks

@Balko this topic is solved already.

1 Like

Hi @Balko,

Although this is maked as solved I have had a quick look into this.

The .dll is up to date, I have tested this morning in 2017 and no issues. I made a few tweaks since the last version to take out some of the humourous debug messages I wrote to make testing less boring, and modified some of the nesting in the list structure for the Document.GetSharedParamsInGroup node. Here is a screenshot below…

Here is the .dll and example script shown above.

Note: This only adds shared params to Family documents, the shared param file must be loaded into the family document before running otherwise it can’t be read and will fail.

I believe Clockwork has some nodes to create/modify the shared param file if you are doing it with excel. You will need to have that run first upstream before running this or it will fail as it relies on having those params and shared param file loaded. All ports are of type string so you could create a workflow quite easily I think to create and add Shared Params on the fly using just the string values.

To take this further, you could use the awesome Dynamo Automation Package by Anreas Diekmann to automate runs on multiple families (although I have not tested this it would be an interesting workflow) and have a whole bunch of company standard Params pushed to all your Family content. If this interests you please have a look at the GitHub wiki link below…

I hope this helps in what you are trying to do.

Cheers,
Dan

2 Likes

Where in your script are your python placed. I’ve come as far as you were in the original topic except that I have no idea where the code should be placed? Is it even necessary to use python code to create a shared parameter through dynamo?

Hi @amyll

You should paste the code inside the custom node:

Right click on the mouse, “Edit Custom Node…”, then appears this Window:

Then Select the Python Script Node and again: Right click onthe mouse, “Edit”, then appears this other Window:

Here you can paste all that Script and Save it!

Hope that was what you mean.

Regards

It was, Raul. I pasted the script and overwrote from line 67-88 in the Python Script, but now my Watch Node says “Function”?
I did some thing wrong, didn’t I? :slight_smile:

I forgot to wire ‘Instance’ with True boolean. Now it says “null”…
Are you able to see if im doing anything wrong?


@amyll

Try all this code:

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

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

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

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

from System.Collections.Generic import *

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
import System
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

_paramName = IN[0]
_groupName = IN[1]
_paramType = IN[2]
_visible = IN[3]
_category = IN[4]
_paramGroup = IN[5]
_instance = IN[6]

def ParamBindingExists(_doc, _paramName, _paramType):
	map = doc.ParameterBindings
	iterator = map.ForwardIterator()
	iterator.Reset()
	while iterator.MoveNext():
		if iterator.Key != None and iterator.Key.Name == _paramName and iterator.Key.ParameterType == _paramType:
			paramExists = True
			break
		else:
			paramExists = False
	return paramExists

def RemoveParamBinding(_doc, _paramName, _paramType):
	map = doc.ParameterBindings
	iterator = map.ForwardIterator()
	iterator.Reset()
	while iterator.MoveNext():
		if iterator.Key != None and iterator.Key.Name == _paramName and iterator.Key.ParameterType == _paramType:
			definition = iterator.Key
			break
	message = None
	if definition != None:
		map.Remove(definition)
		message = "Success"
	return message

def addParam(doc, _paramName, _visible, _instance, _groupName, _paramGroup, k):
	message = None
	if ParamBindingExists(doc, _paramName, _paramType):
		if not RemoveParamBinding(doc, _paramName, _paramType) == "Success":
			message = "Param Binding Not Removed Successfully"
		else:
			message = None
			
	group = file.Groups.get_Item(_groupName)
	if group == None:
		group = file.Groups.Create(_groupName)	

	if group.Definitions.Contains(group.Definitions.Item[_paramName]):
		_def = group.Definitions.Item[_paramName]
	else:
###		_def = group.Definitions.Create(_paramName, _paramType, _visible)
		
		_def = group.Definitions.Create(opt)
		
		param = doc.ParameterBindings.Insert(_def, bind, _paramGroup)
	return message
#"Start" the transaction
TransactionManager.Instance.EnsureInTransaction(doc)

try:
	file = app.OpenSharedParameterFile()
except:
	message = "No Shared Parameter file found."
	pass
k=0
while k<_paramName.Count:
	builtInCategory = System.Enum.ToObject(BuiltInCategory, _category[k].Id)
	cats = app.Create.NewCategorySet()
	cats.Insert(doc.Settings.Categories.get_Item(builtInCategory))
	if _instance[k]:
		bind = app.Create.NewInstanceBinding(cats)
	else:
		bind = app.Create.NewTypeBinding(cats)
	
	opt = ExternalDefinitionCreationOptions(_paramName[k], _paramType[k])
	opt.Visible = _visible[k]
	
	if isinstance(_paramName[k], list):
		###for i, j, k in zip(_paramName[k], _visible[k], _instance[k]):
		for i in _paramName[k]:
			message = addParam(doc, i, _visible[k], _instance[k], _groupName[k], _paramGroup[k], k)
	else:
		message = addParam(doc, _paramName[k], _visible[k], _instance[k], _groupName[k], _paramGroup[k], k)
	k=k+1

# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable
if message == None:
	OUT = "Success"
else:
	OUT = message

For me is working.

I’m running Revit 2015 with Dynamo Version 1.21

Regards

5 posts were split to a new topic: Archi-lab Add Shared Parameter getting null