FamilyInstance.SetRotation into Python Script

I’m trying to use FamilyInstance.SetRotation within a Python script, but the objects are being rotated using arround, I believe, the project origin.

I would like to rotate the family instance around it 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:
dynamobim.org/forums/topic/rotating-family-instances/

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 bold comments:

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