[Python] How to control text attributes with Python

Hello Community,

I am totally new to Python but intrigued and determined to learn. I acknowledge this request for advice/help is an advanced question for a beginner but any advice on where i could focus my learning would be helpful.

Firstly, I am not sure if this is possible in Python so i guess that is the first question. Ideally all the outputs/results would be displayed in grasshopper/rhino.

My 1st goal is to be able to import a list of names from a document such as .csv, .doc or .txt for example, and have control over their attributes when outputted such as font type, start position, spacing and wraping.

The intent is to be able to test to see how a list of names fit within a defined space and then evaluate the space needed to accomodate the entire list when the aobve attributes are modified.

This is a visual representation of the end result (manually created). An arbitrary number of names would be 500.

I started the process by creating the grid in rhino/grasshopper, from there I would like to ask for advice on the following (not in any particular order). See Img_B below:

A. output the list in a font of my choosing

  1. output the text height of my choosing
  2. control the distance between each name of my choosing
  3. create margins so the list of names falls into a predetermined (of my choosing) length. if the text falls outside the margins, it adds the next name to a new line
  4. the ability to define the line height for subsequent lines of names
  5. the ability to control the start point of the text - the goal here is to ensure the text is vertically center justified within in a specific size.

Is this possible inside of Python and where would be a good place to focus my research. I am starting a foundation course for python but thought i would reach out for some specific guidance for a specific problem to which i thought scripting would benefit.

Thank you in advance for any input.

name grid.gh (11.0 KB)

Yes certainly Python is very capable of handling the kind of logic you describe for 500 names. If you are using Rhino v6 then you have access to the csv module to handle csv files. If not then you can easily read from a text file with open() in v5.
You will probably need to go beyond the basic functionality of rhinoscriptsyntax to use Rhinocommon to achieve all you describe there. Alternatively I think I have seen some grasshopper definitions on this forum to achieve similar things.
Happy pythoning!

The textobject methods in rhinoscriptsyntax should get you going.
You may also need to create a bounding box around your text object to get its dimensions.
Look into iterating over text files and lists to get started.

This may help…