Element of family type

Hi all,

I have a problem and trying to find a solution. What i have is a script that places adaptive family’s, and then 2 parameters of the placed family need to be set.(because i place multiple times the same adaptive family but on different locations, and everyone of them has a different number at its parameter)


This is my script. for setting the parameters:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from Autodesk.Revit.DB import FilteredElementCollector, Family
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

doc = DocumentManager.Instance.CurrentDBDocument
name = IN[0]
compact = IN[1]
newcentral = IN[2]
isworkshared = IN[3]
elmts = IN[4]
parmNam = IN[5]
val = IN[6]
geschiedenis = []
geschiedenis_val = []
nieuwe_par = []
nieuwe_val = []
for i in range(len(name)):
	geschiedenis.append([])
	geschiedenis_val.append([])
	nieuwe_par.append([])
	nieuwe_val.append([])
	TransactionManager.Instance.EnsureInTransaction(doc)
	for j in range(len(val[i])):
		TransactionManager.Instance.EnsureInTransaction(doc)
		Revit.Elements.Element.SetParameterByName(elmts[i], parmNam[0][j], val[i][j])
		#Revit.Elements.Element.SetParameterByName(elmts[i], '4D-code', val[i][j])
		nieuwe_par[i].append(parmNam[0][j])
		nieuwe_val[i].append(val[i][j])
		TransactionManager.Instance.ForceCloseTransaction()
OUT = i, j, nieuwe_par, nieuwe_val,elmts

i have two questions:
1- this script now needs to have as input “Elements” → but i would like to go from “AdaptiveComponent.Type” to my script? ? is this possible?

2- when i want to use the same script to place at a different location adaptive families, some of them will be the same as already placed but will have a different value for it’s parameter. but with the use of “All elements of family type” i starts also reading the existing families and mesh up the setting of the parameter.

Hope someone of you know if this is possible?

Thanks in advance

Gr Edward

Hi all,

I’m Quite curious about your thought if the above could be done?

@jacob.small @c.poupin @Kulkul @sovitek @solamour hope someone of you know who might can help me with this?

Many thanks in advance

Gr Edward

Hi,
after placing new adaptive families (at the end of script), you can try to retrieve all (the new and old families) and set the parameters (instance and type)

a simple example

import clr
import sys
import System
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS

#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

IsAdaptive = System.Predicate[System.Object](lambda x : DB.AdaptiveComponentInstanceUtils.IsAdaptiveFamilySymbol(x.Symbol))
allAdapInstances = List[DB.Element](FilteredElementCollector(doc).OfClass(FamilyInstance).ToElements()).FindAll(IsAdaptive)

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

for elem in allAdapInstances:
    #if elem.Name == "????": # add a condition if necessary
    if True:
        elemType = elem.Symbol
        family = elem.Symbol.Family
        #
        # set Element Parameter
        elementPara = elem.LookupParameter("Commentaires")
        elementPara.Set("Merry")
        # set Type Parameter
        elementTypePara = elemType.LookupParameter("Commentaires du type")
        elementTypePara.Set("Christmas")

TransactionManager.Instance.TransactionTaskDone()

OUT = allAdapInstances
2 Likes

@c.poupin
thanks for your reaction.
I did now bypass this problem by using the Rhythm package node “ʳʰʸᵗʰᵐ|Elements.SetParameterValueByNameCaSeiNSeNSiTiVe” directly after placing the adaptive families.
It works for now. but i’m still trying to get this into a python script, Because it’s our company policy that we don’t want to use third party packages as it’s unkown when they will stop updating there packages into newer versions.

SO i did some research and found the sourcode that is inside the DLL file of the package:

   /// <summary>
    /// This node will set a parameter value by search string, regardless of case of the search string. Also accounts for misspellings.
    /// Note: If the parameter name appears multiple times it will retrieve the first one that it finds.
    /// </summary>
    /// <param name="element">The element to get parameter from.</param>
    /// <param name="parameterName">The parameter name.</param>
    /// <param name="value">The parameter value.</param>
    /// <returns name="element">The element that had parameters set.</returns>
    /// <search>CaseInsensitive</search>
    [NodeCategory("Actions")]
    public static Element SetParameterValueByNameCaSeiNSeNSiTiVe(
      Element element,
      string parameterName,
      object value)
    {
      Document currentDbDocument = DocumentManager.Instance.CurrentDBDocument;
      Parameter[] parameters = element.Parameters;
      List<int> source = new List<int>();
      foreach (Parameter parameter in parameters)
        source.Add(StringComparisonUtilities.Compute(parameterName, parameter.Name));
      int index = source.IndexOf(source.Min());
      string name = parameters[index].Name;
      object obj1 = value;
      TransactionManager.Instance.EnsureInTransaction(currentDbDocument);

so is started to try to convert this into my python script. this is how far i am at the moment.


When removing the # at line 29 i get the following error:

So i’m now trying to figure out what the function between <> means.

I hope someone can help me with this.

this is the code i have right now

import clr
import sys
import System
from System.Collections.Generic import List, IList, Dictionary
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
element = IN[0]
parameterName = IN[1]
value = IN[2]
# Place your code below this line
for i in range(len(element)):
	Parameter = [] 
	parameters = element[i].Parameters;
	List<int> source = new List<int>();
#foreach (Parameter parameter in parameters)
#source.Add(StringComparisonUtilities.Compute(parameterName, parameter.Name));
#int index = source.IndexOf(source.Min());
#string name = parameters[index].Name;
#object obj1 = value;
#TransactionManager.Instance.EnsureInTransaction(currentDbDocument);


# Assign your output to the OUT variable.
OUT = parameters

Many Thanks in advance

There is a good documentation how to use the .NET framework APIs directly from IronPython here

https://ironpython.net/documentation/dotnet/

Note:
This question is no longer related to the topic of this thread.

2 Likes