API vs Manual

API vs Manual

myrwen_juntereal6EWNX
Explorer Explorer
1,088 Views
5 Replies
Message 1 of 6

API vs Manual

myrwen_juntereal6EWNX
Explorer
Explorer

I have a floors that are created via API, for some reason i cannot get its boundary curves. The image on the left returns 0 curveloop while the image on the right (manually created) works fine. Please see below code and image for reference.

 

 

private static List<CurveLoop> GetFloorBoundaryLoops(Floor floor)
{
    List<CurveLoop> curveLoops = new List<CurveLoop>();
    Document doc = floor.Document;

    ElementId elementId = new ElementId(floor.Id.IntegerValue - 1);
    List<Curve> curves = new List<Curve>();
    CurveLoop curveLoop;
    
    if (doc.GetElement(elementId) is Sketch element)
    {
        int size = element.Profile.Size;
        for (int i = 0; i < size; i++)
        {
            CurveArray item = element.Profile.get_Item(i);
            if (item != null)
            {
                foreach (Curve curve in item)
                {
                    curves.Add(curve);
                }
            }
            curveLoop = new CurveLoop();
            for (int j = 0; j <= curves.Count - 1; j++)
            {
                curveLoop.Append(curves[j].Clone());
            }
            curves.Clear();
            curveLoops.Add(curveLoop);
        }
    }
 

    return curveLoops;
            

 

 Thanks 

myrwen_juntereal6EWNX_0-1717673047603.png

 

0 Likes
Accepted solutions (1)
1,089 Views
5 Replies
Replies (5)
Message 2 of 6

Moustafa_K
Advisor
Advisor

Well, it is unclear why you are expecting the right sketch element when you do this statement

ElementId elementId = new ElementId(floor.Id.IntegerValue - 1);

 

since Revit 2022 there is already an element ID for sketch as a member of the floor. so you can safely use it, then you can retrieve the profile as CurveArray... see more detail over here

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 3 of 6

Moustafa_K
Advisor
Advisor

just wanted to add... you can boil plate your code to just two lines

 

var floorSegments = sketch.Profile.Cast<CurveArray>().First().Cast<Curve>().ToList();
CurveLoop cloop = CurveLoop.Create(floorSegments);

 

just to note this will skip the holes if any inside your floor

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 4 of 6

myrwen_juntereal6EWNX
Explorer
Explorer

unfortunately, our current project is still in Revit 2021, cannot upgrade yet 

0 Likes
Message 5 of 6

Moustafa_K
Advisor
Advisor

oh.. ok, then a tricky way is to get it from the editor, however, ensure the shape of the floor is not modified, other wise you need to reset it first, then roll back the transaction

 

see this example

 

Trans.Start();
floor.SlabShapeEditor.ResetSlabShape();
Doc.Regenerate();

CurveLoop cloop = new CurveLoop();

foreach (SlabShapeCrease creaseedCurve in floor.SlabShapeEditor.SlabShapeCreases)
{
    cloop.Append(creaseedCurve.Curve);
}
Trans.RollBack();

 

 

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 6 of 6

TripleM-Dev.net
Advisor
Advisor
Accepted solution

Hi @myrwen_juntereal6EWNX,

 

I use a Extension to get the sketch of a Ceiling in Revit 2017 to 2024.

 

For Revit 2022 use the SketchId property

For before Revit 2022 use the GetDependentElements Method and as filter use:

 

ElementClassFilter filter = new ElementClassFilter(typeof(Sketch));

 

 

This should also work for floors.

 

- Michel

 

See image below of the posted document (updated to R2022, don't have R2021 installed), but as seen the Id of the sketch is identical between the 2 options:

(and it's Id is not 1 less then the Id of the floor itself, floor id: 2631, sketch 2622, maybe if created by UI by coincidence)

Revit_SketchId_with_GetDependentElements.png