Giter Club home page Giter Club logo

Comments (4)

benoit-fouletier avatar benoit-fouletier commented on August 21, 2024

I was just about to open an issue about this, this indeed hangs hard. Any luck finding a workaround?

from cmdx.

mottosso avatar mottosso commented on August 21, 2024

No, sorry. I've avoided it ever since :( If you happen to come across one, please do share!

from cmdx.

benblo avatar benblo commented on August 21, 2024

OK, found the issue (and a fix)!

The issue is, in Compound.create() (and actually in every attribute type), you use the same global (static) function set for every instance. I suspect this is a problem, since the Fn must actually be associated with the actual MObject upon create() . So when later you do:

	self.Fn.addChild(child.create(cls))

the child can be added to the correct mobj... which means you can't reuse Fn, it has to be unique. The same might be true (?) for the other attribute types.

I saw examples online that make this clearer:

	fn = om.MFnDependencyNode()
	fn.setObject(mobj)

... I have to admit I don't understand the API's terminology there, if the function set is indeed associated with an object then it's not really a function set but an instance isn't it, so what's the difference? beats me.

Also, I noticed that you're using self.Fn, but Fn is actually declared as a class attribute, not an instance attribute, so shouldn't it be Compound.Fn instead? I don't mean to be pedantic, this usage might be pythonic, but I'm quite new to Python (and Maya too actually) so still getting used to some things that feel odd to me coming from C#/C++ ☺️.


Anyway, not sure I have the correct diagnosis, but to fix this I instantiated a new Fn for each instance:

    def __init__(self, name, children=None, **kwargs):
        self.Fn = om.MFnCompoundAttribute()
        ...

... no more hangs!
(I don't have time atm to make a proper fork and PR, but once I do (hopefully) I'll have a few other fixes to send your way.)


... that being said, unfortunately the attribute editor doesn't show nested compounds :( !
Here's a simple test:

	compound = cmdx.Compound("cmdx_1_compound", children=[
		cmdx.String("cmdx_1_1_string", default="1_1"),
		cmdx.String("cmdx_1_2_string", default="1_2"),
		cmdx.Compound("cmdx_2_compound", children=[
			cmdx.String("cmdx_2_1_string", default="2_1"),
			cmdx.String("cmdx_2_2_string", default="2_2"),
		]),
		cmdx.String("cmdx_1_3_string", default="1_3"),
	])

	sphere = cmdx.encode(cmds.sphere()[0])
	sphere.add_attr(compound)

image
The "cmdx_2_compound" attribute is there, but folded (children are invisible). I can query back the attributes so they're stored properly, just not displayed in the editor.

Any idea how to fix this?
I tried doing the same with cmds, or 'vanilla' OpenMaya; same result. I don't know if there's some flag I can set to tell Maya "yes please display this nested attribute", or "display up to N levels of nesting"...


(BTW I'm the same benoit-fouletier as earlier! I used my work account the last time, but github doesn't play nicely with multi-accounts so I'll be using my regular account from now on.)

from cmdx.

mottosso avatar mottosso commented on August 21, 2024

OK, found the issue (and a fix)!

Aaaaah, yes I think you are on to something here!

Anyway, not sure I have the correct diagnosis, but to fix this I instantiated a new Fn for each instance:

Yes, even if this isn't the solution to this particular issue, this is the correct way of doing it regardless. Let's definitely PR this.

Also, I noticed that you're using self.Fn, but Fn is actually declared as a class attribute, not an instance attribute, so shouldn't it be Compound.Fn instead?

These are the same. I would generally use self to avoid having to remember or pay attention to that Compound is the class you're in as you read it, and not referencing some other class somewhere else in the file. But, I can see how it isn't clear-cut, as that is also the syntax of instance variables. So, I would leave it.

unfortunately the attribute editor doesn't show nested compounds :( !

Oh that's a bummer.. My guess is you need a dedicated attribute editor template for things like that.

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.