object.getSize gives me [1,1,1]


I’m making an NMesh object in python like this:

txt = Text3d.New("MyText")

ob = Object.New('Text')

txtv = NMesh.GetRawFromObject(ob.name)
tob = Object.New('Mesh','MyObj')

[x,y,z] = tob.getSize()
print "Width: ", x, " Height: ", y    
tob.colbits = (1<<0)

The 3D text looks just fine, but tob.getSize always gives me x=1 and y=1 regardless of the real world size of the text object. What am I missing?

Thanks in advance for any help…

getSize() is actually returning you the object’s scale, not actual dimensions

Yes, that’s what I was afraid of. How can I get the actual dimensions of the object?

All I really want to do is center the text3d object at the origin, but its pivot point, by default, is at the lower left corner instead of at the object’s center, and I don’t know how to move it in python. Changing the object’s location with tob.setLocation(0,0,0) sets the pivot point at the origin, not the object’s center.

So I figured if I could calculate the object’s size, I could position it correctly.

use getBoundBox

Yes, I thought of that too, but the vertices I get from that are:

(0,0,0), (0,0,1), (1,0,1), etc…

After txt.setDrawMode(Text3d.DRAWFRONT)
try txt.setAlignment(Text3d.MIDDLE)

This will position it’s center at the bottom middle of the text.

That does center the text horizontally, but not vertically. The origin sits right below the text, not in the middle. If I use multi-line text “Hello
Everyone” then only the first line goes at the origin. Strange…

I know that in the GUI you can put the pivot point at the object’s center (Object menu -> Transform -> Center New), but the functionality is not there yet in python, that I am aware.

This feature will help when positioning the text by aligning from the top line down. (Top doesn’t get clipped)

Gotta go to work, possible solution:
Use getBoundBox (returns 8 xyz coordinated) after linking ob to scene.
the y coordinates should show only 2 different values: maxY minY.
Try this for positioning center.

Aha!! That did it! I had to call ob.getBoundBox AFTER linking the object to the scene. Calling getBoundBox on the “tob” object (an NMesh) didn’t work, but it did when called on the original Text3D object (“ob”) that the NMesh was constructed from.

Thanks a million!

Glad to return some help to the forum.