# \[solved\] Just insert somme object whit a table

**URL:** <https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930>\
**Category:** Uncategorized\
**Created:** [March 4, 2019, 6:11pm UTC](https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930 "2019-03-04T18:11:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JlpOcaBim](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@JlpOcaBim](https://forum.dynamobim.com/u/JlpOcaBim)\
**Post date:** [March 4, 2019, 6:11pm UTC](https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930/1 "2019-03-04T18:11:18Z")

</div>

Hi everybody

I have a problem what turn me mad :

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/b/4b90a2732dda40739ff1c2effddde33ab9d5035e.png)

```
# Activer la prise en charge de Python et charger la bibliothèque DesignScript
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# ressources REVIT
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
from Autodesk.Revit.DB.Structure import StructuralType
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

# Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
dataEnteringNode = IN

famtype=IN[1]
# Placer votre code au-dessous de cette ligne

moa=&quot;&quot;
for i in IN[0] :

id = i[0]
nom = i[1]
type = i[2]
xy1 = i[3]
xy2 = i[4]
z1 = i[5]
z2 = i[6]
d1 = i[7]
d2 = i[8]

symbol = UnwrapElement(IN[1])
element = UnwrapElement(IN[2])
niveau = IN[2]

#NewFamilyInstance Method (Reference, XYZ, XYZ, FamilySymbol)
#NewFamilyInstance Method (Face, XYZ, XYZ, FamilySymbol)
newobj = doc.Create.NewFamilyInstance(element,xy1,xy2,symbol)

#forcer parametre de famille &quot;d1&quot; et &quot;d2&quot; ???

# Affectez la sortie à la variable OUT.
OUT = 0

```

“xy1” is the insert point, “xy2” is the directional vector.  
“d1” and “d2” are Somme family parameter to force

Please help 😕

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [March 4, 2019, 6:43pm UTC](https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930/2 "2019-03-04T18:43:33Z")

</div>

I haven’t been able to find any NewFamilyInstance Method overloads which accept the same arguments that you’re giving it (Level, XYZ, XYZ, FamilySymbol). There _are_ some overloads which have an XYZ as the first argument e.g. (XYZ, FamilySymbol, Level, StructuralType), but none which have a Level as the first argument.

---

<div class="post-metadata">

**Author:** ![JlpOcaBim](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@JlpOcaBim](https://forum.dynamobim.com/u/JlpOcaBim)\
**Post date:** [March 5, 2019, 9:09am UTC](https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930/3 "2019-03-05T09:09:04Z")

</div>

in fact there are many method :  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/2/52f07968b1b6803a938ba7119bdde157ea3e8dc5.png)  
( [Autodesk.Revit.Creation.ItemFactoryBase.NewFamilyInstance Method (2019)](http://www.revitapidocs.com/2019/451ee414-cea0-e9bd-227b-c73bc93507dd.htm) )

My objective is to place some instance of a same family to different points with different orientation and different values of parameters. all this data gived by a table.

---

<div class="post-metadata">

**Author:** ![JlpOcaBim](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@JlpOcaBim](https://forum.dynamobim.com/u/JlpOcaBim)\
**Post date:** [March 5, 2019, 12:49pm UTC](https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930/4 "2019-03-05T12:49:35Z")

</div>

🤨 “expected Level, got Level” ???

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/0/8062c7d97ac860694f11715d7f6b6405144c2aa4.png)

---

<div class="post-metadata">

**Author:** ![JlpOcaBim](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@JlpOcaBim](https://forum.dynamobim.com/u/JlpOcaBim)\
**Post date:** [March 5, 2019, 1:59pm UTC](https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930/5 "2019-03-05T13:59:07Z")

</div>

A begining of responce to myself :

```
import clr
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import *
clr.AddReference('System')
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
symbol = UnwrapElement(IN[1])
refPlane = UnwrapElement(IN[2])

symbol.Activate()
reference = Reference(refPlane)

for i in IN[0] :

	id = i[0]
	nom = i[1]
	type = i[2]
	xy1m = i[3]
	xy2 = i[4]
	z1 = i[5]
	z2 = i[6]
	d1 = i[7]
	d2 = i[8]
	lg = i[9]
	xy1ft = i[10]

	TransactionManager.Instance.EnsureInTransaction(doc)
	new = doc.Create.NewFamilyInstance(reference,xy1ft,xy2,symbol)
	TransactionManager.Instance.TransactionTaskDone()
#Assign your output to the OUT variable.
OUT = 0 

```

but be careful of that (in the family category parameter definition) :

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/c/7cf2d5964cb131a96cd560fc0b43ad1b4104c62f.png)  
Is possible to convert a point coordinate from feet to mm without a “\*304.8” ?

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [March 5, 2019, 3:30pm UTC](https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930/6 "2019-03-05T15:30:50Z")

</div>

> 🤨 “expected Level, got Level” ???

Not sure why this is happening. Usually when you get an error like this, you’re providing a Dynamo object when it’s expecting a Revit object. The two classes have the same name, so the error is very confusing. Here’s an example:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/d/3d6ea8e265f311dae68b8f4f4856200530648a65.png)

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

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

level_dyn = IN[0]
level_rvt = UnwrapElement(level_dyn) # Convert to Revit Object

dyn_type = type(level_dyn)
rvt_type = type(level_rvt)

type_test = dyn_type == rvt_type

OUT = [str(dyn_type),
	   str(rvt_type),
	   isinstance(level_dyn, Level), # Test if Level is Revit Level
	   isinstance(level_rvt, Level)];

```

You can see that the isinstance() function returns `false` for the Dynamo object and `true` for the Revit object. However, you’re already unwrapping the element, so it shouldn’t be raising a TypeError.

Regarding the unit conversion, there is a UnitUtils class which you can easily use to convert between units:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/c/3ccf9a61abbb3cc43c4391e0fbdf852caa7d30a8.png)

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

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

element = UnwrapElement(IN[0])
len_internal = element.LookupParameter('Length').AsDouble()
DUT_mm = DisplayUnitType.DUT_MILLIMETERS
len_converted = UnitUtils.ConvertFromInternalUnits(len_internal, DUT_mm)

OUT = len_internal, len_converted

```

Regarding your initial question, I still don’t really have an answer. Would you be able to provide the .dyn and .rvt or a version with some dummy data?

---

<div class="post-metadata">

**Author:** ![JlpOcaBim](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@JlpOcaBim](https://forum.dynamobim.com/u/JlpOcaBim)\
**Post date:** [March 7, 2019, 10:53am UTC](https://forum.dynamobim.com/t/solved-just-insert-somme-object-whit-a-table/32930/7 "2019-03-07T10:53:52Z")

</div>

another reply to myself :  
schema :

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/7/17eaa6772e070fb6ff65385fed807a5137e344e3.png)

```
import clr
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
from Revit.Elements import *
clr.AddReference('System')
from System.Collections.Generic import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
symbol = UnwrapElement(IN[1])
refPlane = UnwrapElement(IN[2])

symbol.Activate()
reference = Reference(refPlane)

for i in IN[0] :

id = i[0]
nom = i[1]
type = i[2]
xy1m = i[3]
xy2 = i[4]
z1 = i[5]
z2 = i[6]
d1 = i[7]
d2 = i[8]
lg = i[9]
xy1ft = i[10]

TransactionManager.Instance.EnsureInTransaction(doc)
# créer l'instance :
new = doc.Create.NewFamilyInstance(reference,xy1ft,xy2,symbol)
# renseigne les parametres
new.LookupParameter(&quot;Distance_entre_regards&quot;).Set(float(lg)/0.3048);
new.LookupParameter(&quot;D_regard_1&quot;).Set(float(d1)/304.8);
new.LookupParameter(&quot;D_regard_2&quot;).Set(float(d2)/304.8);
new.LookupParameter(&quot;Ai_depart&quot;).Set(float(z1)/304.8);
new.LookupParameter(&quot;Ai_arrive&quot;).Set(float(z2)/304.8);

#TODO recupérer ID

TransactionManager.Instance.TransactionTaskDone()

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

```

All is solved 🙂
