Adding Elements to DisplacementElement Set (need help with Python code)

Hi guys!

I try to place families (some model text nested in a face based generic family) onto displaced elements. I couldn’t get successfully the faces of the DisplacementElement. Now I try to get the original Element from the DisplacementElement (If you hit TAB onto the displacmentElement you can select the original family (“parent element”), to use this for placing my families and moving them to the place where the displacement elements are.

(The warnings are null values and can be neglected)

  • Is there a way to work directly with the displaced families to place families onto the surface?
  • How can I get the parent element of the DisplacementElement?
  • Any other suggestions / ideas?
  • Bonus question: Why is my model text family not exactly in the middle of the wall?

Thanks,
Thomas

Hello…probably something here could help…


Thomas.dyn (31.0 KB)

1 Like

There is a method in Revit API for that:

Are you able place families manually in Revit? If not then you can’t do through programmatically.

Is your family Host Face? Check Location Points Preview before placing them.

3 Likes

@Kulkul …amazing :wink:

1 Like

Thank you @Kulkul the method you suggested works perfectly!

/edit:

I know now why some elements are not translated: Because the placement surface of the original element and the surface of the translated elements is not the same. Thus such elements will not be created at all. So my new strategy is to place the model text at the position of the original elements and add them to the DisplacementElement Set. By doing this way, all elements get translated correctly. I have recreated most of the graph.

In the Revit file are 3 Displacement Elements. One of the Displacement Elements consits of 2 Elements (red arrow). As you can see the model text is created sucessfully at the original position of the displaced elements:

I can add the model text elements with the ui tools (manually) sucessfully:

But I fail to create the python code to automate the process:

The goal of the python code, is to add the model text elements to the existing displacement elements (have a look far on the right of the graph).

I found this method:
https://www.revitapidocs.com/2021.1/97d02f11-7308-579c-031a-5102dc40ae4f.htm

But I’m not sure if it is the correct method.

Thank you for your help!
Thomas

I have tried to improve the Python code. I get not warning anymore, but the elements are not added to the DisplacementElement Set :frowning:

# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Code unterhalb dieser Linie platzieren

parDisEle = UnwrapElement(IN[0])
activeView = UnwrapElement(IN[1])
idsToDisplace = UnwrapElement(IN[2])

TransactionManager.Instance.EnsureInTransaction(doc)

for i in range( len(parDisEle) ):
    diplEle = parDisEle[i]
    for j in idsToDisplace[i]:
        lst = []
        lst.append(j)
        for k in lst:
            e = ElementId(k)
            diplEle.GetAdditionalElementsToDisplace(doc, activeView, e)


TransactionManager.Instance.TransactionTaskDone()

# Weisen Sie Ihre Ausgabe der OUT-Variablen zu.
OUT = "None"

I have solved it with the method SetDisplacedElementIds :slight_smile:

First it is important to create an .net icollection of the elements. And to have no conflict you need to import it with an different name. And then all you need to do is to add the elements which are already in a displacementElement Set to the list with the new elements run this python code on it:


clr.AddReference('System')
from System.Collections.Generic import List as netList

disEle = UnwrapElement(IN[0])
activeView = UnwrapElement(IN[1])
idsToDisplace = UnwrapElement(IN[2])

TransactionManager.Instance.EnsureInTransaction(doc)

for j in range( len(disEle) ):
    eleIds = []
    for k in idsToDisplace[j]:
        eleIds.append(ElementId(k))
    netEleIds = netList[ElementId](eleIds)
    diplEle = disEle[j].SetDisplacedElementIds(netEleIds)

TransactionManager.Instance.TransactionTaskDone()
1 Like