Is there any way to integrate a function within dynamo/within a python script?
I have used the scipy package within python before (which can accomplish what I want to do), but did not know if there was any way to import this package into a python script within dynamo.
Short answer:
Maybe, but not with NumPy. Try Math.NET
Long answer:
A lot of NumPy/SciPy is written in C, and since IronPython is a .NET implementation of Python, it’s incompatible with the standard NumPy and SciPy modules. There is a version of Numpy/SciPy written specifically for use with IronPython, but I haven’t been able to get it to work in Dynamo. I can successfully import it in the ipy console, though:
The ironpkg-1.0.0.py script is no longer on Enthought’s website (although the .egg is available), but someone has it on one of their GitHub repositories. Download the eggs manually from here and put them in a new folder.
Additional steps can be found here (skip steps 1 and 2)
Do you have any references on how to import math.net into the python dynamo node?
Still somewhat new to this and help on the import/setup process to import the math.net integration function would be helpful.
An example how to import Math.NET into Iron Python. I test it and works fine.
import sys
sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")
sys.path.append("D:\\Dropbox\\Dynamo Workspaces\\Nuget\\MathNet.Numerics.4.5.1\\lib\\net40\\MathNet.Numerics.dll")
import os
# Import
from clr import AddReferenceToFileAndPath as addref
location = os.path.join(os.path.expanduser("~"),
'D:\\Dropbox\\Dynamo Workspaces\\Nuget\MathNet.Numerics.4.5.1\\lib\\net40\\MathNet.Numerics.dll')
addref(location)
import MathNet.Numerics.LinearAlgebra as la
from System import Array as sys_array
def array(*x):
return sys_array[float](x) #float is equivalent to .Net double
A = la.Double.Matrix.Build.DenseOfRowArrays(array(3, 2,-1),array(2,-2,4),array(-1,.5,-1))
B = la.Double.Vector.Build.DenseOfArray(array(1, -2, 0))
x = A.Solve(B)
OUT = x