Shared parameter as Project parameter

Shared parameter as Project parameter

Anonymous
Not applicable
4,706 Views
6 Replies
Message 1 of 7

Shared parameter as Project parameter

Anonymous
Not applicable

I have tried two methods using Dynamo to create a project parameter:

- By adding new shared parameters only bound to the category "Project Information" with the custom node below.

- By using the node "Create Project parameter".

 

In both cases the project parameter is available, but the binding with for instance a title block containing the same shared parameter is not working. As if the parameter has a GUID mismatch, but they both come from the same external shared parameter file.

 

Is there anything I'm missing? The active shared parameter file is correct, and the specific parameters have been added to the title block family. Any of the added project parameters can not be edited in the sheet's title block.

 

For the first option I'm using a modified version of Konrad's solution to create shared parameters. This one can handle multiple categories.

 

 

#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(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:
	cats = app.Create.NewCategorySet()
	
	# Insert each category instead of one here...
	for CaT in _category[k]:
		builtInCategory = System.Enum.ToObject(BuiltInCategory, CaT.Id)
		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 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

 

 

0 Likes
Accepted solutions (1)
4,707 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk
Accepted solution

Afaik Revit API does not support creation of project parameters.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 7

bchaney0927
Advocate
Advocate

I would like to be able to add project parameters to my projects.  One example is being able to add a list of consultants with roles and contact information.  Is there a way to do this, or do I need to make a new title block for every project?

 

Thanks,

Bennett

 

Bennett Chaney, AIA

http://bscarchdesphot.com

0 Likes
Message 4 of 7

scheerd
Alumni
Alumni

Check out Extensible Storage.  Not as easy as SPs, but that's the only way I know of saving information to a project at the top level.  Very flexible, and can store lots of data in lots of formats.

0 Likes
Message 5 of 7

jeremytammik
Autodesk
Autodesk

Check out the collection on articles on extensible storage here:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.23

 

Especially this one one global storage:

 

https://thebuildingcoder.typepad.com/blog/2016/04/named-guid-storage-for-project-identification.html

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 6 of 7

axelrasmussen
Explorer
Explorer
Did someone find a solution to this problem? I think it should be possible now in the newest versions of Revit/Dynamo, right?
I'm having the same Issue (probably GUID mismatch) 😕
0 Likes
Message 7 of 7

axelrasmussen
Explorer
Explorer
Okay, the problem was that there were two Projectparameters with a similar Name "GFZ" and GFZ Test". I was trying to set "GFZ" but I assume that the setParameter-Node was taking "GFZ Test"...
I deleted "GFZ Test" from the sharedParameter.txt and it worked 🙂
0 Likes