fusion.LoadComp not working in Fu9?

User avatar
JCB91
Fusioneer
Posts: 92
Joined: Thu Mar 10, 2016 1:46 am
Been thanked: 1 time

fusion.LoadComp not working in Fu9?

#1

Post by JCB91 » Mon Jan 07, 2019 7:48 am

I have a python module that worked fine with Fu7. Its actually quite simple, it opens a Fu flow at a given path and copies all tools from that comp to the current comp.

Code: Select all

def importNodeTreeTemplate(current_comp, template_path):
	template_comp = fusion.LoadComp(template_path)

	template_comp.Lock()	

	template_tools = template_comp.GetToolList(False)
	
	for i in range(len(template_tools)):
		print(i+1)
		print(template_tools[i+1])
		print(template_comp)
		flow = template_comp["CurrentFrame"]["FlowView"]
		
	....

When running this from Fu7 it really opens the comp and does everything fine, you can watch doing it.

In Fu9 it doesnt seem to work properly. The template_path seems to be correct, but it doesn't open the comp properly. You can see that it doesnt get opened.


Instead it fails:

Code: Select all

    flow = template_comp["CurrentFrame"]["FlowView"]
TypeError: 'NoneType' object is not subscriptable

Any ideas on that?

User avatar
Movalex
Fusioneer
Posts: 56
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 6 times
Contact:

Re: fusion.LoadComp not working in Fu9?

#2

Post by Movalex » Mon Jan 07, 2019 8:50 am

This should work with correct path. What does the `template_path` variable contain?

User avatar
JCB91
Fusioneer
Posts: 92
Joined: Thu Mar 10, 2016 1:46 am
Been thanked: 1 time

Re: fusion.LoadComp not working in Fu9?

#3

Post by JCB91 » Tue Jan 08, 2019 12:23 am

Movalex wrote:
Mon Jan 07, 2019 8:50 am
What does the `template_path` variable contain?
It contains a valid path to a comp.

User avatar
Movalex
Fusioneer
Posts: 56
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 6 times
Contact:

Re: fusion.LoadComp not working in Fu9?

#4

Post by Movalex » Tue Jan 08, 2019 1:09 am

All code elements in your sample work from console. Is it mac or PC path? Would you provide the whole script so I could try it here? The script seems pretty useful, we have to make it work.

User avatar
JCB91
Fusioneer
Posts: 92
Joined: Thu Mar 10, 2016 1:46 am
Been thanked: 1 time

Re: fusion.LoadComp not working in Fu9?

#5

Post by JCB91 » Tue Jan 08, 2019 1:53 am

Its PC path on a network drive. I am printing the path and its looking good.


This is the full importNodeTreeTemplate module:

Code: Select all

def importNodeTreeTemplate(current_comp, template_path):
	print(template_path)
	template_comp = fusion.LoadComp(template_path)
	print(template_comp)
	template_comp.Lock()	

	template_tools = template_comp.GetToolList(False)

	for i in range(len(template_tools)):
		print(i+1)
		print(template_tools[i+1])
		print(template_comp)
		flow = template_comp["CurrentFrame"]["FlowView"]
		flow.Select(template_tools[i+1])
		
	template_comp.Copy()
	template_comp["CurrentFrame"]["FlowView"].Select()
	
	
	# Get template comp boundaries (X and Y coordinates)
	nongroup_tool_list = {}
	ntc = 0
	for i in range(len(template_tools)):
		if "TOOLH_GroupParent" not in template_tools[i+1].GetAttrs():
			ntc += 1
			nongroup_tool_list[ntc] = template_tools[i+1]		
	template_boundaries = cptfu_general.getToolListBounds(template_comp, nongroup_tool_list)
	
	template_comp.Unlock()
	template_comp.Close()
	
	print("Template bounds:" + str(template_boundaries))
	
	
	current_tools = current_comp.GetToolList(False)
	# Get current comp boundaries (X and Y coordinates)
	nongroup_tool_list = {}
	ntc = 0
	for i in range(len(current_tools)):
		if "TOOLH_GroupParent" not in current_tools[i+1].GetAttrs():
			ntc += 1
			nongroup_tool_list[ntc] = current_tools[i+1]	
	current_boundaries = cptfu_general.getToolListBounds(current_comp, nongroup_tool_list)
	
	print("Current bounds:" + str(current_boundaries))
	
	current_comp.Paste()
	
	# offset new tools to position 5 points left of current tools
	new_tools = current_comp.GetToolList(True)
	new_tool_bounds = cptfu_general.getToolListBounds(current_comp, new_tools)
	print("New Bounds:" + str(new_tool_bounds))
	ntr = new_tool_bounds[2]
	ntw = new_tool_bounds[2] - new_tool_bounds[0]
	ctl = current_boundaries[0]
	for i in range(len(new_tools)):
		# new_tools[i+1]["TileColor"] = {"R": 0.5, "G": 0.5, "B": 0.5}
		tool_pos = current_comp["CurrentFrame"]["FlowView"].GetPosTable(new_tools[i+1])
		current_comp["CurrentFrame"]["FlowView"].QueueSetPos(new_tools[i+1], ctl + (tool_pos[1] - ntr - 5), tool_pos[2])
	current_comp["CurrentFrame"]["FlowView"].FlushSetPosQueue()
	
	return new_tools
This module gets imported to my main script that is actually run.

The template path generation:

Code: Select all

template_path = os.path.join(cptvars.fusion_template_path, template_dict[dialog_flow["Template"] + 1])

This is the part where the module gets used in my main script

Code: Select all

		comp_new = fusion.NewComp()
			comp_new.SetPrefs({ "Comp.FrameFormat.DepthLock": False })
			comp_new.SetPrefs({ "Comp.FrameFormat.Width": int(dialog_flow["Width"]), "Comp.FrameFormat.Height": int(dialog_flow["Height"]), "Comp.FrameFormat.Rate": float(cptvars.fps_choice[dialog_flow["FPS"] + 1]), "Comp.FrameFormat.PerFeet": 1, "Comp.FrameFormat.DepthFull": 3, "Comp.FrameFormat.DepthPreview": 3, "Comp.FrameFormat.DepthInteractive": 3})

			comp_new.Save(os.path.join(comp_path, shotname + "_v001_" + fusion.GetEnv("FUSION_PROFILE") + ".comp"))
			
			comp_new.Lock()
			
			
			print(template_path)
			new_tools = cptfu8_import.importNodeTreeTemplate(comp_new, template_path)


Still wondering why this works with Fu7.

User avatar
JCB91
Fusioneer
Posts: 92
Joined: Thu Mar 10, 2016 1:46 am
Been thanked: 1 time

Re: fusion.LoadComp not working in Fu9?

#6

Post by JCB91 » Tue Jan 08, 2019 3:55 am

Its definitely a problem that my importNodeTreeTemplate module is being imported and not in the main script. Just did a test with the function inside the main script and it worked. What does Fu9 do differently from Fu7?

User avatar
Movalex
Fusioneer
Posts: 56
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 6 times
Contact:

Re: fusion.LoadComp not working in Fu9?

#7

Post by Movalex » Wed Jan 09, 2019 12:26 am

Do you have import statement for your module in a launcher script? Seems like you didn't have to import modules in fy7?
To import module it has to be in 'sys.path', so I would try to append the script path there.
But in this case 'fusion()' and 'comp()' modules become unavailable, at least on my side.
It would be cool if some script guru here made a short tutorial how to properly import python modules in fu9.
Here's what I found so far, but I'm still uncertain:
viewtopic.php?f=6&t=2512&p=19555&hilit= ... ule#p19555

User avatar
JCB91
Fusioneer
Posts: 92
Joined: Thu Mar 10, 2016 1:46 am
Been thanked: 1 time

Re: fusion.LoadComp not working in Fu9?

#8

Post by JCB91 » Wed Jan 09, 2019 1:04 am

Of course in my main script I do have the import of my module

Code: Select all

import cptfu8_import

Later it gets used like this, as posted above:

Code: Select all

			new_tools = cptfu8_import.importNodeTreeTemplate(comp_new, template_path)

And in Fu7 its exactly the same and it works.

Also it would fail if the module doesnt get imported right?

We have a Environment variable PYTHONPATH that is pointing to a folder with all the python includes.

User avatar
Movalex
Fusioneer
Posts: 56
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 6 times
Contact:

Re: fusion.LoadComp not working in Fu9?

#9

Post by Movalex » Wed Jan 09, 2019 2:56 am

Did you try to import bmd into the imported module?
  1. import BlackmagicFusion as bmd
  2. fusion = bmd.scriptapp("Fusion")
  3. comp = fusion.GetCurrentComp()
I ended up with this solution, seems to work (I placed launcher.py into Scripts:/Comp folder, fu9import.py is in C:\pymodules):
launcher.py
fu9import.py
You do not have the required permissions to view the files attached to this post.

User avatar
JCB91
Fusioneer
Posts: 92
Joined: Thu Mar 10, 2016 1:46 am
Been thanked: 1 time

Re: fusion.LoadComp not working in Fu9?

#10

Post by JCB91 » Wed Jan 09, 2019 3:37 am

I already have this in my cptfu8_import:

Code: Select all

if not "fusion" in locals()["__builtins__"]:
	import BlackmagicFusion as eyeon
	fusion = eyeon.scriptapp("Fusion")
	
When trying to execute your scripts I get this:

Code: Select all

  File "C:\pymodules\fu9import.py", line 4, in <module>
    print(comp.GetAttrs())
AttributeError: 'NoneType' object has no attribute 'GetAttrs'

User avatar
Movalex
Fusioneer
Posts: 56
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 6 times
Contact:

Re: fusion.LoadComp not working in Fu9?

#11

Post by Movalex » Wed Jan 09, 2019 5:26 am

Wow, on my second computer I have exactly the same AttributeError... That'd weird

User avatar
JCB91
Fusioneer
Posts: 92
Joined: Thu Mar 10, 2016 1:46 am
Been thanked: 1 time

Re: fusion.LoadComp not working in Fu9?

#12

Post by JCB91 » Wed Jan 09, 2019 5:41 am

I am running here Win10 Pro 10.0.17763 Build 17763, Python 3.6.7, Fusion 9.0.2 build 15.

Do you see any differences in your two different setups?

Maybe the comp in your downloads is missing?

Code: Select all

'C:\Users\abogomolov.RC\Downloads\test.comp'

User avatar
Movalex
Fusioneer
Posts: 56
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 6 times
Contact:

Re: fusion.LoadComp not working in Fu9?

#13

Post by Movalex » Wed Jan 09, 2019 7:26 am

Yep, you were right, the path was wrong. But nevertheless after fixing the path I had had that strange AttribError. But suddenly I found what was wrong in my case.
Could you please check if you have Fusion Render Node running on your machine? Or at least unwanted FusionScript service hanging around in Task Manager? After I stopped this service and restarted Fusion, my test script started working on my second computer too.

User avatar
JCB91
Fusioneer
Posts: 92
Joined: Thu Mar 10, 2016 1:46 am
Been thanked: 1 time

Re: fusion.LoadComp not working in Fu9?

#14

Post by JCB91 » Wed Jan 09, 2019 7:53 am

I killed the "FusionScript services for Fusion Render Node". Now its working fine! Cant believe this


I am not sure if this service might be essential for the Render Node. Actually this a very bad issue. Hopefully BMD will fix this somehow.

Thank you for your help, Movalex!

User avatar
Movalex
Fusioneer
Posts: 56
Joined: Fri Nov 03, 2017 5:36 am
Been thanked: 6 times
Contact:

Re: fusion.LoadComp not working in Fu9?

#15

Post by Movalex » Wed Jan 09, 2019 8:07 am

Yeah, the amount of WTF's I was spreading around after founding this out was uncountable...
BTW, are you on board? There's a nice Fusion community on Discord called Pirates of ConFusion. If not, you are welcome!