Select to view content in your preferred language

Add DBF to ArcMap After Python Script Finishes

461
4
06-12-2012 12:34 PM
BryanDeverot1
New Contributor
I have script that does everything I want, except that I create two pivot tables...  I want these two dbf tables to automatically be added to ArcMap after the script runs.  Is it arcpy.MakeTableView_management?  For feature classes I used MakeFeatureLayer and the ApplySymbology... but can't seem to find anything for DBF tables

Thanks!
Tags (2)
0 Kudos
4 Replies
VikramS
Occasional Contributor
arcpy.SetParameterasText(TableName) .I guess that should work ..

Or else make maketableview that should add the table to the TOC
0 Kudos
JoelCalhoun
New Contributor III
Bryan,

For feature classes I've used AddLayer or InsertLayer.  I'm not sure if they work with tables though.

Using MakeTableView might work but it only creates a temporary version that will not persist if you do not save your mxd.

One thought if MakeTableView isn't your best option and you always use the same .mdx is to simply add the tables manually the first time and then save your .mxd.
From then on when the script finishes simply replace your tables datasources with the new tables.
 
This is from the Updating and fixing data sources with arcpy.mapping help:

TableView.replaceDataSource(workspace_path, workspace_type, dataset_name, {validate})
The replaceDataSource method on the TableView object is similar to the findAndReplaceWorkspacePath method, but in addition to being able to change a workspace type, the dataset can also be changed. This is the only method that enables you to replace a table's dataset within a workspace. This is especially useful when the name of a dataset is different in the new workspace.



Joel
0 Kudos
JoelCalhoun
New Contributor III
Bryan,

It looks like at 10.1 there is an AddTableView.


Joel
0 Kudos
curtvprice
MVP Esteemed Contributor
I have script that does everything I want, except that I create two pivot tables...  I want these two dbf tables to automatically be added to ArcMap after the script runs.  Is it arcpy.MakeTableView_management?  For feature classes I used MakeFeatureLayer and the ApplySymbology... but can't seem to find anything for DBF tables


If you set up the output table names as parameters of type Output, they will appear in the ArcMap TOC when the tool completes. If you want full control over the names and locations of these tables, you can set the parameter type to Derived, which means they don't appear in the tool dialog -- but you have to set the paths into the parameters with SetParameterAsText().

Here's the relevant help article: Setting script tool parameters
0 Kudos