Skip to main content
1-Visitor
October 2, 2015
Solved

Finding the centre of text

  • October 2, 2015
  • 1 reply
  • 1114 views

Is there a way of selecting text on an illustration and finding the centre of the text in a macro?

I can only find what seems to be the lower left load point (.text.startpoint), but I want to mirror text about it's centre.

Best answer by thendricks

Haven't done this on a single element, my method was for the contents of a page, but you should be able to make use of some of it. Below is a snippet from that code. The main idea is that you have to apply object_info in order to get points of an object. With the snippet below you'll get all four points, you can then use basic math to determine center.

     Define Final_Top as Float

     Define Final_Bottom as Float

     Define Final_Right as Float

     Define Final_Left as Float

     Create object_info ActiveDoc.firstSelectedElement

     ActiveDoc.firstSelectedElement.info.view_context.type = "extent"

     Compare_Left = ActiveDoc.firstSelectedElement.info.view_context.rectangle.left

     Compare_Right = ActiveDoc.firstSelectedElement.info.view_context.rectangle.right

     Compare_Top = ActiveDoc.firstSelectedElement.info.view_context.rectangle.top

     Compare_Bottom = ActiveDoc.firstSelectedElement.info.view_context.rectangle.bottom

1 reply

12-Amethyst
October 2, 2015

Haven't done this on a single element, my method was for the contents of a page, but you should be able to make use of some of it. Below is a snippet from that code. The main idea is that you have to apply object_info in order to get points of an object. With the snippet below you'll get all four points, you can then use basic math to determine center.

     Define Final_Top as Float

     Define Final_Bottom as Float

     Define Final_Right as Float

     Define Final_Left as Float

     Create object_info ActiveDoc.firstSelectedElement

     ActiveDoc.firstSelectedElement.info.view_context.type = "extent"

     Compare_Left = ActiveDoc.firstSelectedElement.info.view_context.rectangle.left

     Compare_Right = ActiveDoc.firstSelectedElement.info.view_context.rectangle.right

     Compare_Top = ActiveDoc.firstSelectedElement.info.view_context.rectangle.top

     Compare_Bottom = ActiveDoc.firstSelectedElement.info.view_context.rectangle.bottom

TimSharp1-VisitorAuthor
1-Visitor
October 2, 2015

Wow that was quick, thanks Trevor, I'll check it out early next week, looks promising.