Create new family parameter

Dear Dynamo colleagues,

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.

I would be very grateful for any kind of help.

Hi @c.poupin
I apologize for disturbance.
Is there a way to create a new family shared parameter via api, while .rfa file is opened?

Thank you very much for the help.

Hi @george guess in Crumple there is some nodes for that…here is an example with synthesize toolkit in a open family document

2 Likes

1 Like

Thank you very much @sovitek !

I just checked Crumble, and it is not an open-source project:

I can’t see how to replicate this functionality via Revit API.

ok dont know Crumple nodes so much…maybe Gavin can bring light @GavinCrump

1 Like

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.

2 Likes

Hi @GavinCrump ,
Thank you very much for the reply.
All Crumble nodes are compiled C# code?

Is it possible to see the source code of the Parameters.CreateFamilySharedParamater node?

I would be very grateful for this help.

99% certain you can find the source code you need in open source repositories.

Where have you looked so far? This is a pretty good starting point: DynamoRevit/src/Libraries/RevitNodes/Elements/Parameter.cs at 07d1b9e08b57827d84b7effd2805b73a94c5fa0d · DynamoDS/DynamoRevit · GitHub

1 Like

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.

The add parameter (C#) code is here:

1 Like

Thank you very much @jacob.small ! I haven’t look anywhere. I though the nodes Sovitek posted are Crumble nodes. Thank you again.

Thank you very much for the help @GavinCrump !

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

Or did I misunderstand you?

Here is a sample example, assuming that the parameter share file is loaded in Revit

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…

1 Like

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.

1 Like