Running Python (that works independently) inside Dynamo?

IronPython and PythonNet have access to the .Net framework (a huge .Net library) so here is an alternative you can use

import sys
import clr
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('System.Drawing')
from System.Drawing import *
from System.Drawing.Drawing2D import *

myBitmapPath = IN[0]
out_folder = System.IO.Path.GetDirectoryName(myBitmapPath)
out_bmp_path = out_folder + "\\out_img.png"
text_to_draw = IN[1]

bmp = Bitmap(myBitmapPath)
rectf = RectangleF(bmp.Size.Width / 2, bmp.Size.Height / 2  - 180, 160,  30)
g = Graphics.FromImage(bmp)
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic
g.PixelOffsetMode = PixelOffsetMode.HighQuality
g.DrawString(text_to_draw, Font("Tahoma", 20), Brushes.Black, rectf)
g.Flush()
bmp.Save(out_bmp_path)

OUT = bmp
3 Likes