Giter Club home page Giter Club logo

Comments (3)

mottosso avatar mottosso commented on August 21, 2024

Hi @GuidoPollini, thanks and happy to hear you like it. :)

clashes are possible for nodes in the same scene

Indeed, except that leaves out the very next and most important line from the docs.

However different MObjectHandles whose MObjects refer to the same internal Maya object will return the same hash code.

In other words, it always returns the same node in the scene, which is exactly what you want. That's how you can get the same instance of the singleton like this.

instanceA = cmdx.createNode("reverse", name="myNode")
instanceB = cmdx.ls(type="reverse")[0]
assert instanceA is instanceB

Because they will be the same variable.

instanceA._my_special_data = "Hello!"
print(instanceB._my_special_data)
# Hello!

from cmdx.

GuidoPollini avatar GuidoPollini commented on August 21, 2024

Indeed:).
if I'm not wrong, in case of clash the Singleton._instance will lose the reference to the original wrapper and (if no cycles are involved) next garbage collection will call Node.del unregistering the callbacks.
It should all be fine:)

from cmdx.

mottosso avatar mottosso commented on August 21, 2024

I should hope __del__ is only called when the last reference is lost, rather then once there is a clash. In my code, I call cmdx.uninstall() on scene open to clear out any references and old commands from undo, which is when I expect __del__ to get called.

In practice it has been working well so far. Have been using this for a few years now in all of my Maya projects, most recently/currently ragdoll.

Thanks for double-checking, if you come up with any optimisations or improvements, feel free to share!

from cmdx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.