2

I want to create a Python Script for ArcGIS, using arcpy. The script would have several user input fields. I would like to create a table based on one or two of the user input (the path and name). I am trying :

import arcpy
import os
from arcpy import env
from arcpy.management import CreateFeatureclass
workspace = arcpy.GetParameterAsText(0)
poly = arcpy.GetParameterAsText(1)
poly_nou = arcpy.GetParameterAsText(2)
input_areas = arcpy.GetParameterAsText(3)
direction = arcpy.GetParameterAsText(4)
env.workspace = workspace
out_path = os.path.split(poly_nou)[0]
name = os.path.split(poly_nou)[1]
arcpy.CreateTable(out_path, name)

I have set up the Script in ArcMap to look like this: 1. Workspace type 2. Feature class 3. Table 4 and 5 Strings

I want the script to read 3 (possibly also 1) and create a table.

I get the error:

Traceback (most recent call last): File "C:\Users\user\Documents\Proiecte\Python Toolbox\Divide_percentage.py", line 16, in arcpy.CreateTable(out_path, name) AttributeError: 'module' object has no attribute 'CreateTable' Failed to execute (Script1).

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Apr 5, 2020 at 13:09

2 Answers 2

4

There are two ways to run a geoprocessing tool using Python.

  1. To use its corresponding function.

    arcpy.<toolname_toolboxalias>(parameters)
    
  2. To call the toolbox as a module and then the tool as a function. Geoprocessing tools are also available in modules that match the toolbox alias name. The syntax is as follows:

    arcpy.<toolboxalias>.<toolname>(parameters)
    

Since CreateTable table is in management toolbox, you should use one of the following lines:

arcpy.CreateTable_management(out_path, name)
# OR
arcpy.management.CreateTable(out_path, name)
answered Apr 5, 2020 at 14:19
3

A classic case of time to read the help file! If you go to the Create Table tool, in fact any geoprocessing tools' help page, you see a syntax section and a code example of how to use the tool in python. Have a look at that then your line of code that creates the table, what is missing...?

answered Apr 5, 2020 at 14:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.