[solved] Just insert somme object whit a table

Hi everybody

I have a problem what turn me mad :

# 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=""
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 "d1" et "d2" ???

# 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 :confused:

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.

in fact there are many method :
image
( Autodesk.Revit.Creation.ItemFactoryBase.NewFamilyInstance Method (2019) )

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.

:face_with_raised_eyebrow: “expected Level, got Level” ???

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


Is possible to convert a point coordinate from feet to mm without a “*304.8” ?

:face_with_raised_eyebrow: “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:

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:

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?

another reply to myself :
schema :

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("Distance_entre_regards").Set(float(lg)/0.3048);
new.LookupParameter("D_regard_1").Set(float(d1)/304.8);
new.LookupParameter("D_regard_2").Set(float(d2)/304.8);
new.LookupParameter("Ai_depart").Set(float(z1)/304.8);
new.LookupParameter("Ai_arrive").Set(float(z2)/304.8);

#TODO recupérer ID

TransactionManager.Instance.TransactionTaskDone()

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

All is solved :slight_smile:

1 Like