ViewCaptureToFile in RhinoCompute

I have one 3dm file by hand, and have set the locally debug environment. Language im using is Python.

Question: How could I achieve the similar effect of ‘ViewCaptureToFile’ through the pure code way?

Assumed Steps: Readfile-- SetView-- ViewToBitmap (I saw these in RhinoCommon API, but not in Rhino3dm or the Rhino_Compute documentation or repos… so kind get stuck)
:face_with_spiral_eyes: :melting_face:

0802_ScrnShot_POST.gh (9.8 KB)

I tried to achieve this effect in the gh context, and it works. But I DO want to get rid of the gh file, and can run it directly from the console or python prompt window.

So as you can see in the gh file, I add the Get_XXX component new in Rhi8. However, when I run it together with the codes below in the locally debugging environment, it fails.

Code:

Path=str(os.path.dirname(os.path.realpath(__file__)))
Path=r"{}".format(Path)
Switch=True

#stringtify objs
Path_serialized=json.dumps(Path)
Path_tree=gh.DataTree("Path")
Path_tree.Append([0],[Path_serialized])


Switch_serialized=json.dumps(Switch)
Switch_tree=gh.DataTree('Switch')
Switch_tree.Append([0],[Switch_serialized])

trees=[Path_tree,Switch_tree]

gh.EvaluateDefinition('0802_ScrnShot_POST.gh',trees)

Error Message in Console:

Error Message in Compute.exe: