Skip to main content

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 = {} 
    parameterst'Book'] = Prod_gdb + "\\" + "Book" 
    parametersa'Span'] = Prod_gdb + "\\" + "Span" 
    parametersi'CRP_Splice'] = Prod_gdb + "\\" + "CRP_Splice" 
    parametersc'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" 
    parametersn'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" 
    parameterso'Pole'] = Prod_gdb + "\\" + "POLE" 
    parametersr'Riser'] = Prod_gdb + "\\" + "RISER" 
    parameterst'ROW_Lines'] = Prod_gdb + "\\" + "ROW_Lines" 
    parameters"'Slackloop'] = Prod_gdb + "\\" + "SLACKLOOP" 
    parametersr'Utility_Infra_Lines'] = Prod_gdb + "\\" + "utility_infrastructure_lines" 
    parametersP'SimpleLineDem'] = Prod_gdb + "\\" + "Simple_Dimension_Lines" 
    parametersb'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()i2] 
    tbinfo = traceback.format_tb(tb)e0] 
    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)

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