Custom python script not show up in Flame2022

Hello, all the experts:

I was using some modified python scripts for creating custom library management since Flame 2020. After brought those scripts into Flame 2022, some scripts just don’t show up from the context menu. Wondering if it’s the issue from Python 2.7 to 3.7? And how should I fix it when I’m not any savvy at scripting…T_T

Appreciate for any suggestion or hint, as always~ Have a good weekend,

Jeff Chin

Yea, sounds like some of your scripts aren’t working with 3.7. Best bet is to check the terminal for errors. The most common problem I ran into ground from 2.7 to 3.7 is print. In 3.7 anything being printed needs to have (). So this: print ‘something’ needs to be: print (‘something’)

Mike

1 Like

Thanks Mike. Maybe I should start from some documents of the syntax difference between 2.7 and 3.7…It’s should be a good start point for morning studying :slightly_smiling_face:

Jeff Chin

I had a couple of export python script that I borrowed from someone and I don’t know anything about python. If you Google python 2 to 3 converters online, some of them allow you to copy paste python to scripts and they auto convert to python three. Your mileage may vary.

Hi, Randy:

Thanks for the hint! I’ve tried several online scripting converter (i.e. https://python2to3.com) this morning but no luck. Wondering if I should install Python 3.x explicitly because my Flame’s running on MacPro…I’ll keep on digging~

Wish you a wonderful weekend!

Jeff Chin

You shouldn’t have to install a Python package as Flame comes with its own Python package. Please try to launch Flame from a Terminal, run your custom action and send us the errors that appear in the terminal (they might appear right at startup).

1 Like

Hi, Warren:

Greatly appreciate for your help here!!
I’m away from the office this couple days and will follow your suggestion right after back to work tomorrow~

Best wish,
Jeff Chin

Dear Warren (and any kindly genius):

Here I found several lines show some error message about python when startup Flame in terminal window:

Python encountered SyntaxError(‘unexpected character after line continuation character’, (‘/opt/Autodesk/presets/2022.3/python/create_process_libraries.py’, 1, 37, ‘{\rtf1\ansi\ansicpg1252\cocoartf2638\n’)) in unknown code

[PYTHON HOOK] An error occurred. Ignoring python hooks from /opt/Autodesk/presets/2022.3/python/create_process_libraries.py

Following are some more lines addressing the error after login into the Project and User:

Python encountered TabError(‘inconsistent use of tabs and spaces in indentation’, (‘/opt/Autodesk/user/JeffChin_2022/python/create_folder_with_current_date.py’, 12, 17, ‘\timport datetime\n’)) in unknown code

[PYTHON HOOK] An error occurred. Ignoring python hooks from /opt/Autodesk/user/JeffChin_2022/python/create_folder_with_current_date.py

Python encountered TabError(‘inconsistent use of tabs and spaces in indentation’, (‘/opt/Autodesk/user/JeffChin_2022/python/create_new_batch.py’, 12, 65, “\tschematicReels = [ ‘Src’, ’ Pre’ ] #create/name schematic reels\n”)) in unknown code

[PYTHON HOOK] An error occurred. Ignoring python hooks from /opt/Autodesk/user/JeffChin_2022/python/create_new_batch.py

Python encountered TabError(‘inconsistent use of tabs and spaces in indentation’, (‘/opt/Autodesk/user/JeffChin_2022/python/create_media_libraries.py’, 13, 50, ‘\tFootage = customLibrary.create_folder(“Footage”)\n’)) in unknown code

[PYTHON HOOK] An error occurred. Ignoring python hooks from /opt/Autodesk/user/JeffChin_2022/python/create_media_libraries.py

Python encountered SyntaxError(‘unexpected character after line continuation character’, (‘/opt/Autodesk/user/JeffChin_2022/python/create_process_libraries.py’, 1, 37, ‘{\rtf1\ansi\ansicpg1252\cocoartf2638\n’)) in unknown code

[PYTHON HOOK] An error occurred. Ignoring python hooks from /opt/Autodesk/user/JeffChin_2022/python/create_process_libraries.py

And finally is one of my silly tweaked python code as a reference:

def get_media_panel_custom_ui_actions():

	def scope_libraries(selection):
		import flame
		for item in selection:
			if isinstance(item, flame.PyLibrary):
				return True
		return False

	def create_process_library(selection):
		import flame
		procLibrary = flame.project.current_project.current_workspace.create_library("Process")
		procLibrary.create_folder("Batch")
		procLibrary.create_folder("BFX")
		procLibrary.create_folder("WIP")
    
	return [
		{
			"name": "PYTHON: Libraries",
			"actions": [
				{
					"name": "Create Process Library",
					"isVisible": scope_libraries,
					"execute": create_process_library
				}
			]
		}
	]

It’s seems my wrongly syntax confused the application. Any suggestion or recommend book of Python scripting is extremely welcome!

Best wish,
Jeff Chin

Hard to really say without seeing the code that’s causing the problem. I just tried the code you posted and it worked fine. Can you post any of the code that’s giving you a problem? Sounds like there might be a problem in the others with mixing spaces and tabs for indenting your code. If it is mixed try making it all one or the other and see if that helps it any.

Hi, Mike:

Thanks for review my post. The “create_process_libraries.py” is one of the scripts that don’t show up in the context menu. The following are another two similar scripts that not appear as well…

For creating a media library with folders:

def get_media_panel_custom_ui_actions():

    def scope_libraries(selection):
        import flame
        for item in selection:
            if isinstance(item, flame.PyLibrary):
                return True
        return False

    def create_media_library(selection):
        import flame
        customLibrary = flame.project.current_project.current_workspace.create_library("Media")
	Footage = customLibrary.create_folder("Footage")
	Footage.create_folder("Flat")
	Footage.create_folder("Grade")
	customLibrary.create_folder("Artwork")
	customLibrary.create_folder("Stock")
	customLibrary.create_folder("CGI_AFX")
	customLibrary.create_folder("Audio")

    return [
        {
            "name": "PYTHON: Libraries",
            "actions": [
                {
                    "name": "Create Media Library",
                    "isVisible": scope_libraries,
                    "execute": create_media_library
                }
            ]
        }

    ]

and for creating a new batch group:

def get_media_panel_custom_ui_actions():
    def scope_desktop(selection):
        import flame
        for item in selection:
            if isinstance(item, flame.PyDesktop):
                return True
        return False

    def create_new_batch(selection):
        import flame, os
        
	schematicReels = [ 'Src', ' Pre' ] #create/name schematic reels
	shelfReels = [ 'Batch Renders', 'Backup' ] #create/name shelf reels

	#Create batch group with name, start_frame value, duration value, set of schematic 	reel names, set of shelf reel names
	flame.batch.create_batch_group( '30s_SH000',
	start_frame = 1,
	duration = 99,
	reels =  schematicReels,
	shelf_reels = shelfReels )


    return [
        {
            "name": "PYTHON: DESKTOP",
            "actions": [
                {
                    "name": "Create New Batch",
                    "isVisible": scope_desktop,
                    "execute": create_new_batch
                }
            ]
        }
    ]

Finally, there is the code that can show up in context menu correctly:

def get_media_panel_custom_ui_actions():

    def scope_libraries(selection):
        import flame
        for item in selection:
            if isinstance(item, flame.PyLibrary):
                return True
        return False

    def create_shared_library(selection):
        import flame
        import os
        from PySide2 import QtWidgets
        
        dlg = QtWidgets.QInputDialog()
        dlg.setLabelText("Enter the artist name")
        if dlg.exec_():
            name = str(dlg.textValue())
        
        shared = flame.project.current_project.create_shared_library(name)
        shared.acquire_exclusive_access()
        shared.create_folder("from_"+name)
        shared.create_folder("to_"+name)
        shared.release_exclusive_access()

    return [
        {
            "name": "PYTHON: Libraries",
            "actions": [
                {
                    "name": "Create Shared Library",
                    "isVisible": scope_libraries,
                    "execute": create_shared_library
                }
            ]
        }

    ]

I have tried to compare and reference the “create_shared_library” script with other “disappear” ones but can’t figure what’s wrong. Need more learning and luck here >_<

Again I’m very appreciate for your input!

Best wish,
Jeff Chin

Yea, so you are mixing tabs and spaces for your indents. I did a quick fix to this one. It also need an extra import flame. In whatever program you’re using to write your code I would enable rendering of white space. Then you’ll see where you’re using tabs and space. This is how it looks in VS code with white space rendering on. The periods at the beginning of lines are spaces and the little arrows are tabs. They should all only be spaces or all tabs.

def get_media_panel_custom_ui_actions():
    def scope_desktop(selection):
        import flame
        for item in selection:
            if isinstance(item, flame.PyDesktop):
                return True
        return False

    def create_new_batch(selection):
        import flame, os

    import flame

    schematicReels = [ 'Src', ' Pre' ] #create/name schematic reels
    shelfReels = [ 'Batch Renders', 'Backup' ] #create/name shelf reels

    #Create batch group with name, start_frame value, duration value, set of schematic 	reel names, set of shelf reel names
    flame.batch.create_batch_group( '30s_SH000',
    start_frame = 1,
    duration = 99,
    reels =  schematicReels,
    shelf_reels = shelfReels )


    return [
        {
            "name": "PYTHON: DESKTOP",
            "actions": [
                {
                    "name": "Create New Batch",
                    "isVisible": scope_desktop,
                    "execute": create_new_batch
                }
            ]
        }
    ]

Hi, MikeV:

Thanks!!! Is it “Visual Studio Code”? I will look into my scripts with it as your recommendation when I back home (office has security policy…)

However I’ve done this kind of clean up for the script (create_process_libraries.py) and it’s still not show up in the context menu. This is the point that made me confused…I’ll recheck again with VS.

Greatly appreciate for your guide, I’ll keep digging for solution~

Jeff Chin

@JeffChin Python is really picky with tabs and whitespaces. I would recommend running your scripts through a tool like pylint. It should return all the errors to be fixed.

Hi, Mike and Warren:

I’ve checked those scripts and fixed the inconsistent indentation. Then compare those update scripts with the ones currently working and seems promising to me. Starting Flame in terminal window without any error message, which is a good sign, however, the issue still exist…some Python code show up in the context menu but others don’t :flushed:

Below is the screen capture for both the not working and working script. Seems good to me but one of it still hiding from me

Not working script

fairly working script

Maybe it’s time to go to the temple and pray for luck? :sweat_smile:
Thanks and keep welcome for any suggestion~Cheers,

Jeff Chin

Have you tried to intend lines 13, 14, and 15 so they are at the same indentation level as line 12?
You should also remove the whitespaces on line 16.

Dear Warren:

Perhaps I should say genius Warren?

After applied your suggestion, most of the scripts now appear and function as expected :smiley:
Thank you sooooo much sir~ You made me a wonderful Friday!

I should definitely spend more time and efforts on Python. And let me thank you once more for your kindly guiding.

All the best wish,
Jeff Chin

1 Like