0
$\begingroup$

I have got this far with generating text objects (this code is embedded in a loop in which the value of c is being set to different strings and i is incrementing as you might expect)...

    bpy.ops.object.text_add(location=(i*1.05, 0, 3.0), rotation=(0, 0, 0))
    tx=bpy.context.object
    tx.name = 'Letter_{}'.format(c)
    tx.data.body = c
    tx.data.font = fnt
    tx.location=(i*1.05, 0.0, 1.0)

so far so good, but now I would like to deepen or extrude this text object preparatory to meshifying it and trying to incise it into a cube face using a boolean operator; I have seen examples of this extrusion but they seem to be using a completely different api -- such as this snippet:

localTextObject = Text3d.New(myTextName) #Create a text object.
localTextObject.setText(myTextValue) #Set the copy for the text.
localTextObject.setExtrudeDepth(0.01) #Give it some depth

So: my question is... given the api I'm using, can I set the Extrude Depth for my text object, and if so, what's the syntax? and how, more generally, can I discover all the options that can be set in tx.data for example? I have been googling for weary minutes and have not yet found the right reference, manpage or whatever that would show all the settable options. Is the api introspective enough that I can dig into it from the python console? if so, syntax please...

UPDATE: at last I found the right keywords to retrieve this answer Documentation for accessable object properties

I am happy now :-)

$\endgroup$
0
$\begingroup$

Text objects are Curves with the subclass TextCurve. To create a text object(without using bpy.ops):

font = bpy.data.curves.new('myFont', 'FONT') #this is the 'data' of the text.data in your code
text = bpy.data.objects.new('myText', font)
bpy.context.scene.objects.link(text)
bpy.context.scene.update() #in your case do this outside the loop

To set the extrude:

font.extrude = 0.1
$\endgroup$
  • $\begingroup$ Thanks cmomoney. I have read here and there that avoiding bpy.ops is a Good Thing because it does auto scene updating after each op. Just out of curiosity, is there an object count threshold at which one really does not want to use bpy.ops? Like "more than 20" or "more than 1000" in scene? $\endgroup$ – Tazling Jan 4 '17 at 19:35
  • $\begingroup$ I don't know of any threshold. I would say more than one is too many, but that's just me. If there is a low level way to do what you're trying to do, do that and avoid bpy.ops if you can. Plus low level functions give you more control imo. Although, sometimes bpy.ops is the only(or more practical) way. $\endgroup$ – cmomoney Jan 4 '17 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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