ModelText Rotation
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.
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 [might be a bug, @Jermy Tamik to confirm].
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 line code to get the angle. however, it worth mentioning, such procedure needs to be tested that would return the expected results in all cases. I couldn't find a supporting documentation for such workaround, but it WORKS :)
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;
}
Subscribe to my newsletter
Read articles from Moustafa Khalil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Moustafa Khalil
Moustafa Khalil
I'm Moustafa Khalil El-Sayed, an Egyptian native with a passion for architecture and technology. After completing high school in 1999, I embarked on my journey into architecture, earning my Bachelor's degree in Architecture in 2004. My academic pursuits continued, and I later acquired my Master's degree in Architecture from Wings University. However, my thirst for knowledge extended beyond architectural design, leading me to pursue a degree in Computer Science as well. Driven by a desire to innovate, I began self-teaching computer science, which later empowered me to achieve my Associate degree in Computer Science from the University of the People more easily. Armed with dual expertise in architecture and computer science, I've cultivated a unique skill set that blends creativity with technical acumen. My career has taken me across borders, from Egypt to Oman and the UAE, where I've honed my skills as an architect. As a graduate architect and a proficient .NET BIM Solution Developer, I specialize in translating unique visions into tangible realities. My role extends beyond conventional architectural practices; I leverage technology to streamline processes and enhance project outcomes. My journey into programming began with developing script-based Excel tools to augment project management efforts, notably during the Sharm El Sheikh development. Over time, I expanded my programming prowess to address practical challenges encountered in bridging Revit and AutoCAD within my professional sphere. Several of my applications, born from this evolution, have gained recognition, with some even being featured on the Autodesk website. I am committed to pushing boundaries and continually enriching the intersection of architecture and technology, ensuring that my clients benefit from cutting-edge solutions tailored to their needs.