How to get the same Face.Origin value as displayed in the Revit Lookup

How to get the same Face.Origin value as displayed in the Revit Lookup

jaymee.manglicmot
Contributor Contributor
568 Views
2 Replies
Message 1 of 3

How to get the same Face.Origin value as displayed in the Revit Lookup

jaymee.manglicmot
Contributor
Contributor

We are developing a tool which aims to align electrical elements (e.g. lighting fixtures) to the edge of the ceiling grid. I cannot make it work for rectangular elements, I was hoping to get the origin x and y values of the solid faces so I can calculate the correct length of the element, but the API is returning different values for the Origin. (Did not use the bounding box of the element because it includes other details of the element). I have tried different transforms also but no success yet. I would like to use the same value from the Face.Origin being returned by the Revit Lookup. Thank you.

jaymeemanglicmot_0-1625761895433.png

 

jaymeemanglicmot_2-1625762010973.png

My code is as follows:

Options gOptions = new Options();
gOptions.ComputeReferences = true;
gOptions.DetailLevel = ViewDetailLevel.Undefined;
gOptions.IncludeNonVisibleObjects = false;

GeometryElement geomElem = e.get_Geometry(gOptions);
GeometryObject geoObj = geomElem.FirstOrDefault();
GeometryInstance geomInst = geoObj as GeometryInstance;

 

if (geomInst != null)
{
GeometryElement gInstGeom = geomInst.GetInstanceGeometry();

foreach (GeometryObject gGeomObject in gInstGeom.Where(x => x is Solid))
{


Solid geoSolid = gGeomObject as Solid;

if(geoSolid.Volume > 0 && geoSolid.Visibility == Visibility.Visible && geoSolid.Faces.Size > 0)
{

foreach (Face f in geoSolid.Faces)
{
if (f is PlanarFace)
{
PlanarFace pf = f as PlanarFace;

XYZ origin = pf.Origin;

0 Likes
Accepted solutions (1)
569 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

RevitLookup is written entirely using the Revit API, the same methods that you are using as well.

 

So,  the good news is that you can retrieve the exact same values as you see in RevitLookup.

 

If they give you what you need, just debug RevitLookup and follow the same sequence of Revit API calls to retrieve the same values in your add-in as well.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

jaymee.manglicmot
Contributor
Contributor
Thanks Jeremy for the quick response, my fault/mistake is where/which part of the code I am calling the get_geometry method. Apparently, why I'm getting a different value for origin is could be a document regeneration or transaction issue. So I just tried the same methods in the same view as where the revit lookup is used, before doing anything, and I got the same results.
0 Likes