Help porting code from 2.49a to 2.62

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

adelie
Posts: 1
Joined: Thu May 31, 2012 8:46 pm
Location: NY, NY

Help porting code from 2.49a to 2.62

Postby adelie » Thu May 31, 2012 9:04 pm

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: Select all

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: Select all

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

dom107
Posts: 35
Joined: Wed Apr 18, 2012 10:04 am

World coordinates

Postby dom107 » Mon Jun 04, 2012 11:13 am

Hello,

I'm a very recent Blender script learner... :D

From my knowledge:

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

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

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Mon Jun 04, 2012 11:57 pm

you better port it to 2.63 (bmesh) if you plan to update Blender periodically...

with modifiers applied:

Code: Select all

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...


Return to “Coding Blender”

Who is online

Users browsing this forum: No registered users and 0 guests