Hi all,
I was wondering if it was possible to import a .pyd module into the dynamo python interpreter? It works fine in VSC, but in dynamo I get an Import Error. I’m guessing it’s because dynamo uses Iron Python? I’ve had a read around but can’t find a fix, I found this on stack overflow. Has anyone overcome this? Any help would be appreciated.
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 3, in
ImportError: No module named fmeobjects
Here is my code:
import sys
sys.path.append(r'C:\Program Files\FME\fmeobjects\python27')
import fmeobjects
OUT = dir(fmeobjects)
Thanks,
TJ
You can’t import C python modules directly into iron python but you can launch a sub-process with a regular python interpreter (or any other program for that matter), pipe data over to the sub-process, perform the desired functionality and finally bring the result back over to Dynamo.
A common way to send data back and forward is with an intermediate file.
Cheers @Dimitar_Venkov, thanks for the info.
Hi Tom,
FMEObjects also has a .NET API, which can be used within the IronPython, instead of the Python API.
As an illustration, the following can be used to read a text file into Dynamo:
import sys
sys.path.append('C:\\Program Files\\FME 2018.0 x64')
import clr
clr.AddReference('ProtoGeometry')
clr.AddReferenceToFile('FMEObjectsDotNet4.dll')
from Autodesk.DesignScript.Geometry import *
from Safe.FMEObjects import *
from System.Collections.Specialized import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
session = FMEObjects.CreateSession()
sparams = StringCollection()
sparams.Add('FME_DEBUG')
sparams.Add('DUMP_CONFIG')
session.Init(sparams)
reader = session.CreateReader('TEXTLINE', False, None)
rparams = StringCollection()
rparams.Add('DATASET')
rparams.Add('c:\\test\\test.txt')
reader.Open('c:\\test\\test.txt', rparams)
outlist = []
feature = session.CreateFeature()
more = reader.Read(feature)
while more:
line = feature.GetStringAttribute('text_line_data')
outlist.append(line)
feature = session.CreateFeature()
more = reader.Read(feature)
#Assign your output to the OUT variable.
OUT = outlist
4 Likes
This is great thanks Dave, thanks for pointing me to this. I can make some pretty cool workflows now!
I have created a custom node to read table data through FME, and am working right now on one to read geometry. I can send you the table reader .dyf if you would like to try it out, and give me feedback.