Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit 2023: Getting normal/origin of FamilyInstance StrongReference ReferencePlane/Face

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Jameshenager
79 Views, 1 Reply

Revit 2023: Getting normal/origin of FamilyInstance StrongReference ReferencePlane/Face

I'm trying to determine the origin and normal of a FamilyInstance which has a family with a plane with "Strong Reference". The purpose is to place another familyInstance in such a way that it lies along plane and another reference plane.

The loop runs as many times as there are strongReference planes.

 

My code is below:

 

    public void GetReferencePlanes(string selectedElementGuid)
    {
        var doc = uiApplication.ActiveUIDocument.Document;
        if (doc.GetElement(selectedElementGuid) is not FamilyInstance familyInstance) { return; }

        var instanceGeometry = familyInstance.get_Geometry(new Options() { ComputeReferences = true, });

        var references = familyInstance.GetReferences(FamilyInstanceReferenceType.StrongReference);
        foreach (var reference in references)
        {
            var f = doc.GetElement(reference).GetGeometryObjectFromReference(reference);

            if (doc.GetElement(reference.ElementId) is not { } referencedElement) { continue; }
            //get stable reference
            var stableReference = reference.ConvertToStableRepresentation(doc);
            var referencedElementType = referencedElement.GetType();
            var guid = referencedElement.UniqueId;
            var geometryObject = doc.GetElement(reference).GetGeometryObjectFromReference(reference);
            //var somePlanarGeometry = familyInstance.GetGeometryObjectFromReference(reference) as PlanarFace; //null
            var geometryType = geometryObject.GetType(); //always returns "Autodesk.Revit.DB.GeometryObject"

            switch (geometryObject) //none of these are ever hit
            {
                case Curve curve: Debugger.Break(); break;
                case Edge edge: Debugger.Break(); break;
                case Face face: Debugger.Break(); break;
                case GeometryElement geometryElement: Debugger.Break(); break;
                case GeometryInstance geometryInstance: Debugger.Break(); break;
                case Mesh mesh: Debugger.Break(); break;
                case Point point: Debugger.Break(); break;
                case PolyLine polyLine: Debugger.Break(); break;
                case Profile profile: Debugger.Break(); break;
                case Solid solid: Debugger.Break(); break;
                default: break;
            }
            Debugger.Break();
        }
    }

 

1 REPLY 1
Message 2 of 2
Jameshenager
in reply to: Jameshenager

Solution here:

    private static List<NamedPlane> GetReferencesPlanesByTypeCore(Document doc, string familyInstanceGuid)
    {
        if (doc.GetElement(familyInstanceGuid) is not FamilyInstance familyInstance) { return []; }

        var result = new List<NamedPlane>();
        var familyInstanceReferenceTypes = Enum.GetValues(typeof(FamilyInstanceReferenceType)).Cast<FamilyInstanceReferenceType>().ToArray();

        foreach (var familyInstanceReferenceType in familyInstanceReferenceTypes)
        {
            List<Reference> references = familyInstance.GetReferences(familyInstanceReferenceType).ToList();
            foreach (var reference in references)
            {
                var sketchPlane = SketchPlane.Create(doc, reference);
                var plane = sketchPlane.GetPlane();
                result.Add(new NamedPlane() { Name = familyInstance.GetReferenceName(reference), Origin = plane.Origin.ToPoint(), Normal = plane.Normal.ToPoint(), });
                sketchPlane.Dispose();
            }
        }
        return result;
    }

 

public class NamedPlane
{
    public string Name { get; set; } = null!;
    public Point Origin { get; set; } = null!;
    public Point Normal { get; set; } = null!;
}

public class Point
{
    public double X { get; set; }
    public double Y { get; set; }
    public double Z { get; set; }
}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community