I would retrieve the extrusion geometry, find the underlying Solid and align its faces with the reference planes.
Options opt = new Options();
opt.ComputeReferences = true;
GeometryElement ge = solidExtrusion.get_Geometry(opt);
foreach (var e in ge)
{
if (e is Solid)
{
FaceArray fa = (e as Solid).Faces;
foreach (Face f in fa)
{
//Align the face with corresponding reference plane
}
}
}
Of course, this would not work for extrusions with more than one sketch loop, and it is not very easy to find the corresponding reference plane. (The same as your proposed method)
Using Revit Lookup, I did a little research about the top and bottom faces, or I should say start and end faces of the extrusion (if you have created the extrusion in a different view than top view). It seems that when you get the faces of the extrusion solid, the first two faces in the array are the start and end faces of the extrusion. Which means you can align the sketch lines the way you mentioned and then get the geometry, get the solid, get faces and align the first two with your bottom and top reference planes. (See snapshots)
I also tried to verify my finding using the stable representation of the faces. (See https://thebuildingcoder.typepad.com/blog/2016/04/stable-reference-string-magic-voodoo.html)
And it seems token4 in the stable representation of the start and end faces is always 0 and 1 respectively and the other faces are assigned random integers. (keep editing the extrusion and those integers change!)
Again, this was only an observation and I'd love to know how you end up implementing this process!
![Capture1.JPG Capture1.JPG]()
![Capture2.JPG Capture2.JPG]()
![Capture3.JPG Capture3.JPG]()