Skip to main content
Question

startup python script

  • February 19, 2013
  • 3 replies
  • 30 views

Forum|alt.badge.img
Hi,

 

 

I am using FME 2012 and would like to write a startup python script in which I can import a python module and call that module's function. I used to be able to do this with pyfme but with FME 2012 I have to use fmeobjects and it throws an error when I do. Two simple test cases below.

 

 

What might be causing the error? Looks like when I import the custom module, fmeobjects is not getting recognized.

 

 

Embedded script (works):

 

import fmeobjects

 

 

def audit_start():

 

    logger = fmeobjects.FMELogFile()

 

    logger.logMessageString("audit_start()")

 

    for name,val in FME_MacroValues.iteritems():

 

        logger.logMessageString( "   %s:%s" %(name,val))

audit_start()

 

 

Imported script (error):

 

import audit

 

audit.audit_start()

audit.py

 

import fmeobjects

 

 

def audit_start():

 

    logger = fmeobjects.FMELogFile()

 

    logger.logMessageString("audit_start()")

 

    for name,val in FME_MacroValues.iteritems():

 

        logger.log( "   %s:%s" %(name,val))

 

 

Error: Python Exception <NameError>: global name 'FME_MacroValues' is not defined

3 replies

Forum|alt.badge.img
  • Author
  • February 19, 2013
Solved. __main__ namespace have to be imported:

 

 

import __main__

 

import fmeobjects

 

 

def audit_start():

 

    logger = fmeobjects.FMELogFile()

 

    logger.logMessageString("audit_start()")

 

    for name,val in __main__.FME_MacroValues.iteritems():

 

        logger.log( "   %s:%s" %(name,val))

 

 

 


mark2atsafe
Safer
Forum|alt.badge.img+45
  • Safer
  • February 20, 2013
Just to mention, pyfme was replaced in FME2012 to solve a bunch of problems and improve our Python support. You can find more details at:

 

 

http://fmepedia.safe.com/articles/How_To/New-Python-FME-Objects-API-in-FME-2012

david_r
Celebrity
  • February 22, 2013
Another suggestion would be to add the log file object and the FME_MacroValues dictionary as a parameter to audit_start(), e.g.:

 

 

In the workspace

 

import audit

 

audit.audit_start(fmeobjects.FMELogFile(), FME_MacroValues)

 

 

In audit.py

 

def audit_start(myFMELogger, myMacroValues):

 

    myFMELogger.logMessageString("audit_start()")

 

    for name,val in myMacroValues.iteritems():

 

        myFMELogger.log( "   %s:%s" %(name,val))

 

 

I would consider this a slightly better approach as the coupling between FME (the caller) and your external script is less tight.

 

 

David

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings