Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently using an addon to serve the value of a .txt file to two different text objects, which works great. I want to force all characters to capital though, and am unsure about how I would do that given the current data flow. I am open to using a completely different addon/script to do this, sadly google didn't turn up any results.

share|improve this question
1  
Actually I am using the typewriter add-on as a workaround – NᴏᴠɪᴄᴇIɴDɪsɢᴜɪsᴇ Mar 17 at 18:37
up vote 2 down vote accepted

In your script after you have created your text object and are in edit mode for it just run these two commands.

bpy.ops.font.select_all()
bpy.ops.font.case_set(case='UPPER')

That will convert all the characters in that text object to upper case, but leave it all selected.

If you want to have your text unselected (still in edit mode) run this command after the two above

bpy.ops.font.move(type='LINE_END')

Documentation on the font operators.


Here is an example script that uses the operators above to get a string from an external text file, convert it to all upper case, and make a new text object in.

import bpy
data = ""
with open('path/to/file.txt', 'r') as file:
    rawtext = file.read()
f.closed

bpy.ops.object.text_add(view_align=False, enter_editmode=True, location=(0.0, 0.0, 0.0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.font.delete(type='ALL')
bpy.ops.font.text_insert(text = rawtext, accent = False)
bpy.ops.font.select_all()
bpy.ops.font.case_set(case='UPPER')

bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

This script gets a string from an external text file, converts it to all upper case, and makes a new text object in blender; same as the script above, however this one does not use ops which will have better performance.

import bpy

#get letters from file
file = open('path/to/file.txt')
rawtext = file.read()
file.close()

#create new text curve and object
curve = bpy.data.curves.new("curve", 'FONT')
text = bpy.data.objects.new("text", curve)

#add uppercase letters to text curve
curve.body = rawtext.upper()

#add text object to scene
bpy.context.scene.objects.link(text)
share|improve this answer

enter image description here

The python string function upper and lower can help you.

enter image description here

Title function above.

share|improve this answer

No, I don't think there currently is a way to do that, at least without some coding involved, as far as I know.

Closest thing you can do is either use the option "Small Caps" and set it's size to 1, that will make non capital letters look like capital ones though the inserted text is still non caps, or you could find and all-caps font.

share|improve this answer
    
Some reason this doesn't work because of the font I am using – NᴏᴠɪᴄᴇIɴDɪsɢᴜɪsᴇ Mar 17 at 15:53
    
Workflow of Small Caps option is a bit convoluted, I've had a hard time using it before, believe you have to set the size to 1, enable the Small Caps option and then start typing – Duarte Farrajota Ramos Mar 17 at 15:55
    
The content of my text object is entered via a script, which gets the data from a .txt file – NᴏᴠɪᴄᴇIɴDɪsɢᴜɪsᴇ Mar 17 at 15:57
    
Oh sorry I misread, missed that part. Only other thing I can think of is using an external editor with case conversion functionality to make characters into capitals, though that might not be practical depending on where your text is coming from. Is it somehow auto generated or data extracted by a script from somewhere? Notepad++, SublimeText, Atom, or any other programmer's text editor are be able to do case conversion. – Duarte Farrajota Ramos Mar 17 at 16:06
1  
Alright, I will have to see what I can do. Thanks for trying to help :) – NᴏᴠɪᴄᴇIɴDɪsɢᴜɪsᴇ Mar 17 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.