Placing electrical sockets near door in correct orientation

Hi all
I am trying to develop a script to place sockets near the door from linked file.Socket family I am using is non hosted and families are getting placed in wrong orientation in many areas,How can I control the orientation of family with respect to corresponding wall so that I get the desired orientation as shown in second image.

desired orientation is as shown below.

As an initial step I found the angle between vector of the wall orientation and facing orientation of the family as shown below.

Here is the dynamo script.
Socket placement forum.dyn (79.8 KB)

here is the revit file (2020)

Hi there,

I guess you need to rotate the family after the Vector.AngleAboutAxis node

BTW, we don’t have you’re revit links :wink:


As it’s Non-Hosted Family it will depend on how the family is built (family orientation), then the orientation of the wall alone will not help you, you need the Normal vector of the face.

An example with a Non-Hosted Family oriented along the Y axis

lstFaces = wall.Faces;
// draw curves for Visualization
lstcurve = wall.Faces.Edges.CurveGeometry;
// draw a small sphere to find intersection with faces (50 is mm here)
socketsphere = Sphere.ByCenterPointRadius(elem.Location, 50);
mask = lstFaces.DoesIntersect(socketsphere);
outdict = DSCore.List.FilterByBoolMask(lstFaces, mask);
//get normal wall face
surface = outdict.ValueAtKey("in");
normal_Wallface = surface[0].NormalAtParameter(0.5, 0.5);
// Base Family Orientation (family construction)
familyOrientation = Autodesk.DesignScript.Geometry.Vector.YAxis();
// get angle
angle = normal_Wallface.AngleWithVector(familyOrientation);
// fix angle
clockwise = normal_Wallface.Cross(familyOrientation).Normalized().Z;
angleR = clockwise < 0 ? angle * clockwise : angle;
// set element Rotation