Question

passing an instance of a portal to an FME workspace as a parameter in the RunWorkspace.py.

  • 23 September 2019
  • 1 reply
  • 2 views

I am trying to run a workspace from a python script. I need to pass the portal as a parameter for the workspace. The workspace reads the new portal and then saves a copy to a gdb. I can not find any documentation or examples on how to write the syntax or what syntax is needed to get the workspace to recognize the portal. If anyone knows how to do this, it would be a huge relief.

 

# ============================================================================ 

# Name : RunWorkspace.py 

# Purpose : FMEPedia Sample of FMEWorkspaceRunner 

# Author               Date            Changes made 
# ------------------   ------------    ------------------------------- 
# Ken Bragg           July 15th, 2014   Original Definition 


# Note: # The path to fmeobjects must by in your python path so you may need something like this: 
import sys 
sys.path.append(r"C:\Program Files\FME\fmeobjects\python27") 
import fmeobjects 
import arcpy
import traceback 

try: 
    # initiate FMEWorkspaceRunner Class runner = fmeobjects.FMEWorkspaceRunner()
    arcpy.env.overwriteOutput = True
# Full path to Workspace, example comes from the FME 2014 Training Full Dataset 
    workspace = r'C:\Users\BB0322\Desktop\Projects\Redline Strip Maps\Reference\FME\GetData4AsBuilt.fmw' 
# Set workspace parameters by creating a dictionary of name value pairs 
    Prod_gdb = r"C:\Users\BB0322\Desktop\Projects\Redline Strip Maps\Stripmaps\StripMap_1710AIAK_3\PROD_DATA.gdb" 
    route = r"C:\Users\BB0322\Desktop\Projects\Redline Strip Maps\Stripmaps\StripMap_1710AIAK_3\Map_Data.gdb\RT1710AIAK_3" 
    portal = "https://fed.3-gislive.com/arcgis/rest/services/KansasCity/KansasCity_UDM_Data_Extraction_Model/FeatureServer" 
    parameters = {} 
    parameters['Book'] = Prod_gdb + "\\" + "Book" 
    parameters['Span'] = Prod_gdb + "\\" + "Span" 
    parameters['CRP_Splice'] = Prod_gdb + "\\" + "CRP_Splice" 
    parameters['FiberCable'] = Prod_gdb + "\\" + "FiberCable" 
    parameters['Cons_redline_Points'] = Prod_gdb + "\\" + "Construction_Redline_Points" 
    parameters['Route'] = route parameters['Streets'] = Prod_gdb + "\\" + "Streets" 
    parameters['Admin_Bound'] = Prod_gdb + "\\" + "Admin_Boundary" 
    parameters['CityLimits'] = Prod_gdb + "\\" + "CityLimits" 
    parameters['Demand_Points'] = Prod_gdb + "\\" + "Demand_Points" 
    parameters['Site_Span_Bound'] = Prod_gdb + "\\" + "site_span_nfid_boundaries" 
    parameters['Structure'] = Prod_gdb + "\\" + "STRUCTURE" 
    parameters['SpliceClosure'] = Prod_gdb + "\\" + "SPLICECLOSURE" 
    parameters['Pole'] = Prod_gdb + "\\" + "POLE" 
    parameters['Riser'] = Prod_gdb + "\\" + "RISER" 
    parameters['ROW_Lines'] = Prod_gdb + "\\" + "ROW_Lines" 
    parameters['Slackloop'] = Prod_gdb + "\\" + "SLACKLOOP" 
    parameters['Utility_Infra_Lines'] = Prod_gdb + "\\" + "utility_infrastructure_lines" 
    parameters['SimpleLineDem'] = Prod_gdb + "\\" + "Simple_Dimension_Lines" 
    parameters['portal'] = portal 
# Use Try so we can get FME Exception 
    try: 
# Run Workspace with parameters set in above dictionary 
        runner.runWithParameters(workspace, parameters) 
# Or use promtRun to prompt for published parameters 
# runner.promptRun(workspace) 
    except fmeobjects.FMEException as ex: 
# Print out FME Exception if worskspace failed 
        print ex.message 
        arcpy.AddMessage(ex.message) 
    else: 
# Tell user the workspace ran 
        print('The Workspace: ' + workspace) 
        print('...ran successfully') 
        arcpy.AddMessage("The Workspace: " + workspace) 
        arcpy.AddMessage("...ran Successfully") 
# get rid of FMEWorkspace runner so we don't leave an FME process running 
    runner = None 
except: 
    tb = sys.exc_info()[2] 
    tbinfo = traceback.format_tb(tb)[0] 
    pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_type) + ": " + str(sys.exc_value) + "\n" 
    msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n" 

    arcpy.AddError(msgs) 
    arcpy.AddError(pymsg) 
    print msgs 
    print pymsg 

    arcpy.AddMessage(arcpy.GetMessages(1)) 
    print arcpy.GetMessages(1)

1 reply

Badge +3

I am not really answering the question, but merely providing some ideas:

It looks like most of your parameters are just dependent on "Prod_gdb", so why not code those as private parameters, to make calling the workspace a lot simpler.

Even if you cannot or don't want to edit the original workspace, you might consider creating another workspace in FME with a WorkspaceRunner calling the original one, and defining as many parameters as private parameters. After that you call that wrapper workspace from arcpy.

Maybe the "portal" parameter can be also be set as private in the wrapper workspace, so it's no longer an issue in arcpy?

Reply