Previous Thread  Next Thread

chat icon Help porting code from 2.49a to 2.62

adelie

Posted: Thu May 31, 2012 8:04 pm
Joined: 31 May 2012
Posts: 1
Hi,

I have a module that I wrote that converts mesh vertices into gcode, for CNC work. I'm having difficulty porting this to 2.62.


Code:
from Blender import Mesh, Scene
import BPyMesh
import numpy as np

scn = Scene.GetCurrent()
ob = scn.getActiveObject()
me = BPyMesh.getMeshFromObject(ob) # gets a mesh from the object with modifiers applied, also so transform wont effect the original mesh data.
me.transform(ob.matrixWorld) # transforms the mesh by the loc/size/rot of the object

coordinates = []
for v in me.verts:
    coordinates.append([v.co.z, v.co.y])





I've tried this but I need to get the global coords, not the local ones:

Code:
import bpy

myobj = bly.context.object.data
coordinates = []
for v in me.vertices:
    coordinates.append([v.co.z, v.co.y])




what is the equiv. to:
me = BPyMesh.getMeshFromObject(ob)
me.transform(ob.matrixWorld)

Thanks much.
-Dave
Reply with quote


dom107

Posted: Mon Jun 04, 2012 10:13 am
Joined: 18 Apr 2012
Posts: 35
Hello,

I'm a very recent Blender script learner... Very Happy

From my knowledge:

# World coordinates:
world_v = v.co * ob.matrix_world

as for the last question:
me.transform(ob.matrix_world)
Reply with quote


CoDEmanX

Posted: Mon Jun 04, 2012 10:57 pm
Joined: 05 Apr 2009
Posts: 894
you better port it to 2.63 (bmesh) if you plan to update Blender periodically...

with modifiers applied:
Code:
import bpy

ob = bpy.context.object
me = ob.to_mesh(bpy.context.scene, True, 'PREVIEW') # or 'RENDER'

me.transform(ob.matrix_world)

coordinates = []
for v in me.vertices:
    coordinates.append([v.co.z, v.co.y])
   
# to_mesh() creates a new mesh, should remove it if not needed afterwards
bpy.data.meshes.remove(me)

_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group