python - creating a button that can select an object/locator in the scene

python - creating a button that can select an object/locator in the scene

Anonymous
Not applicable
1,386 Views
1 Reply
Message 1 of 2

python - creating a button that can select an object/locator in the scene

Anonymous
Not applicable

Hi Guys,

I'm completely new to python and pretty new to Maya and reqire some help.

 

Using python in maya i've managed to create a UI with a button and a text field next to it.

The intended purpose of the button is to be able to "click it" and then select an object/locator in the scene to get/store it's transform infomation for use later in the script.

The purpose of the textfield is to state the name of the object that has been selected.

 

If someone could show/provide the code for doing this that would be very much appreciated

 

thanks in advance

0 Likes
1,387 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable

Well, MEL, and by association cmds does not have a particular native UI control that is the same as what you would get in 3DSMax (pickbutton), possibly because Max uis can be or are often Modal, meaning that the rest of the interface is effectively non interactive until you select something that is associated with the command under the pickbutton object.

 

If you were using QtDesigner and QT then you would fare better and have an easier(ish) time of creating what you want to do.

 

If you stay with Python wrapped MEL (cmds.something(attribute = True)) then you have two immediate choices as I see them.

1. Utilise a different methodology to get what you want i.e select an object, then hit a button in the UI to do something with it, list, delete move etc.

2. Create a script job that will allow for something to happen when something else happens, then delete the script job from memory.

 

Im not that keen on script jobs, as I favour using QT to do most of my UI creation, but if that is not viable for you right now, look at the options above. They are not the only solutions, but as you are new to scripting, perhaps its a good time to try them out.

 

Are there no TDs at your work who can help you with this? Perhaps a tall, well educated one with a beard and bad language? Hehehehehe

 

For future reference, might be best if you have a go, show what coding you have tried and then ask for help as it is often the case that people post here in the hope that others will write their code for them, which will not help you learn.

 

Pm if you want, I will see what I can rustle up.

 

Regards

0 Likes