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

Good morning. I couldn’t find that y-axis information. Where it is?
Thank you very much in advance

Go to the reference level view in your family. This shows the x and y axis lines.


I still don’t understand, because I didn’t find it. :worried:

Open a plan view of the family (in your case I believe it is named reference level). The +X axis is to the right of that view. The +Y is to the top of the monitor, and the + Z extends out of the monitor.

1 Like

Instead of trying to use Dynamo to constantly rotate this family, better to make the family face based or work plane based so you choose a surface of walls or whatever to place them. I don’t know if the family will cut the wall with voids though

1 Like

I don’t think I understand, see, it doesn’t show, would it be my family specifically?

Yes, you’re absolutely right. However, I’ve already taken this family as it is, and I’ve put in a lot of effort to create various routines with them. If I change now, I’ll have to redo several processes or even create numerous new families. I was thinking if there was a way to modify them directly, establish a link, but I couldn’t figure out how to do it.

Nothing shows - this just tells you which way is ‘up’ relative to the geometry. If you want the object ‘facing’ a particular way you need to rotate it relative to this position.

1 Like

Would I have to specify the angle and position for each family? I didn’t understand, and it didn’t work for me. Could you please help?

I think it’s best if you share your family so we can figure out why this isn’t working

1 Like

It worked, yes. I was doing the selection in reverse. Thank you very much for your help!