Inconsistent Dimension Reference in Revit API - Sometimes Shows FamilySymbol Instead of Instance

Inconsistent Dimension Reference in Revit API - Sometimes Shows FamilySymbol Instead of Instance

mohamedabdullah_btech
Explorer Explorer
289 Views
3 Replies
Message 1 of 4

Inconsistent Dimension Reference in Revit API - Sometimes Shows FamilySymbol Instead of Instance

mohamedabdullah_btech
Explorer
Explorer

Hello everyone,

I'm facing an issue with a Revit API script I've written to automate the dimensioning of foundation and column instances visible in the current view. The script generates the dimensions and retrieves their IDs, but the dimensions are sometimes not visible in the view. When I inspect the referenced element ID of the dimensions, it occasionally shows the reference type as FamilySymbol instead of the instance of the foundation or column.

Dimension_Reference_Issue.pngAlgorithm I followed:

  1. Retrieve Visible Elements: I get all visible foundation and column instances from the current view.
  2. Get Vertical Faces: For each element, I retrieve the vertical faces and group two opposite faces.
  3. Create References: I gather references from these faces and add them to a ReferenceArray.
  4. Create Dimensions: I create the dimensions using this ReferenceArray.

The issue is inconsistent. Sometimes the dimensions work as expected, with correct references to the instances, and other times they don't, with the references incorrectly pointing to the FamilySymbol.

I suspect this may be due to how I am capturing or applying the face references, but I haven't pinpointed the exact cause.

Has anyone encountered similar behavior or have suggestions on how to resolve this inconsistency?

Thanks in advance for your help!

0 Likes
290 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni

> I suspect this may be due to how I am capturing or applying the face references

  

This begs the question: how exactly are you capturing them?

  

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

mohamedabdullah_btech
Explorer
Explorer

This is how exactly, I am capturing the references from the structural Foundation:

using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;

namespace sample
{
    [Transaction(TransactionMode.Manual)]
    public class Strutural_Foundation : IExternalCommand
    {

        private Solid GetSolidFromGeometry(GeometryElement geoElement)
        {
            foreach (var geoObj in geoElement)
            {
                if (geoObj is GeometryInstance geoInstance)
                {
                    GeometryElement instanceGeometry = geoInstance.GetInstanceGeometry();
                    Solid solid = GetSolidFromGeometry(instanceGeometry);
                    if (solid != null)
                    {
                        return solid;
                    }
                }
                else if (geoObj is Solid solid && solid.Volume > 0)
                {
                    return solid;
                }
            }
            return null;
        }


        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            try
            {

                using (Transaction tx = new Transaction(doc, "Foundation Dimensions"))
                {
                    tx.Start();

                    IList<Reference> selectedReferences = uidoc.Selection.PickObjects(ObjectType.Element, "Select structural foundations");
                    List<Element> selectedElements = new List<Element>();

                    foreach (Reference reference in selectedReferences)
                    {
                        Element element = doc.GetElement(reference);
                        selectedElements.Add(element);
                    }

                    List<FamilyInstance> rectangularFoundations = new List<FamilyInstance>();
                    List<Reference> faceReferences = new List<Reference>();

                    foreach (FamilyInstance foundationElement in selectedElements)
                    {
                        var verticalFaces = new List<PlanarFace>();

                        if (foundationElement != null)
                        {
                            Options geoOptions = new Options { ComputeReferences = true, IncludeNonVisibleObjects = true };
                            GeometryElement geoElement = foundationElement.get_Geometry(geoOptions);

                            if (geoElement != null)
                            {
                                Solid solid = GetSolidFromGeometry(geoElement);

                                if (solid != null)
                                {
                                    foreach (Face face in solid.Faces)
                                    {
                                        if (face is PlanarFace planarFace)
                                        {
                                            XYZ normal = planarFace.FaceNormal;

                                            if (Math.Abs(normal.Z) < 0.01)
                                            {
                                                verticalFaces.Add(planarFace);

                                                Reference faceRef = planarFace.Reference;
                                                faceReferences.Add(faceRef);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (verticalFaces.Count > 3)
                        {
                            rectangularFoundations.Add(foundationElement);
                        }
                    }

                    tx.Commit();
                }

                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }
}
0 Likes
Message 4 of 4

mohamedabdullah_btech
Explorer
Explorer

@jeremy_tammik 
Just following up the above issue. I found something interesting. Ifthe Structural columns have been joined, the dimensions were created perfectly. And this is also true even if we separate them afterwards. But if we create a new instance of the same structural column the dimension doesn't work. 

I've attached the image for the reference below FYR. Please look into it and provide your insights. 

 

Note: I've checked the building coder post regarding symbol and instance geometry. but it looks like everything is right according to your suggestions.

Screenshot 2024-10-30 151805.png

0 Likes