Snagged from elsewhere and modified a bit already. Need to be able to get pitch and azimuth of a face relative to the root axes of the model. (Even if the face is inside a component that isn't aligned with the same axes.) I'll fix azimuth at some point (it's 90 degrees off, so a simple translation there) but pitch is always 90 degrees within a small error margin, regardless of how I orient the face being measured.
mod = Sketchup.active_model
ent = mod.active_entities
sel = mod.selection
sel.grep(Sketchup::Face).each{|fac|
rpt = fac.bounds.center;
nrm = fac.normal;
rax = nrm.axes[0]
tr = Geom::Transformation.rotation(rpt,rax,Math.asin(nrm.z))
nrm.transform! tr
if nrm.x < 0
azm = Math::PI - Math::asin(nrm.y) # Quadrant III or IV
elsif nrm.y < 0
azm = Math::PI * 2 + Math::asin(nrm.y) # Quadrant II
else
azm = Math::asin(nrm.y) # Quadrant I
end
deg = azm.radians;
deg=deg%360;
d=deg.floor;
m=((deg-d)*60).floor;s=(((deg-d)*3600)-m*60).round(2)
pitch=Math::acos(nrm.z);
pitchd=pitch.radians;
ent.add_text "Pitch=#{altd}\nAzimuth=#{d}#{176.chr} #{m}' #{s}\"",rpt,nrm
}