mottosso / cmdx

Fast and persistent subset of maya.cmds
https://mottosso.com/cmdx
BSD 2-Clause "Simplified" License
193 stars 36 forks source link

Fix disconnect/connect with Undo #46

Closed mottosso closed 3 years ago

mottosso commented 3 years ago

This fixes #45

I've also moved the MYPY statement to below the import statements to make linters happy; but I wonder whether this breaks things for you @benblo?

mottosso commented 3 years ago

This is still somewhat fragile; the user can still..

mod.disconnect(a, b)

Which would try and disconnect both source and destination connections to both a and b, even if no connections exists. If that's the case, Maya will happily carry on. Until you undo, which is when it'll tell you "hey, something you did at some point in the past was wrong, so now I will throw an exception. Happy hunting."

We can address this by testing that an attribute is actually connected before attempting to disconnect it.. but that's somewhat of a rabbit hole. As what really matters is what is connected upon calling doIt. A connection could not exist when calling disconnect but then later be made, which would invalidate whatever check we perform during the call to disconnect.

So I'm leaving that as-is for now. Hasn't been a problem so far.

mottosso commented 3 years ago

Took another crack at this, and oh man.

tm = cmdx.createNode("transform")
tm["tx"] << tm["ty"]

with cmdx.DagModifier() as mod:
  mod.disconnect(tm["ty"], tm["tx"])

# OK

Except, it's not OK. Maya cares deeply about the order in which you specift the disconnect. Here, it'll try and disconnect tx from ty, except tx is not connected to ty. It's the other way around. So guess what happens? Nothing, ignored. And guess what happens on redo? ty gets a connection to tx. xDDD Lol. That's bad.