The Revit API does not seem to have enabled certain aspects of either Location or LocationPoint with respect to TextElements. When using the code below, the result is the error "Object reference not set to an instance of an object". As noted with comments, it claims to get a Location, and also a LocationPoint, but there is nothing in the .Point.X (Y Z). Note also that I am picking an actual TextElement in the first line.
Reference One_Pick = uiDoc.Selection.PickObject(ObjectType.Element, "Select First Text");
Id1 = One_Pick.ElementId;
One_Pikt = uiDoc.Document.GetElement(One_Pick) as TextElement;
Location One_Location = One_Pikt.Location;//does not fail;
LocationPoint One_Pt = One_Location as LocationPoint;//does not fail;
Double XX = One_Pt.Point.X; Double YY = One_Pt.Point.Y; Double ZZ = One_Pt.Point.Z;//fails setting XX
我想要做的是按位置排序多个文本元素,或者移动文本,使其对齐点位于对象的中点或末尾。
Revit版本是2016
答案 0 :(得分:0)
TextBox
未实现Location
属性。 Location
属性可以提供单点数据或曲线数据。不幸的是,TextBox
位置由更复杂的内容表示,例如多个点,使用LocationCurve
或LocationPoint
无法表示。因此,文本元素没有返回任何内容。您可以查询文本边界框:
http://thebuildingcoder.typepad.com/blog/2014/10/new-text-note-and-text-width-calculation.html