Creating new topic for discussion from this thread below @Hadi.Moosavi
It is possible to get images using matplotlib by creating a temp file and loading it in using the DSCore.IO methods
Be warned it is quite the task to get all the python libraries working as openseespy has to be version 3.4.0.8 (python 3.9 / Dynamo 2.19) including a modification to the __init__.py file in the openseespywin folder to point to the tkinter install. Basic code below and image using an Opsvis example
import clr
import io
import os
import tempfile
import matplotlib.pyplot as plt
clr.AddReference("DSCoreNodes")
import DSCore
def image(fig):
with io.BytesIO() as buf:
fig.canvas.print_png(buf)
with tempfile.NamedTemporaryFile(
mode="w+b", prefix="IMG_", suffix=".png", delete=False
) as fp:
fp.seek(0)
fp.write(buf.getvalue())
fp.close()
# Dynamo Core Image
filepath = DSCore.IO.FileSystem.FileFromPath(str(fp.name))
image = DSCore.IO.Image.ReadFromFile(filepath)
os.remove(fp.name)
return image
# Clear memory
plt.close("all")
# Script here creating pyplot figures
OUT = [image(plt.figure(n)) for n in plt.get_fignums()]
Posting the code would be easier than trying to guess what is above line 19
Read the full warning and try and work back
Line 38 is incorrect - change to fp.close() to call the method
Uncomment import clr and add the following lines if they are not present above