2

Currently I try to improve an ArcPy script which is run outside ArcGIS Pro 2.5 in Spyder.

I want to write a table to memory using the Table to Table tool. This tool is placed inside a loop and writes a new table to my workspace for every run.

Part of my code:

#Defining output path
output = "Routebestand_portaal_"+str(nummer_portaal)+"_selectie"
portalen_join_met_totaal = arcpy.AddJoin_management(in_layer_or_view="Routebestand_200605_totaalbestand_opgeschoond_copy",
                                                in_field="Portal_OBJECTID", join_table=Portaal_vultabel,
                                                join_field="Portal_OBJECTID", join_type="KEEP_COMMON")[0]

Portaal_vultabel = r"C:\Users\Work\Portalen_met_intensiteit"

#Write table to gdb
arcpy.TableToTable_conversion(in_rows=portalen_join_met_totaal, out_name= output, where_clause="", field_mapping="Van___naar \"Van___naar\" true true false 200 Text 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.Van___naar,0,200;VTGKM_VWH \"VTGKM_VWH\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.VTGKM_VWH,-1,-1;Portal_OBJECTID \"Portal_OBJECTID\" true true false 4 Long 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.Portal_OBJECTID,-1,-1;SUM_VTGKM_TOT \"SUM_VTGKM_TOT\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Portalen_met_intensiteit.SUM_VTGKM_TOT,-1,-1;SUM_VTGKM_VWH \"SUM_VTGKM_VWH\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Portalen_met_intensiteit.SUM_VTGKM_VWH,-1,-1", config_keyword="")[0]

..this code works and writes the table to my workspace. Now I want to write the table to memory.


My first approach was figure out how to write a table to memory outside a loop and without considering the variable output:

#Approach1  - using 'memory'
output1 = r"memory\tmpTable"     
portalen_join_met_totaal = arcpy.AddJoin_management(in_layer_or_view="Routebestand_200605_totaalbestand_opgeschoond_copy",
                                                in_field="Portal_OBJECTID", join_table=Portaal_vultabel,
                                                join_field="Portal_OBJECTID", join_type="KEEP_COMMON")[0]

Portaal_vultabel = r"C:\Users\Work\Portalen_met_intensiteit"           

arcpy.TableToTable_conversion(in_rows=portalen_join_met_totaal, out_name= output1, where_clause="", field_mapping="Van___naar \"Van___naar\" true true false 200 Text 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.Van___naar,0,200;VTGKM_VWH \"VTGKM_VWH\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.VTGKM_VWH,-1,-1;Portal_OBJECTID \"Portal_OBJECTID\" true true false 4 Long 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.Portal_OBJECTID,-1,-1;SUM_VTGKM_TOT \"SUM_VTGKM_TOT\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Portalen_met_intensiteit.SUM_VTGKM_TOT,-1,-1;SUM_VTGKM_VWH \"SUM_VTGKM_VWH\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Portalen_met_intensiteit.SUM_VTGKM_VWH,-1,-1", config_keyword="")[0]

..or these lines:

#Approach2 - using 'in_memory'
output2 = r"in_memory\tmpTable"
portalen_join_met_totaal = arcpy.AddJoin_management(in_layer_or_view="Routebestand_200605_totaalbestand_opgeschoond_copy",
                                                in_field="Portal_OBJECTID", join_table=Portaal_vultabel,
                                                join_field="Portal_OBJECTID", join_type="KEEP_COMMON")[0]

Portaal_vultabel = r"C:\Users\Work\Portalen_met_intensiteit"

arcpy.TableToTable_conversion(in_rows=portalen_join_met_totaal, out_name= output2, where_clause="", field_mapping="Van___naar \"Van___naar\" true true false 200 Text 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.Van___naar,0,200;VTGKM_VWH \"VTGKM_VWH\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.VTGKM_VWH,-1,-1;Portal_OBJECTID \"Portal_OBJECTID\" true true false 4 Long 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Routebestand_200605_totaalbestand_opgeschoond_copy.Portal_OBJECTID,-1,-1;SUM_VTGKM_TOT \"SUM_VTGKM_TOT\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Portalen_met_intensiteit.SUM_VTGKM_TOT,-1,-1;SUM_VTGKM_VWH \"SUM_VTGKM_VWH\" true true false 8 Double 0 0,First,#,C:\\Users\\Work\\Data.gdb\\Routebestand_200605_totaalbestand_opgeschoond_copy,Portalen_met_intensiteit.SUM_VTGKM_VWH,-1,-1", config_keyword="")[0]

..both the options delivered an error message:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000354: The name contains invalid characters
Failed to execute (TableToTable).

What I would like to get is something like r"memory\ + "Routebestand_portaal_" + str(nummer_portaal) + "_selectie"

Any suggestions how to solve this?

0
5

Per the tool documentation, Table to Table is setup with an output location and an output name parameter. As you're using it right now, you're trying to pass both the path and name in a single parameter.

Try something like:

arcpy.TableToTable_conversion("vegtable.dbf", "memory", "vegtable")

or in your case

# output2 = just the output name, not the path
arcpy.TableToTable_conversion(in_rows=portalen_join_met_totaal, out_path="memory", out_name= output2, where_clause="", ......
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.