On Friday, February 17, 2017 at 1:45:34 AM UTC-8, [email protected] wrote:
> i just want to use getpoints to get the points from both meshes. Then from my 
> selection of verts on one mesh, copy those points into the other points list 
> of the other mesh.
> 
> Then when i set points i will effectively have set the points on the second 
> mesh in the shape of the selected points from the first mesh
> 
> thanks, 
> Sam

there's really no need to get the points on both meshes, and depending on 
vertex counts, you may wanna avoid getting all the vertices opposed to just the 
ones you have selected.

It would be strange to loop over the full set of points on the target mesh, 
updating just the indices of the selected vertices on the src mesh, then 
setting ALL the points on the tgt. you can do it, but its strange imo.

But anyways, The code below doesn't store any vertices/MPoints.  It simply 
loops over the indices of the vertices you have selected on the src mesh, and 
sets the point on the tgt mesh with the equivalent point on the src mesh in 
local space. 

import maya.api.OpenMaya as om2

# get MSelectionList of actively selected objects in the viewport
sel = om2.MGlobal.getActiveSelectionList()

# the first item is the src, along with its selected vertices
src, components = sel.getComponent(0)

# the second selected item is the target
tgt = sel.getDagPath(1)

# create function sets
fnMeshSrc = om2.MFnMesh(src)
fnMeshTgt = om2.MFnMesh(tgt)
fnSingle = om2.MFnSingleIndexedComponent(components)

indices = fnSingle.getElements()
for index in indices:
    fnMeshTgt.setPoint(index, fnMeshSrc.getPoint(index, om2.MSpace.kObject), 
om2.MSpace.kObject)


It may be better to get the entire point array of the src mesh, and index into 
that instead of calling 'getPoint()' inside the loop. It depends on object 
vertex counts, and how many vertices you have selected. you'll have to test it.

srcPnts = fnMeshSrc.getPoints(om2.MSpace.kObject)
indices = fnSingle.getElements()
for index in indices:
    fnMeshTgt.setPoint(index, srcPnts[index], om2.MSpace.kObject)


goodluck!

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/7cc678d5-ee1b-4346-b288-018d5c02960f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to