How to feed with XYZ?

Hello,

i want to create a new familyInstance and delete the old one → like refresh the placement.

import clr
import sys 

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

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

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

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#variables
p1 =  IN[0]
fam = IN[1]
level = IN[2]

#functions
def DeleteElement(el):
	t1 = SubTransaction(doc)
	t1.Start()
	deleted = doc.Delete(el.Id)
	t1.Commit()
#transaction
trans = Transaction(doc, "Place FamilyInstance")
    
trans.Start()
ins = doc.Create.NewFamilyInstance(p1, fam, level,Structure.StructuralType.NonStructural)
DeleteElement(ins)

trans.Commit()


OUT = "Done"

thats my code so far

KR

Andreas

Hello @Draxl_Andreas

Is there a reason why you don´t want to just move (translate) the family instance to a new location?

Regarding your code, you are coding with revit methods (Create.NewFamilyInstance). Revit methods don´t work with dynamo points, they need XYZ as you can see in the documentation:

You have to convert like that

point.ToXyz()

Or you can create an XYZ like that

XYZ(point.X, point.Y, point.Z)

Regarding your error, it says input 0 is a list, what is not right as it should be a single point, strange.
Please verify if the point node is outputting a single element.

Should the code work with a list of points when finished?

1 Like

@gerhard.p ,

it helped, for any reason i have to feed with a symbol instead of a instance … how?

i just test it with a single point …

its more about learning transactions … i want to place a instance on en existing one and delete the old

KR

Andreas
P1.rvt (604 KB)
PyTransaction.dyn (14.5 KB)

If you want to place a family instance with standard methods you have to define which family(type) you want to use. It´s like in revit UI, you can not place an instance without knowing which family to use.

If you want to use a famliy instance as input you have to add something to your code. You have to get the family symbol from the instance.

family_symbol = family_instance.Symbol

family symbol is pretty much the family type.

1 Like

grafik

grafik

This is because you did not unwrap your element.

if you don´t unwrap your element you can use element.Type

if you unwrap your element you can use element.Symbol

3 Likes

@gerhard.p ,


it resists to become a symbol, CPython and IronPython 2 does not work :frowning:

Hi,
To respond to your topic
Here is a variation using the family location (no need to delete and recreate)



import clr
import sys

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

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

doc = DocumentManager.Instance.CurrentDBDocument

elt=IN[0]
dec=IN[1]

fam_instance=UnwrapElement(elt)
pos=fam_instance.Location
new_pos=XYZ(pos.Point.X+dec[0]/0.3048,pos.Point.Y+dec[1]/0.3048,pos.Point.Z+dec[2]/0.3048)

TransactionManager.Instance.EnsureInTransaction(doc)
pos.Point=new_pos
TransactionManager.Instance.TransactionTaskDone()

OUT = pos,str(fam_instance)

if you want to use a new point (you convert it to Point.Revit with the dynamo add-ons)
new_pos becomes smaller
cordially
christian.stan

1 Like

You can work with the type. Symbol and type is the same in this context.

p1 =  IN[0]
fam = UnwrapElement(IN[1])
level = UnwrapElement(IN[2])
symb = fam.Symbol

trans = Transaction(doc, "Place FamilyInstance")
    
trans.Start()
ins = doc.Create.NewFamilyInstance(p1.ToXyz(), symb, level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural)

trans.Commit()

OUT = ins

2 Likes