View Full Version : Connecting a control with an attribute
ConSeannery 05-16-2008, 07:23 PM Hi!
I was wondering what the most elegant way is to establish a two-way connection between a control and an attribute.
I know there are attrControl... attrSlider controls which have this function built in. Other controls can use the connectControl command.
But which method is best if I want to use other controls for two-way connections, like symbolButtons, or iconTextCheckboxes etc. Do I have to write procedures then?
Thx!
|
|
drGonzo
05-16-2008, 08:38 PM
Check out the connectControl command
ConSeannery
05-16-2008, 09:35 PM
I mentioned the command in my posting, but the manual says it doesn't work for all controls.
Buexe
05-16-2008, 09:46 PM
The question is if you really need this dragging behaviour on an iconTextCheckBox ( which doesn`t seem to work for me on OSX btw). These slider/dragger controls are supposed to simulate the behaviour of being directly connected to some attribute without actually having a DG connection, as you probably know. You probably have your reasons why you would want this , but is dragging a checkBox really the goal ? Maybe callbacks (sciptjobs) would be a method to evaluate, since they can trigger all sorts of stuff and get notice when scenes are being loaded, etc. If you could specify a little bit more what you are after, maybe I could be more helpful : )
ConSeannery
05-16-2008, 10:04 PM
No I don't need this dragging behaviour on the iconCheckBox.
I just want the iconCheckBox to be two-way connected with another on/off switch, like for instance switching global illumination on and off so that when changing the status of either on/off switch the other one reacts accordingly.
As far as I understood from the manual this behaviour is not default...?
ConSeannery
05-16-2008, 10:19 PM
The connectControl command works two-ways for a simple checkBox, but not for an iconCheckBox. With an iconCheckBox the connectControl command doesn't cause an error, but it only works as a one-way connection.
Buexe
05-16-2008, 11:35 PM
Well, I don`t know how deep you are into GUI stuff in Maya, so please excuse if I tell you something you already know. Usually an interface has layouts and controls (the visible stuff) that need to be existent to start with. Next it interfaces with various other parts of Maya. Since Maya is more or less an interface to a bunch of connected nodes with attributes( rough explanation of the DG ), the GUI stuff needs ways to change attributes, but also get information when some attribute changes. This would be done through callbacks. There are various so called events ( something has happened ). These Callbacks simply say: "Yo something has happened!" and start a script that YOU can define. This script should then check what has happened and take appropriate measures, like updating the controls so that the information is synchronized with the rest of Maya. So there are usually different types of scripts that need to act together to get more sophisticated behaviour. Usually they can be categorized :
1. create stuff ( windows, layouts, controls)
2. update stuff ( get the info and synchronize )
3. save info, reset info ( optionVar )
4. registering + deleting callbacks
5. cleaning up stuff
6. do something
This is roughly the way I do it. That does not mean anyybody else should do it this way if they have something better. But if you take your example, there is a layout with controls (render globals) and there are node(s) (mentaRayGlobals). Now if you select your mentalRayGlobals node and open up the AE and then open the render globals and change attributes on either one, the information "magically" synchronizes between those two locations. The reason behind this are callbacks that were initiated at some point and get triggered when something changes. Check the Script Editor to get names what those scripts are called. If you want to see how they work type for example "whatIs mentalRayOptionsCheckFinalGather". Maya will give you a file name where this proc is stored and you can take a look at how this "connection magic" actually works. I hope that I understood you and your intentions correct : )
Cheers
drGonzo
05-17-2008, 07:39 AM
I mentioned the command in my posting, but the manual says it doesn't work for all controls.
Ooops sorry. I read your post to fast.
ConSeannery
05-18-2008, 03:26 PM
Well, I don`t know how deep you are into GUI stuff in Maya, so please excuse if I tell you something you already know. Usually an interface has layouts and controls (the visible stuff) that need to be existent to start with. Next it interfaces with various other parts of Maya. Since Maya is more or less an interface to a bunch of connected nodes with attributes( rough explanation of the DG ), the GUI stuff needs ways to change attributes, but also get information when some attribute changes. This would be done through callbacks. There are various so called events ( something has happened ). These Callbacks simply say: "Yo something has happened!" and start a script that YOU can define. This script should then check what has happened and take appropriate measures, like updating the controls so that the information is synchronized with the rest of Maya. So there are usually different types of scripts that need to act together to get more sophisticated behaviour. Usually they can be categorized :
1. create stuff ( windows, layouts, controls)
2. update stuff ( get the info and synchronize )
3. save info, reset info ( optionVar )
4. registering + deleting callbacks
5. cleaning up stuff
6. do something
This is roughly the way I do it. That does not mean anyybody else should do it this way if they have something better. But if you take your example, there is a layout with controls (render globals) and there are node(s) (mentaRayGlobals). Now if you select your mentalRayGlobals node and open up the AE and then open the render globals and change attributes on either one, the information "magically" synchronizes between those two locations. The reason behind this are callbacks that were initiated at some point and get triggered when something changes. Check the Script Editor to get names what those scripts are called. If you want to see how they work type for example "whatIs mentalRayOptionsCheckFinalGather". Maya will give you a file name where this proc is stored and you can take a look at how this "connection magic" actually works. I hope that I understood you and your intentions correct : )
Cheers
Thanks a lot, Buexe! That was helpful. I am new to programming and thus also new to MEL. I guess I have to look into callbacks.
The only callbacks available for buttons are drag and dropcallbacks, right? So these can't be used to synchronizing...?
So if I understood you right the only way to synchronize values is by writing a procedure?
How exactely can I find the name of one of these procedures? You mentioned the whatIs command, but this one only gives me the message "Result: Unknown". Or does the mentalRayOptionsCheckFinalGather not exist?
ConSeannery
05-18-2008, 03:41 PM
Oops, got it now! I accidently had "Suppress Command Results" turned on.
Thanks a again! ;-)
Buexe
05-18-2008, 05:10 PM
Generally controls have the "-command" flag and the "-changeCommand" flag. Attach your procedure to these flags.
CGTalk Moderation
05-18-2008, 05:10 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.