I am not entirely sure whether I'm using the MObjectHandle correctly, but I
added 'self.vertsHandle = om.MObjectHandle(vertices)' to the doIt()
function. Where 'vertices' is from the 'sel.getComponent(0)'. In the
undoIt() function, I put the condition of 'self.vertsHandle.isAlive()'. It
still manages to crash on undo. I added some print statements to figure out
where it starts bugging. So in the undoIt, I'm printing the vert ID, the
color at that ID (self.sourceCols[v]) as well as the mesh (Mem address). I
am only printing, and not doing the assignment with setVertexColor, so like
this:
def undoIt(self):
if self.vertsHandle.isAlive():
print(self.vertsHandle.isAlive())
for v in self.verts:
print("v is {}".format(v))
print("sourceCols is {}".format(self.sourceCols[v]))
print("Mesh is {}".format(self.mesh))
It manages to print correctly on all undos, so the references seem solid.
And isAlive() returns true on it all. That kind of just leaves the mesh
function setVertexColor I suppose? On Tech-artists.org Slack, Theodox
mentioned there might be an issue somewhere with assignment of vertexColors
and not faceVertexColors. My logic says if I use a getVertexColors, I have
an array of MColors for each vertex, which shouldn't upset anything with
faceVertexColors, but I've tried a bunch of things to get this working
without luck, so my logic is failing me.
On Tuesday, October 9, 2018 at 1:40:58 PM UTC+2, dur wrote:
>
> Hello,
>
> So I have been quite stuck on a problem in regards to Maya crashing when I
> undo.
> More specifically, it will crash on second, third or fourth undo. So the
> undo step *can* work.
>
> def doIt(self, args):
> self.parseArguments(args)
> sel = om.MGlobal.getActiveSelectionList()
> __, vertices = sel.getComponent(0)
> fn_vertices = om.MFnSingleIndexedComponent(vertices)
> self.verts = fn_vertices.getElements()
> self.path = sel.getDagPath(0)
> self.mesh = om.MFnMesh(self.path)
> self.colors = self.mesh.getVertexColors()
> self.sourceCols = self.mesh.getVertexColors()
> self.redoIt()
>
> def redoIt(self):
> for v in self.verts:
> self.colors[v].r = self.sourceCols[v].b
> self.mesh.setVertexColor(self.colors[v], v)
> def undoIt(self):
> for v in self.verts:
> self.mesh.setVertexColor(self.sourceCols[v], v)
>
> This is the code. What I'm trying to do, is swap channels on a per vertex
> basis.
> I only want it to act on selected vertices. I am explicitly copying the
> blue to the red channel for test purposes.
>
> I know that some MArrays get referenced rather than copied, but I tried to
> check the sourceCols pre- and post redoIt, and it's identical.
>
> My biggest hurdle here is that I don't really know what to look for? I'm
> really not certain what's happening behind the curtain, since to me it
> looks like pretty basic steps:
>
> 1. save original color
> 2. init redo and change colors and apply to mesh
> 3. apply original colors to mesh on undo
>
> It always manages to get through the initial undo, but seems quite random
> after that.
> I have been stuck on this thing for two days soon. Any help would really
> be appreciated!
>
--
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/3d1136ed-ec1e-47d1-8285-8442824fab3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.