How to get direction of model text in Revit api?

How to get direction of model text in Revit api?

hai_nn
Contributor Contributor
439 Views
4 Replies
Message 1 of 5

How to get direction of model text in Revit api?

hai_nn
Contributor
Contributor

Hi everybody,

How to get direction of model text(text 3D, not textnote) in Revit api?

Please see the image below to understand more about my question?

hai_nn_0-1714634583765.png

 

0 Likes
Accepted solutions (1)
440 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Th first thing to do, and one of the simplest, is to snoop the element using RevitLookup and other database explorations tools. That will show you what classes are used to represent it which properties they make available. In this case, you might discover the TextNote class and its BaseDirection property:

  

  

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

hai_nn
Contributor
Contributor

The case I want to mention is that the text model is not the text note.

0 Likes
Message 4 of 5

Moustafa_K
Collaborator
Collaborator
Accepted solution

Model text, in fact, is a bit tricky to determine its rotation value. I attempted to inspect its solids in the hope of finding any reference lines to grasp it, but I was unsuccessful. As I expanded my investigation to comprehend how model text functions, I discovered some hidden references. These references are visible on the user interface only when you attempt to align the model text or draw a line over it.

 

Moustafa_K_0-1714972898964.png

 

Which I couldn’t figure out how to identify these references. But wait, here comes the tricky part. When I attempted to obtain the geometry of this model text element, I got 2 solids. The first one has faces and edges, and the second one has zero faces and edges. I thought the second empty solid was indeed empty, but it turned out not to be. When I applied SolidUtil.SplitVolume to the empty solid, it produced 8 solids with actual volumes [ @jeremy_tammik , might be a bug? ].

 

Continuing with this account, the 8 returned solids are single-faced solids. These faces represent the references that I managed to select while hovering the mouse over. Through experimentation, I realized that the first solid returned always indicates the direction of the text.

 

Now the rest is just a couple of lines code to get the angle.

Moustafa_K_1-1714972922177.pngMoustafa_K_2-1714972926519.png

 

 

public IEnumerable<Solid> GetSolids(ModelText modelTextElement)
{
    var op = new Options()
    {
        IncludeNonVisibleObjects = true
    };

    var geomCollection = modelTextElement.get_Geometry(op);

    IEnumerable<Solid> solids = geomCollection.OfType<Solid>();
    return solids;
}

public double? GetModelTextDirection(ModelText modelTextObject)
{
    double? angleInDegree = null;
    if (modelTextObject != null)
    {
        var solids = GetSolids(modelTextObject);
        foreach (var solid in solids)
        {
            // we are keen to get the reference solids, hence ignore all above zero volume value
            if (solid.Volume > 0)
                continue;

            var directedSolid = SolidUtils.SplitVolumes(solid).First();
            var faces = directedSolid.Faces.Cast<Face>();

            PlanarFace directedFace = faces.First() as PlanarFace;
            var direction = directedFace.Normal();

            double toDegree = 180 / Math.PI;
            angleInDegree = Math.Round(XYZ.BasisX.AngleTo(direction) * toDegree, 2);
            break;
        }

    } 
    return angleInDegree;
}

 

 

 hope this helps

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

jeremy_tammik
Alumni
Alumni

Wow. Cool. Thank you for the brilliant in-depth research. This is certainly not a bug. You might call it a feature, and it is probably undocumented behaviour. So, as long as it works, it is a great approach. When making use of any such undocumented feature, however, you need to be very careful and implement a strong unit test to guarantee that it continues working in future releases and in other situations. Obviously,. all undocumented behaviour can change at any time.

  

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