maxSript - undo on paint interface

Dear All,

I am working on a tool that involves the paint interface of 3D Studio Max. So far so good but I am stuck on an issue. I am not able to activate the undo functionality.
I tried to use the functions thePainterInterface.undoStart() in the startStroke and paintStroke functions of the script and the thePainterInterface.undoAccept() function in the EndStroke but the undo doesn’t work.
Can you please enlighten me on this obscure matter? I am surely missing something but I cannot see what.
Below you can see a tutorial copied from a book. It represents the structure of my script. Just in case it can help you to understand what I am doing.

Thanks to all of you in advance.

Cheers
ciccio_paco


function StartStroke = (
	thePainterInterface.undoStart() 
	)
function PaintStroke = (
	
	thePainterInterface.undoStart() 
	
	localHit = [0, 0, 0]
	localNormal = [0, 0, 0]
	worldHit = [0, 0, 0]
	worldNormal = [0, 0, 0]
	str = 0.0f
	radius = 0.0f
	
	thePainterInterface.getHitPointData &localHit &localNormal &worldHit &worldNormal &radius &str 0
	
	spike = instance selectedObjects[2]
	spike.pos = worldHit
	spike.dir = worldNormal
	
	print worldHit
		
	
	)
function EndStroke = (
	thePainterInterface.undoAccept() 
	)
function CancelStroke = ()
function SystemEnd = ()

selectedObjects = selection as array 	
	
print selectedObjects[1] -- PAINTED SURFACFE
print selectedObjects[2] -- PAINTED OBJECT
	
thePainterInterface.ScriptFunctions startStroke paintStroke endStroke cancelStroke systemEnd

	
thePainterInterface.initializeNodes 0 selectedObjects[1]

thePainterInterface.startPaintSession()

thePainterInterface.endPaintSession()



Dear All,

I saw many views on this post but no answer so far. This makes me think that perhaps there is someone else among us that had the same issue but wasn’t able to get around it.
I spent a lot of time trying to figure out the matter and, eventually, I ended up with a solution.
Basically, rather than typing the instructions to execute at the invocation of the paintStroke function I encapsulated them in a separate local function. Result… the painting interface is able to perform the undo properly.
Below there is the same example fixed as just depicted in those lines above. I hope that you will find it useful. I am testing this solution now on a more complex study case.
Two notes:
[ul]As you will notice I also put the undo function where they are supposed to be[/ul]
[ul]If you write the testSpikeLocal as global rather than local the undo works fin [/ul]

Cheers
ciccio_paco



-- LOCAL FUNCTION containing the instruction to execute during the stroking
fn testSpikeLocal obj pst nrm=(
	spike = instance obj
	spike.pos = pst
	spike.dir = nrm
)

function startStroke = (
	thePainterInterface.undoStart() 
	print "here is where the stroking STARTS"

)
function paintStroke = (
	print "I AM STROKING"
	--thePainterInterface.undoStart() 
	
	localHit = [0, 0, 0]
	localNormal = [0, 0, 0]
	worldHit = [0, 0, 0]
	worldNormal = [0, 0, 0]
	str = 0.0f
	radius = 0.0f
	
	thePainterInterface.getHitPointData &localHit &localNormal &worldHit &worldNormal &radius &str 0
	

	testSpikeLocal selectedObjects[2] worldHit worldNormal -- Invocation of the local function

	
	print worldHit
	
		
)
function endStroke = (
	print "stroke is OVER"
	thePainterInterface.undoAccept()
	--thePainterInterface.undoCancel() 
)
function cancelStroke = (
	print "what about CANCEL STROKE?!?"
	thePainterInterface.undoCancel() 
)
function systemEnd = (
	print "painting session ENDED"
	thePainterInterface.endPaintSession()
)

selectedObjects = selection as array 	
	
print selectedObjects[1] -- PAINTED SURFACFE
print selectedObjects[2] -- PAINTED OBJECT
	
thePainterInterface.ScriptFunctions startStroke pluto paintStroke cancelStroke systemEnd

	
thePainterInterface.initializeNodes 0 selectedObjects[1]
thePainterInterface.startPaintSession()

thePainterInterface.endPaintSession()