Custom Node - Input lists Error

Dear network,
I am trying to create a custom node to draw plots using matplot lib. I need to give inputs as “lists” to my custom node, But an error occurs as follows,

Hi @utech.udara ,

I am not an expert with creating custom nodes but you should use something like this (i think).

String and Int

(Or, if the first one doenst work) Var or Var

Ps: do you need to specify the input types at all?

1 Like

Hello,
you have to look at the script by M. C. Poupin
I tried but with I have trouble with python, if it can help you Can I use matplotlib in Dynamo? - #5 by c.poupin

I attach what I tried to do

# Charger les bibliothèques DesignScript et Standard Python
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import os

clr.AddReference('System.Drawing')
import System.Drawing
from System.Drawing import *
from System.Drawing.Imaging import *
from System.IO import MemoryStream

localapp = os.getenv(r'LOCALAPPDATA')

sys.path.append(os.path.join(localapp, r'python-3.9.12-embed-amd64\Lib\site-packages'))
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
import io
import math



# Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
a=IN[0]
b=IN[1]


# Placer votre code au-dessous de cette ligne
def plt2arr(fig):
    fig.canvas.draw()
    rgba_buf = fig.canvas.buffer_rgba()
    (w,h) = fig.canvas.get_width_height()
    rgba_arr = np.frombuffer(rgba_buf, dtype=np.uint8).reshape((h,w,4))
    return rgba_arr

def convertToBitmap2(npImgArray):
    bitmap_ = None
    # remove alpha
    if npImgArray.ndim == 3 and npImgArray.shape[-1] == 4:
        npImgArray = npImgArray[:, :, :-1]
    # convert to PIL Image
    if npImgArray.ndim == 3:
        image = Image.fromarray(npImgArray, "RGB")
    else:
        image = Image.fromarray(npImgArray, "L")
    # convert to Python ByteArray
    byteIO = io.BytesIO()
    image.save(byteIO, format='BMP')
    byteArr = byteIO.getvalue()
    # convert to Net ByteArray
    netBytes = System.Array[System.Byte](byteArr)
    with MemoryStream(netBytes) as ms:
        bitmap_ = Bitmap(ms)
    return bitmap_
    
xpoints = np.array(b[0])
ypoints = np.array(b[1])
plt.plot(xpoints,ypoints)
plt.xlabel(a[0])
plt.ylabel(a[1])
fig=plt.figure()
ax = fig.add_subplot(111)
ax.plot(xpoints,ypoints)
ax.set_xlabel(a[0])
ax.set_ylabel(a[1])

image_from_plot = plt2arr(fig)
bitmap1 = convertToBitmap2(image_from_plot)

# Affectez la sortie à la variable OUT.
OUT = bitmap1

Cordially
christian.stan

2 Likes

@christian.stan Thank you for the reply. Yes, I have followed it and used the python fuction defined. However, the issue occurs when I create a custom node. The idea is to reuse the node at different locations rather creating python node repeatedly.

1 Like

Hi!

But when I use var instead of List , then custom node take one item at a time. That’s the problem :frowning:

Hello,
I tried like this if can help you


Cordially
christian.stan

2 Likes