FamilyInstance.SetRotation and Revit API problems

1,250 views
Skip to first unread message

Prof Ari Monteiro

unread,
May 9, 2016, 9:39:03 AM5/9/16
to RevitPythonShell
Hi, everyone!

I'm trying to use FamilyInstance.SetRotation within a Python script, but the objects are being rotated using the project origin as reference.

I would like to rotate the family instance around insertion point.

I noticed that when using the node FamilyInstance.SetRotation it works, but I want to do this from a Python script node.

I tried using the guidelines in this post:

But I have a problem when I declare the reference "from Autodesk.Revit.DB import *". When I do this the method "ByCoordinates" of the standard Dynamo class "Point" doesn't work. There seems to be a conflict of namespace.

Anyway, I'd rather run the FamilyInstance.SetRotation method within a Python script, instead of using the guidelines in this post.

Here the my Python Script. My problem is on the line indicates by a red comment:

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

# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit

# Import Revit elements & geometry
from Revit.Elements import *
from Revit.GeometryConversion import *

# Import Services, Document, Transaction
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

# Import RevitAPI
#clr.AddReference('RevitAPI')
#import Autodesk
#IF I DECLARE THIS LINE THE 'Point.ByCoordinates' DOESN'T WORK
#from Autodesk.Revit.DB import *

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
mod = IN[0]
ext1 = IN[1]
rot = IN[2]
ep =  "%.0f" % IN[3]
ja = IN[4]
jh = IN[5]
jv = IN[6]
res = []

#Iniciar transação para inserção dos blocos
TransactionManager.Instance.EnsureInTransaction(doc)

#Redefinir ponto de inserção do primeiro bloco
p1 = Point.ByCoordinates(ext1.X, ext1.Y, ext1.Z + ja)
for item in mod:
modBloco = item[0]
numBlocos = item[1]
if modBloco == 39.0:
tipoBloco = "Bloco Inteiro de Vedação de Concreto " + ep + " cm"
elif modBloco == 19.0:
tipoBloco = "Meio Bloco de Vedação de Concreto " + ep + " cm"
elif modBloco == 9.0:
tipoBloco = "Bloco Compensador de 1/4 de Concreto " + ep + " cm"
elif modBloco == 4.0:
tipoBloco = "Bloco Compensador de 1/8 de Concreto " + ep + " cm"
contador = 1
while contador <= numBlocos:
cs = CoordinateSystem.ByOrigin(p1)
p1 = Point.ByCylindricalCoordinates(cs,rot,0.0,(modBloco+jv)/2.0)
nomeBloco = FamilyType.ByName(tipoBloco)
instBloco = FamilyInstance.ByPoint(nomeBloco,p1)

#THIS COMMAND ROTATES THE FAMILY INSTANCE, BUT NOT ARROUND OF INSERTION POINT
instBloco = instBloco.SetRotation(rot)

res.append(instBloco)
cs = CoordinateSystem.ByOrigin(p1)
p1 = Point.ByCylindricalCoordinates(cs,rot,0.0,(modBloco+jv)/2.0)
contador += 1
#Finalizar transação para inserção dos blocos
TransactionManager.Instance.TransactionTaskDone()

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

- - -
Any suggestions?

Thanks!
Prof. Ari Monteiro


Cyril Waechter

unread,
May 10, 2016, 10:20:30 AM5/10/16
to RevitPythonShell
Hello Prof Ari Monteiro,

I suggest you to take a look at this article on my blog : [Revit] Rotation de famille sur l’axe X. I use ElementTransformUtils.RotateElement(), not FamilyInstance.SetRotation. It worked for me, tell me if you encounter any issue. This article is actually in french but you can use translator on the side bar (or ask me for translation if needed).

Cheers,
Cyril Waechter
Reply all
Reply to author
Forward
0 new messages