该代码似乎旨在选择多个文本元素,然后以特定的水平距离排列它们。
IList<Reference> selectedRefs = uiDoc.Selection.PickObjects(ObjectType.Element,"Select text instances");
if (selectedRefs.Count < 2)
{
TaskDialog.Show("Error", "Select at least two text instances.");
return Result.Cancelled;
}
// Calculate the desired equal horizontal distance between text instances
double desiredHorizontalDistance = 50.0; // Change this value as needed
using (Transaction tx = new Transaction(doc, "Move Text "))
{
tx.Start();
// Sort selected text instances by their X-coordinates
List<Element> selectedTextInstances = new List<Element>();
foreach (Reference reference in selectedRefs)
{
Element textElement = doc.GetElement(reference);
selectedTextInstances.Add(textElement);
}
selectedTextInstances.Sort((elem1, elem2) =>
{
XYZ point1 = (elem1.Location as LocationPoint).Point;
//XYZ point1 = elem1.Coord;
XYZ point2 = (elem2.Location as LocationPoint).Point;
return point1.X.CompareTo(point2.X);
});}
文本元素的
Location
属性可以由多个点组成,具体取决于文本对齐设置。因此,属性值不能用 LocationPoint
或 LocationCurve
来表示。因此,不幸的是,Revit API 不提供任何读取或写入此属性的可能性。