Is it possible to create a new family shared parameter, via Dynamo Python?
But while Metric Generic Model Adaptive.rfa file is opened?
I searched, and found a solution made by@c.poupin which works perfectly when .rvt file is opened.
Is there a solution which works when only .rfa file is opened (without any other .rvt file being opened in Revit)?
I did found similar topics on this forum, but they are all before the Revit API 2022 DB.SpecTypeId changes.
It is open in the aspect I share all my dyfs without the need for a package manager install.
I don’t currently have a node for creating new shared parameters but there is a node for adding existing ones to families as well as a sample script for that process also.
They are generally using Python. If you install via package manager you can view the node content by right clicking on the nodes and editing temporarily.
I dont have a node with that name in Crumple though. That’s a Rhythm node which you can view source (C#) code for on the github for it. My equivalent node is a bit different and is called FamilyDoc.AddSharedParameter.
So all your Crumble nodes, are written in python or C#?
The source code of the python ones - I can see by right clicking on them.
The source code of the C# ones - I can see at OpenMEP/OpenMEPRevit at dev · chuongmep/OpenMEP · GitHub
import clr
import sys
import System
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
def get_external_def_by_name(para_name):
global dictsharParaDef
for group, lst_external_def in dictsharParaDef.items():
for ext_def in lst_external_def:
if ext_def.Name == para_name:
return ext_def
lst_shparameter_name = IN[0]
lst_GroupType = IN[1]
lst_is_instance_parameter = IN[2]
#
result = []
# get all definitions in the SharedParameterFile
spf = app.OpenSharedParameterFile()
if spf is not None:
dictsharParaDef = {}
spfGroups = spf.Groups
for group in spfGroups:
setExternalDef = group.Definitions
dictsharParaDef[group.Name] = setExternalDef
if doc.IsFamilyDocument and spf is not None:
owner_family = doc.OwnerFamily
famManager = doc.FamilyManager
TransactionManager.Instance.ForceCloseTransaction()
TransactionManager.Instance.EnsureInTransaction(doc)
#
# add Parameters
for nameP, groupType, is_instance in zip(lst_shparameter_name, lst_GroupType, lst_is_instance_parameter):
ext_def = get_external_def_by_name(nameP)
#
if ext_def is not None:
famManager.AddParameter(ext_def, DB.ForgeTypeId(groupType.TypeId), is_instance)
result.append(f"parameter '{nameP}' added")
else:
result.append(f"parameter '{nameP}' failed")
TransactionManager.Instance.TransactionTaskDone()
OUT = result
the link mentioned has nothing to do with adding parameters to families…
My package is written using Python nodes in Dynamo. You can’t view that in a github format naturally, but the dyf files on there can be viewed in Dynamo by installing my package.