Convert DB.FamilyParameter to Elements.FamilyParameter

Hey Guys,

recently i am trying to manipulate a batch of families by deleting and adding certain parameters.
My Script is, thanks to Gavin’s Crumple, working just fine now.
I open the familly docs by path with Crumple’s FamilyDoc.Open and from there on only use Crumple’s Nodes.
The last part i am trying to archieve is to delete FamilyParameters by DataType.
This is working with the OOTB Node FamilyParameters.ParameterType but the node wont work with the kind of FamilyParameter Element i get from Crumple’s Node.
Crumple gives me Autodesk.Revit.DB.FamilyParameter (Or FamilyDocument) but i need Revit.Elements.FamilyParameter to make it work. In the back of my mind i remember reading something about translating DB Elements to Dynamo Elements but i can’t remember.
Does someone have a hint?

@GavinCrump any ideas on this?

2 Likes

To date, the DB.FamilyParameter Type is not supported by the DynamoPythonWrapper, here is a workaround with Reflection

import clr
import sys
import System

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
import Autodesk.Revit.DB as DB

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("System.Reflection")
from System.Reflection import BindingFlags

# get list of DB.FamilyParameter at IN[0] input
lst_familyParameters = UnwrapElement(IN[0])
arrayType = System.Array[System.Type]([DB.FamilyParameter])
ueConstrutor = clr.GetClrType(Revit.Elements.FamilyParameter).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance , None, arrayType, None)

OUT =  [ueConstrutor.Invoke((x,)) for x in lst_familyParameters]
3 Likes

Yep Cyril nailed it. Definitely a Dynamo specific thing as I’m running this no issues in pyRevit toolbars in bulk.

1 Like

Thank you for the response Cyril!
I will try it out at the beginning of next year. For now i splitted the Script in two but i will definitely merge them together with your workaround!

That’s a good hint as well Gavin. Later down the road this feature is supposed to be added to our internal pyRevit Toolbar. Good to know i can fall back to my original plan then.

1 Like

@MaxHue
Were you able to perform this action and troubleshoot the problem?
If so, could you explain the workflow a bit?

Hi Deep,

for a quick solution i splitted the script in 4 small ones each dedicated for a specific task.
For example in one i only used Orchid-Nodes to open families/procession and in another i used only gavin’s nodes to avoid the problem of translating the familyTypes within Dynamo.

This might not be the most elegant solution, but it was a quick one.
So far i have not been able to look more deeply into the possibilites within the Revit API.

I hope this answers your question,
Max

Keep an eye out for Crumple in a month or so. Big update to family/parameter nodes to allow bulk processing a majority of tasks that Orchid does.

2 Likes