0
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

What I am wanting to do is either sort multiple text elements by location, or else MOVE a text so it's justification point is at the midpoint or end of an object.

Revit version is 2016

1 Answers1

0

Yes indeed. The TextBox does not implement the Location property. The Location property can provide either single point or a curve data. Unfortunately, the TextBox location is represented by something more complex, e.g., multiple points, which is not representable using LocationCurve or LocationPoint. Therefore, nothing at all is returned for text elements. You can query the text bounding box instead:

http://thebuildingcoder.typepad.com/blog/2014/10/new-text-note-and-text-width-calculation.html

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • I find it cryptic that you have to provide a point value when creating the TextElement in the first place, but there is no direct way to access that point value in a text already in your model. – KeachyPeenReturns Jun 06 '17 at 18:40
  • Plus if I have to use a bounding box, I also have to include a bunch of code determining which of the 9 possible points represents my actual justification point. Convoluted at best. – KeachyPeenReturns Jun 06 '17 at 18:57