Hello Dynamo Friends
I have a script to place these lighting families:
The script also attempts to rotate this family by 3 axis, but in revit this is not possible at all.
I have to go the workaround to nest the family in an adaptive family.
So I changed the graph to work with adaptive families:
This works by building a source and target coordinatesystem for every instance.
As I now had no “FamilyInstance.Transform” node to convert from one CS to another, I had to build this node myself, and that’s where the trouble starts. I´m doing something wrong at transforming because the families get moved far away from their origin.
# Get inverse transform of the source coordinate system
sourceTransform = Transform.Identity
sourceTransform.Origin = sourceCS.Origin.ToXyz()
sourceTransform.BasisX = sourceCS.XAxis.Normalized().ToXyz()
sourceTransform.BasisY = sourceCS.YAxis.Normalized().ToXyz()
sourceTransform.BasisZ = sourceCS.ZAxis.Normalized().ToXyz()
sourceTransformInverse = sourceTransform.Inverse
# Get transform of the target coordinate system
targetTransform = Transform.Identity
targetTransform.Origin = targetCS.Origin.ToXyz()
targetTransform.BasisX = targetCS.XAxis.Normalized().ToXyz()
targetTransform.BasisY = targetCS.YAxis.Normalized().ToXyz()
targetTransform.BasisZ = targetCS.ZAxis.Normalized().ToXyz()
# Compute the transformation from source to target
transform = sourceTransformInverse.Multiply(targetTransform)
The placing works fine it is just my transforming in the end that’s messing everything up. I´m out of ideas and hope for someone to go to the rescue! Files and full code attached, happy about any advice!
Place_Adaptive_on_Line.rvt (6.9 MB)
FamilyAtPointOnPolycurveTransformAdaptive.dyn (52.4 KB)
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import System
from System import Array
from System.Collections.Generic import *
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.UI import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = uiapp.ActiveUIDocument
def create_transform_from_coordinate_systems(sourceCS, targetCS):
# Get inverse transform of the source coordinate system
sourceTransform = Transform.Identity
sourceTransform.Origin = sourceCS.Origin.ToXyz()
sourceTransform.BasisX = sourceCS.XAxis.Normalized().ToXyz()
sourceTransform.BasisY = sourceCS.YAxis.Normalized().ToXyz()
sourceTransform.BasisZ = sourceCS.ZAxis.Normalized().ToXyz()
sourceTransformInverse = sourceTransform.Inverse
# Get transform of the target coordinate system
targetTransform = Transform.Identity
targetTransform.Origin = targetCS.Origin.ToXyz()
targetTransform.BasisX = targetCS.XAxis.Normalized().ToXyz()
targetTransform.BasisY = targetCS.YAxis.Normalized().ToXyz()
targetTransform.BasisZ = targetCS.ZAxis.Normalized().ToXyz()
# Compute the transformation from source to target
transform = sourceTransformInverse.Multiply(targetTransform)
return transform
def move_adaptive_component(famInst, trf, unHost):
try:
AdaptiveComponentInstanceUtils.MoveAdaptiveComponentInstance(famInst, trf, unHost)
except Exception as ex:
OUT = str(ex)
adaptive_components = UnwrapElement(IN[0])
sourceCSs = UnwrapElement(IN[1])
targetCSs = UnwrapElement(IN[2])
for component, sourceCS, targetCS in zip(adaptive_components, sourceCSs, targetCSs):
transform = create_transform_from_coordinate_systems(sourceCS, targetCS)
move_adaptive_component(component, transform, True)
OUT = []