convert objects to mesh type in python script?

Is it possible to convert th curve, text… in a scene to the mesh by a python script?

no

but hopefully that will change in the future. Look for the (and if none are found add) requests on blender.org for mesh conversion for all object types (well, lamps, empties, et.cetera do not apply)

This is exactly what I need. So I’m asking if there is any solution to this problem after years have passed. I’ve been searching the API Dokumentation ( http://www.blender3d.org/documentation/242PythonDoc/API_intro-module.html) for hours now without success. But I can’t believe that there is no Python-equivalent to an Alt+C. I really need this one.

Thanks!

But you can get its data as a mesh, link this mesh to the scene and unlink the old object.
Use the NMesh.getRawFromObject .
http://www.zoo-logique.org/3D.Blender/scripts_python/API/242/

object= Blender.Object.Get(‘Curve’) curve 2D or text…
NMesh.getRawFromObject(object.getName())

etc.

Or you can use the equivalent in Mesh: getFromObject
http://www.zoo-logique.org/3D.Blender/scripts_python/API/242/Mesh.Mesh-class.html#getFromObject
(but it seems that currently Mesh has some problems with memory management )

Thank you for your reply.
But this is not exactly what I need. I’m trying to convert nurbs objects.
Neither raw vertices data nor a subdivision mesh will help me.

So, as to be workaround, how to simulate a key stroke, let me say an Alt+C, in a script? Or a klick on one of Blenders Buttons? I believe I red some time ago something about this done successfully here in the forum, but I cant find it any more.

getrawfromobject works with nurbs, metaball and text objects .

(a bit in french, sorrry)

I played a bit with NMesh.getRawFromObject but I only get the handling points of the Curve. And this is NOT what im looking for. I need the result of the nurbs curve process in the Endpoint U flavour. In my opinion NMesh.getRawFromObject can’t serve this.
Mesh.getFromObject is able to take subdivision into account, but this didn’t help me either.

If I’m wrong please give me a hint, how to manage it. In fact I need exactly something like an Alt+C.

Oyster, since you have not answered, Does this help you?

RedSharky, if you want people to help you its worth going into some detail about what you want to do.
what do you want to convert the nurbs object into?
You can access the points from the Curve module, Though if you wanted to access curve data from a text object the API would need to be extended.

Read up on the curves module, if it dosent do what you want I might be able to extend the API.
http://members.iinet.net.au/~cpbarton/ideasman/BPY_API/API_intro-module.html

Hey Cambo,
i really like your skripts (though I sometimes wish the documentation would be better ;)).

When I didn’t go into detail then only because I don’t want to bore anyone. And because I thought everything was clear.

As you can see on the pic I have a nurbs curve created by script and turned on Endpoint U. Then I want to convert it in this example (DefResol U = 3) to a mesh to get the smoothed result. Normally I would do it by pressing Alt+C. But in this case I would like to do it by script because I want to use it in a chain of automated conversions.

We all know that there is a kind of function in Blender that performs this conversion. I just thought it would be fine to have access to it by Python.

http://mitglied.lycos.de/redsharky/Misc/Curve-to-Mesh.gif

Hey RedShaky,
I like scripting a lot more then writing docs and it shows :wink: - Will have to change that for the script refactor.

As far as I can see its possible to do this with meshes getFromObject, you just need to change the default res and set EndpointU beforehand with the python API.

Thank you, cambo! It works.
And thank you to jms! I just was too blind to see.

For everyone who would like to see an example, here is it. :slight_smile:


import Blender 
from Blender import *

ob = Object.GetSelected()[0]    # get the first of all selected objects

ob_data = ob.getData()        # get object's linked data

ob_data.setResolu(3)        # set refining resolution, equivalent to DefResolU button

m = Mesh.New()            # create new mesh
m.getFromObject(ob.name,0)    # get data from another object

ob2 = Object.New('Mesh')      # create new mesh object with name 'Mesh'
ob2.link(m)            # link mesh to object

sc = Scene.getCurrent()      # get current scene
sc.link(ob2)            # link object ob2 to scene sc

Blender.Redraw()


Thanks! Just spent ages browsing through api and everywhere to see how to do this.

Hi All,

I’m expanding the particles to mesh script a bit or lets say i do my own
strand system. (for radium)

it seems python code changed again. It’s one year past now.
Blender 2.44 Python 2.5

Using the above

m = Mesh.New() # create new mesh
m.getFromObject(ob.name,0) # get data from another object

gives me an error
RuntimeError: cant convert curve to mesh. Does the curve have segments?

m = Blender.NMesh.GetRawFromObject(ob.name) seems to work
But NMesh is deprecated so we shouldn’t use it anymore.

here my code:

import Blender 
from Blender import *

ob = Object.GetSelected()[0]    # get the first of all selected objects

ob_data = ob.getData()        # get object's linked data

ob_data.setResolu(3)        # set refining resolution, equivalent to DefResolU button

m=Blender.NMesh.GetRawFromObject(ob.name)   # get data from another object
for f in m.faces: f.smooth = True                              # set smooth to True for each face

ob2 = Object.New('Mesh')      # create new mesh object with name 'Mesh'
ob2.link(m)            # link mesh to object

sc = Scene.getCurrent()      # get current scene
sc.link(ob2)            # link object ob2 to scene sc

Blender.Window.Redraw()

Oh by the way how to set a mesh smooth in python .?
EDIT founbd and added:
"
smooth is stored per face.
for f in me.faces: f.smooth = True
"

The Curve is a bezier curve with some Extrude and Bevel.
Alt-C works on it.

So what should we use now ?

Help is apprechiated. :wink:

cheers

u3dreal :wink:

would someone be so kind to translate this code into the latest blender version?

I have a text curve but cannot find a way of converting it into a mesh using python

bpy.data.curves.new(type="FONT", name='label').body = 'techA'
label = bpy.data.objects.new(name="label0", object_data=bpy.data.curves['label'])