Revit link placement and rotation

Hello, I am trying to place a Revit link in the origin point of a selected family, but I can’t find the error.
image
I would really appreciate it if you can help me, the script below just inserts the Revit link but it doesn’t move o rotate.

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

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

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

import math
from math import radians

# The inputs to this node will be stored as a list in the IN variables.
Path = IN[0] 
FamilyDyn = IN[1]
FamilyRvt = UnwrapElement(IN[1])

#Finding rotation axis
Pt1 = FamilyRvt.Location.Point
Pt2 = XYZ(Pt1.X, Pt1.Y, 10)
Line = Line.CreateBound(Pt1, Pt2) 

#Finding rotation angle
FamAngle = FamilyDyn.FacingOrientation
DefaultModuleAnlge = Vector.XAxis()
RotatAngle = Vector.AngleWithVector(FamAngle, DefaultModuleAnlge)

Doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(Doc)

#Insertion of Rvt Family
LinkPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(Path)
LinkOpt = RevitLinkOptions(' ')
RvtLink = RevitLinkType.Create(Doc, LinkPath, LinkOpt)
RvtLinkInstance = RevitLinkInstance.Create(Doc, RvtLink.ElementId)
Link = RvtLinkInstance.ToDSType(False)

#Family Location
Link.Location.Point = Pt1
#ElementTransformUtils.MoveElement(Doc, Link.Id, Pt1)

#Family Rotation 
ElementTransformUtils.RotateElement(Doc, Link.Id, Line, radians(RotatAngle)) 

TransactionManager.Instance.TransactionTaskDone()

# Assign your output to the OUT variable.
OUT = Link.Location

Hi,
try to remove the conversion

Replace

RvtLinkInstance = RevitLinkInstance.Create(Doc, RvtLink.ElementId)
Link = RvtLinkInstance.ToDSType(False)

by

Link = RevitLinkInstance.Create(Doc, RvtLink.ElementId)

3 Likes