# NewFamilyInstance on topo

**URL:** <https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718>\
**Category:** Packages\
**Created:** [November 17, 2014, 4:57am UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718 "2014-11-17T04:57:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jostein\_olsen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jostein_olsen/32/8570_2.png) [@jostein\_olsen](https://forum.dynamobim.com/u/jostein_olsen)\
**Post date:** [November 17, 2014, 4:57am UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718/1 "2014-11-17T04:57:53Z")

</div>

I’ve tried to place site families by a python-script. I once read that if you feed the NewFamilyInstance XYZs and a topo it will still pick the topo’s height in the points you specify.

The inspiration came from here: [http://thebuildingcoder.typepad.com/blog/2010/11/place-site-component.html](http://thebuildingcoder.typepad.com/blog/2010/11/place-site-component.html)

However, once again, I come short. Is anyone willing to give me a pointer to what I should be doing with this script to achieve the stated?(I know I have a lot of imports at the top, but I’ll delete the unnecessary ones in the future.)

I hope someone grabs the challenge! 😉

&nbsp;

![2](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/2X/e/e9aaa776c50424ef8c02b498fb71c6f3f03743b2.png)

&nbsp;

&nbsp;

![1](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/2X/6/6034f3a14d7e14ead0b82fd6a50264a7719585ca.png)

---

<div class="post-metadata">

**Author:** ![Andreas\_Dieckmann](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/andreas_dieckmann/32/365_2.png) [@Andreas\_Dieckmann](https://forum.dynamobim.com/u/Andreas_Dieckmann)\
**Post date:** [November 17, 2014, 5:37am UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718/2 "2014-11-17T05:37:13Z")

</div>

Hello Jostein,

it would help if you could provide your script as text.

Copying it line by line seems like a waste of time… 😉

EDIT: Alternatively, you should at least provide the error message that the Python Script node throws…

---

<div class="post-metadata">

**Author:** ![jostein\_olsen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jostein_olsen/32/8570_2.png) [@jostein\_olsen](https://forum.dynamobim.com/u/jostein_olsen)\
**Post date:** [November 17, 2014, 5:43am UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718/3 "2014-11-17T05:43:51Z")

</div>

Yeah, sorry:

&nbsp;

import clr  
clr.AddReference(‘ProtoGeometry’)  
from Autodesk.DesignScript.Geometry import \*

# Import RevitAPI

clr.AddReference(“RevitAPI”)  
import Autodesk  
from Autodesk.Revit.DB import \*  
from Autodesk.Revit.Creation import \*

# Import DocumentManager and TransactionManager

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

# Import ToDSType(bool) extension method

clr.AddReference(“RevitNodes”)  
import Revit  
clr.ImportExtensions(Revit.Elements)  
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument  
view= doc.ActiveView

#The inputs to this node will be stored as a list in the IN variable.  
dataEnteringNode = IN  
list=IN[0]  
symbol=IN[1]  
topo=IN[2]  
stype=IN[3]

unwrap=[]  
xyzs=[]

for i in list:  
unwrap.append(UnwrapElement(i))

for j in unwrap:  
xyzs.append(unwrap.ToXyz())

try:  
TransactionManager.Instance.EnsureInTransaction(doc)

for k in xyzs:  
NewFamilyInstance(k, symbol, topo, stype)

TransactionManager.Instance.TransactionTaskDone()

OUT = "success."  
except:  
OUT = “failed…”

---

<div class="post-metadata">

**Author:** ![Dimitar\_Venkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/dimitar_venkov/32/2068_2.png) [@Dimitar\_Venkov](https://forum.dynamobim.com/u/Dimitar_Venkov)\
**Post date:** [November 17, 2014, 9:18am UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718/4 "2014-11-17T09:18:41Z")

</div>

Just guessing here, but it looks like you need to unwrap the topo element as well because it’s coming from a dynamo node.

The error from the python node would indeed be helpful 🙂

---

<div class="post-metadata">

**Author:** ![Andreas\_Dieckmann](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/andreas_dieckmann/32/365_2.png) [@Andreas\_Dieckmann](https://forum.dynamobim.com/u/Andreas_Dieckmann)\
**Post date:** [November 17, 2014, 9:34am UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718/5 "2014-11-17T09:34:22Z")

</div>

This should work. Note that this method will _not_ place the site elements _associatively_ like the tool in the GUI. Honestly, I don’t know how they do that, must be some secret sauce.

import clr

### EDIT ### Here I removed the reference to ProtoGeometry - you usually won’t need that in a Revit-related script

# Import RevitAPI

clr.AddReference(“RevitAPI”)  
import Autodesk  
from Autodesk.Revit.DB import \*

### EDIT ### Removed the reference to Revit.Creation

# Import DocumentManager and TransactionManager

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

# Import ToDSType(bool) extension method

clr.AddReference(“RevitNodes”)  
import Revit  
clr.ImportExtensions(Revit.Elements)  
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument

### EDIT ### I can use this to call creation functions later on

doccreation = doc.Create  
view= doc.ActiveView

### EDIT ### Here’s a one-liner for getting all your xyzs

xyzs = [x.ToXyz() for x in UnwrapElement(IN[0])]  
symbol = UnwrapElement(IN[1])  
topo = UnwrapElement(IN[2])

### EDIT ### Create an empty list for the new objects we’ll create

elementlist = list()

### EDIT ### In this last bit I had to make some more changes

### 1. The transaction wraps around everything

### 2. Then we cycle through each xyz

### 3. Then we use try/except for each xyz - in some cases it might work, in others maybe not

### 4. There’s a bug in the Dynamo build I am currently using, so I am adding the structural type directly in Python, not from an input.

### 5. Elements that were created successfully get added to the output list, for failed elements we add an empty list (may become important if need to filter for success or failure)

TransactionManager.Instance.EnsureInTransaction(doc)

### 6. Each newobj should actually be returned as newobj.ToDSType(False), but that is broken in my current build as well…

for xyz in xyzs:  
try:  
newobj = doccreation.NewFamilyInstance(xyz, symbol, topo, Structure.StructuralType.NonStructural)  
elementlist.append(newobj)  
except:  
elementlist.append(list())  
TransactionManager.Instance.TransactionTaskDone()  
OUT = elementlist

---

<div class="post-metadata">

**Author:** ![Andreas\_Dieckmann](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/andreas_dieckmann/32/365_2.png) [@Andreas\_Dieckmann](https://forum.dynamobim.com/u/Andreas_Dieckmann)\
**Post date:** [November 17, 2014, 9:38am UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718/6 "2014-11-17T09:38:36Z")

</div>

Here’s a screenshot so you can see the indentation. Would be nice if the forum would not destroy that type of info when copy/pasting.

![placeontopo-python](https://cdck-file-uploads-us1.s3.dualstack.us-west-2.amazonaws.com/flex022/uploads/dynamobim/original/2X/5/5eb75b6d78b5724d29785a8cb98138718463d8fb.png)

---

<div class="post-metadata">

**Author:** ![jostein\_olsen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jostein_olsen/32/8570_2.png) [@jostein\_olsen](https://forum.dynamobim.com/u/jostein_olsen)\
**Post date:** [November 17, 2014, 1:05pm UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718/7 "2014-11-17T13:05:35Z")

</div>

Thanks Andreas! You must be very ideally driven to even bother responding, even better: you deliver a copy/paste solution, AND to top it off you annotate the py-script so that amateurs like me can learn. That’s inspirational right there!

However I’m not able to get the elements to “obtain” the Z-value from the topo. they all get set to whatever Z-value that was the input.

I based my hopes on the article above and the following line:

“\<span style=“color: #232323;”\>It turns out the Z coordinate can be zero, by specifying TopoSurface it will be anchored correctly”\</span\>

I’ve looked through this script in VB, but I can’t find anything. I can’t attach it here because the forum won’t let me, but look in the link above if you’r interested.

Anyways, thanks yet again.

&nbsp;

---

<div class="post-metadata">

**Author:** ![Andreas\_Dieckmann](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/andreas_dieckmann/32/365_2.png) [@Andreas\_Dieckmann](https://forum.dynamobim.com/u/Andreas_Dieckmann)\
**Post date:** [November 18, 2014, 2:19am UTC](https://forum.dynamobim.com/t/newfamilyinstance-on-topo/718/8 "2014-11-18T02:19:41Z")

</div>

🙂

Well, I’ve been away from the forum for about three months now, so I figured a little extra effort was okay. Only took a couple of minutes in any case - your code was a good basis.

In your blog post ([http://jbdynamo.blogspot.no/2014/11/extend-pile-length-to-topo-its-working.html](http://jbdynamo.blogspot.no/2014/11/extend-pile-length-to-topo-its-working.html)) you are mentioning the ReferenceIntersector method. I had that working in 0.6.3 but haven’t managed to build a bug-free version for 0.7 yet. This may indeed be a good use case. But what really bugs me is the fact that if I place a site element on a topo using the GUI, I can drag that element across the topo and its height will adapt.
