It is probably evident to everyone the real power of Shotgun is its ability to exchange the stored or yet-to-be-stored data (such as Project Name, Shot Name, Task Name, First Frame Number, Output Resolution and etc etc). If set up properly any application supporting Python (such as Maya) would be able to send and receive the information (the data) from Shotgun. Unfortunately this extremely important subject is not well documented. I make my best efforts to puzzle together the randomly spread across Shogun's forum pieces of the information that would help me to understand how this all works in Shotgun. This message is an attempt to summarize of what I could learn so far (from perspective of the Computer Graphics professional for whom Python and other programming languages are subset of the main toolset).
SENDING DATA FROM SHOTGUN.
a. Create Custom Action Menu Item First
To be able to send the data from Shotgun the user should create a Custom Action Menu Item (or for simplicity sake let's call it just a "Custom Action Menu"). After it is created the Custom Action Menu will appear as a new command under the Gear icon or in Right-Click pull down menu.
The Shotgun's Custom Action Menu is created outside Shotgun itself. You can create it from Python command prompt, from Maya Python script editor. Or you can simply write a Python script with a proper syntax, save it and double click to execute. If the Python script was written properly next time you login to your Shotgun session you should be able to see your new Custom Action Menu in place.
The Python syntax for the Custom Action Menu's creation is very simple.
First you need to load so-called "Python modules", or simply-put - a pre-written set of instructions Python needs to be aware of before it executes the commands written in your script.
from shotgun_api3 import Shotgun
from pprint import pprint
Then specify a basic info for your Shotgun web site:
SERVER_PATH = 'https://yourShogun.shotgunstudio.com'
SCRIPT_NAME = 'your_api_script'
SCRIPT_KEY = 'your_api_script_key_long_series_of_numbers_and_letters'
Now type the Python command to get connected to your Shotgun
sg = Shotgun(SERVER_PATH, SCRIPT_NAME, SCRIPT_KEY)
Now type the values for the Action Menu itself. Give it a tittle in "title": key. "URL:" is where the real Python script will be uploaded to and downloaded from
"entity_type": key is used to make your Action Menu appear under only specific Shotgun entities such as Project, Shot, Version, Asset and etc
If you create an Action Menu for Versions then type "version". If it is to be used with the Shot entities then type "shot" and etc.
data = {
"title":"My_Action_Menu",
"url": "http://www.mydomainnameaddress.com/my_python_scripts/myPython_Script.py:",
"list_order": 1,
"entity_type": "Shot",
"selection_required": False,
}
# Now, the very last command is to actually create the Action Menu
menu_item = sg.create("ActionMenuItem", data)
Now. Let talk what happens when the user selects this Action Menu from pull down menu by Right-Clicking the entity name or from the Gear icon pull down menu.
The following description on what happens when the Action Menu is clicked is based on my assumptions other than on my knowledge. So I can easily make false statements here.
As soon as Action Menu is clicked Shotgun looks at this Action Menu's definition (set at the time the Action Menu was created). It is this line of code that is most important:
"url": "http://www.mydomainnameaddress.com/my_python_scripts/myPython_Script.py:",
Shotgun reads the value defined in this line. First It determinate a so-called PROTOCOL. A Protocol is that word that proceeds the www address. In this case it is "HTTP". After Shotgun knows it is HTTP it is now can download the script into system memory from the specified URL location:
www.mydomainnameaddress.com/my_python_scripts/myPython_Script.py
Since it is a Web Based Protocol (since it is HTTP Protocol) Shotgun is sending all the data using once again a web-based GET protocol.
Depending on what was selected in Shotgun at the time the Action Menu was clicked (Project, Shot, Asset or Version) Shotgun sends a different data to the system memory (via GET protocol). For this example, let's assume Shotgun sends the "Project Name", "User Name" and "Shot Name" data.
The data is sent. The Python script was downloaded from the specified URL address and placed into the system memory for an execution. Python executable is called. Python reads the Python script just downloaded and placed in memory. Hopefully the Python script was written to be able to process the data sent by Shotgun via GET protocol. There must be some string or array variable defined in the downloaded Python script that would then allocate the sent by Shotgun data and process it.
We would need to make sure that the Python script that was downloaded and now being executed by Python has the right syntax or the set of commands that are able to receive and to process the Shotgun data.
The rest is quite simple. It is up to the user to decide what they want to do with the information or with the data received from Shotgun.
What I would like to know now is how to write a Python script to make sure Python is able to get the data sent via GET protocol. What would be a command syntax for it? If let's say I have a string array
my_string_array = []
what line of code I should be using to store the data sent from Shotgun via GET protocol into my_string_array?