Add Elements to existing DisplacementElement Sets

Add Elements to existing DisplacementElement Sets

Thommy_
Advisor Advisor
725 Views
3 Replies
Message 1 of 4

Add Elements to existing DisplacementElement Sets

Thommy_
Advisor
Advisor

Hi all,

I try to create an python code to add elements (model text) to existing DisplacementElement Sets. It is possible to do it manually and I try to find a way to do it automatically with Python in my Dynamo Script. And in addition I'm not sure which method I should use.

 

31-07-_2021_16-53-08.png

Example of the manual process:

tvogt_0-1627822797482.png

 

Do you think GetAdditionalElementsToDisplace() ( https://www.revitapidocs.com/2021.1/97d02f11-7308-579c-031a-5102dc40ae4f.htm ) is suitable method?

 

Goal of the Python Code is to add the elements in the first sublist ("idsToDisplace") to the first DisplacementElement Set. And the second sublist  to the to the second DisplacementElement Set and so on. 

 

tvogt_1-1627823000941.jpeg

Revit 2021 files + dyanmo script:

https://1drv.ms/u/s!Ar9xxoyu3-Zhkf0Ixn63Hpo-INbowg?e=1bix7W

 

Thank you for your time!

Thomas


Thomas Vogt

VDC Technology & Process Manager


EESignature




Revit®, Dynamo, BIM  |  Training und Consulting in Stuttgart

E-Mail | Twitter | LinkedIn | YouTube | Facebook | Blog

0 Likes
Accepted solutions (2)
726 Views
3 Replies
Replies (3)
Message 2 of 4

Thommy_
Advisor
Advisor

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

 

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

# Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

# Import Dynamo Core Nodes
clr.AddReference("DSCoreNodes")
import DSCore
from DSCore import *
# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

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"

 

tvogt_1-1627827461722.png

 


Thomas Vogt

VDC Technology & Process Manager


EESignature




Revit®, Dynamo, BIM  |  Training und Consulting in Stuttgart

E-Mail | Twitter | LinkedIn | YouTube | Facebook | Blog

0 Likes
Message 3 of 4

RPTHOMAS108
Mentor
Mentor
Accepted solution

Why are you not just using SetDisplacedElementIds to amend the collection i.e. query current collection via GetDisplacedElementIds add to it the additional elements and then use SetDisplacedElementIds.

 

I don't think the method DisplacementElement.GetAdditionalElementsToDisplace does anything other than return secondary hosted ids of elements that need to be displaced when you list a set of primary host ids you want to displace. Seems to be only an information tool returning a list of ids. It doesn't state that it displaces anything and the name of the function doesn't give that impression either i.e. would have expected it to be a Set not a Get if that were the case.

 

From Remarks section of RevitAPI.chm for GetAdditionalElementsToDisplace:

"For example, when a wall is displaced, any inserts or hosted elements should also be displaced."

Message 4 of 4

Thommy_
Advisor
Advisor
Accepted solution

hi @RPTHOMAS108 ,

you are right, thank you! I have used now SetDisplacedElementIds:

 

tvogt_0-1627860143154.png

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()

 

 


Thomas Vogt

VDC Technology & Process Manager


EESignature




Revit®, Dynamo, BIM  |  Training und Consulting in Stuttgart

E-Mail | Twitter | LinkedIn | YouTube | Facebook | Blog

0 Likes