Comments (4)
I was just about to open an issue about this, this indeed hangs hard. Any luck finding a workaround?
from cmdx.
No, sorry. I've avoided it ever since :( If you happen to come across one, please do share!
from cmdx.
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)
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.
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)
- cmdx.listRelatives always returns None HOT 18
- Plugs not taking and returning UI units HOT 4
- DagNode.addChild crashes in certain circumstances HOT 6
- Modifiers and data types HOT 2
- design proposition for components HOT 10
- attributes' default value not saved in scene HOT 3
- Support for proxy attributes
- DGModifier.disconnect and Undo
- Attribute reuse and undo
- Multiple versions simultaneously
- How to debug Maya crashes? HOT 9
- Deploy on CI HOT 1
- Direct passing of cmdx.Node to vanilla cmds HOT 3
- Support keyframing of pairBlended attributes
- MObjectHandle hashCode... HOT 3
- Two users, one machine
- Thoughts on code formatter such as Black? HOT 5
- Set a nodes transform HOT 7
- Auto offset group
- Add type annotations HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmdx.