Why does Custom Attribute definition register an Undo record?

Why does Custom Attribute definition register an Undo record?

denisT.MaxDoctor
Advisor Advisor
1,447 Views
15 Replies
Message 1 of 16

Why does Custom Attribute definition register an Undo record?

denisT.MaxDoctor
Advisor
Advisor

run this snippet and see the undo list...

 

 

 

 

gc()

undo off
(
	attributes _attr attribid:#(0x0A0A0A, 0x000A)
	(
		parameters params 
		(
		)
	)
	ok
)

 

 

 

 

 

you will see one record - "Custom Attribute Redefinition". Why?! I said: "UNDO OFF!". It works for everything except "ca definitions". Any idea how to suspend this hold?
(theHold.Suspend() doesn't work, everything that I tried doesn't work...)

 

ps. do "max undo" after that is not a solution, clear the undo buffer is not a solution as well. 

 

pps. pps. of course, to get the "redefinition" you have to call it at least twice...

0 Likes
Accepted solutions (1)
1,448 Views
15 Replies
Replies (15)
Message 2 of 16

denisT.MaxDoctor
Advisor
Advisor

I can also ask - can we call it "redefinition", by the way? Same name, same identifier, same script...

But that's another story, I can get over it. 

0 Likes
Message 3 of 16

MehdiZangenehBar
Advocate
Advocate

This works for me:

theHold.DisableUndo()
(
	attributes _attr attribid:#(0x0A0A0A, 0x000A)
	(
		parameters params 
		(
		)
	)
	ok
)
theHold.enableUndo()


This is wierd that undo context dosn't work!

0 Likes
Message 4 of 16

denisT.MaxDoctor
Advisor
Advisor

let's try another one:

gc()

thehold.disableundo()
(
	attributes __cca attribid:#(0x21111, 0x72111)
	(
		parameters params 
		(
		)
	)
	attributes __caa attribid:#(0x51522, 0x5B222)
	(
		parameters params 
		(
		)
	)
)
theHold.enableUndo()

 

 

 

0 Likes
Message 5 of 16

MehdiZangenehBar
Advocate
Advocate

I'm not sure what is going on:

(
	gc()
	attributes __cca attribid:#(0x21111, 0x72111)
	(
	)
	attributes __caa attribid:#(0x51522, 0x5B222)
	(
	)
	theHold.getUndoNames()
)
0 Likes
Message 6 of 16

larryminton
Autodesk
Autodesk
Accepted solution

I'll log a defect on the creation of the undo record when redefining scripted CAs in this case, but it is complicated.

 

The 'with undo off' causes a context object that suspends the hold system to start to execute, then what is in the expression is executed, and then the hold system is resumed coming out. But that is all occurring during the execution of the script. 

 

The scripted CA definition is not a run time operation, rather it occurs in the parser thread as the script is being 'compiled'.  So execution is not occurring at this time.

 

Going to be tricky to handle as since not executing the script, code has no way to know what the undo state is.  This is perfectly valid:

xxx = true
with undo xxx do 
(
)

 

This is why you can't say something like the following, and expect executing the function to change the scripted CA definition.

fn def1 =
(
	attributes __cca attribid:#(0x21111, 0x72111)
	(
		parameters params 
		(
			hitPoints type:#float default:10
		)
	)
)
fn def2 =
(
	attributes __cca attribid:#(0x21111, 0x72111)
	(
		parameters params 
		(
			cost type:#float default:100
		)
	)
)

Larry Minton
Principal Engineer, M&E-Design Animation
0 Likes
Message 7 of 16

larryminton
Autodesk
Autodesk

note that this works, with expected undo records.

fn def1 =
(
	::XX = execute "attributes __cca attribid:#(0x21111, 0x72111)
	(
		parameters params 
		(
			hitPoints type:#float default:10
		)
	)"
)
fn def2 =
(
	with undo off ::XX = execute "attributes __cca attribid:#(0x21111, 0x72111)
	(
		parameters params 
		(
			cost type:#float default:100
		)
	)"
)
def1()
XX.source
def2()
XX.source

 


Larry Minton
Principal Engineer, M&E-Design Animation
0 Likes
Message 8 of 16

denisT.MaxDoctor
Advisor
Advisor

@larryminton wrote:

 

The 'with undo off' causes a context object that suspends the hold system to start to execute, then what is in the expression is executed, and then the hold system is resumed coming out. But that is all occurring during the execution of the script. 

 

The scripted CA definition is not a run time operation, rather it occurs in the parser thread as the script is being 'compiled'.  So execution is not occurring at this time.

this may explain the behaviour, but running this script we see that both Restore Objects and Hold record are added inside the code block, ignoring the fact that UNDO is suspended

 

 

 

undo off
(
	attributes _attr attribid:#(0x0A0A0A, 0x000A)
	(
		parameters params 
		(
		)
	)
	format "% % %\n" (thehold.IsSuspended()) (thehold.GetGlobalPutCount()) (thehold.getCurrentUndoLevels()) 
	ok
)

 

 

 

 

I can live with the fact that restore obejct can be put whithout UNDO available, but when the system does do it, I like to know what exacltly was regestered.

 

0 Likes
Message 9 of 16

denisT.MaxDoctor
Advisor
Advisor

It's not really a solution, and I don't think it needs to be solved at all, but explaining it suffices and makes sense to me:

"The 'with undo off' causes a context object that suspends the hold system to start to execute, then what is in the expression is executed, and then the hold system is resumed coming out."

0 Likes
Message 10 of 16

denisT.MaxDoctor
Advisor
Advisor

deleted

0 Likes
Message 11 of 16

denisT.MaxDoctor
Advisor
Advisor

Perhaps the only thing to note is that the multiple definitions should be stored as a block:

 

 

undo "DA" on
(
	attributes __cca attribid:#(0x21111, 0x72111)
	(
		parameters params 
		(
		)
	)
	attributes __caa attribid:#(0x51522, 0x5B222)
	(
		parameters params 
		(
		)
	)
)

 

 

The above example creates two 'undo' records, when there should only be one.

 

 

0 Likes
Message 12 of 16

denisT.MaxDoctor
Advisor
Advisor

@larryminton wrote:

I'll log a ...


Thanks, Larry, for bringing some pieces of the MAX dump to light...

 

By the way, can we also expose some of the theHold MXS methods in the C++ SDK?
(like getMaxUndoLevels, getUndoNames ...)

Message 13 of 16

larryminton
Autodesk
Autodesk

those are exposed via the 'theHold' struct


Larry Minton
Principal Engineer, M&E-Design Animation
0 Likes
Message 14 of 16

denisT.MaxDoctor
Advisor
Advisor

@larryminton wrote:

those are exposed via the 'theHold' struct


I'm asking about the c++ sdk ... Or maybe I missed something? Could you please point to *.h or *.cpp file?

0 Likes
Message 15 of 16

larryminton
Autodesk
Autodesk

Ah, gotcha. Those are not exposed via public sdk.  I'll log a task to add them.


Larry Minton
Principal Engineer, M&E-Design Animation
Message 16 of 16

denisT.MaxDoctor
Advisor
Advisor

@larryminton wrote:

Ah, gotcha. Those are not exposed via public sdk.  I'll log a task to add them.


👍

0 Likes