Select to view content in your preferred language

Script tool feature set problem in ArcGIS 10.1

1574
6
Jump to solution
12-14-2012 04:30 AM
MichelleConvey
Deactivated User
[ATTACH=CONFIG]19937[/ATTACH]Hi there,
We are upgrading from 10 to 10.1 at the moment and I have a script tool in a toolbox that allows the user to click on the map, fill in some details and create a map based on the settings held in the mxd.  This involves using a feature set, with the schema being specified in the parameters of the script tool and works fine in ArcGIS 10. 

I have since tried to run it in 10.1 and it would appear as though my schema is not being recognised and the screen looks like the attached so no attribute data can be recorded.

My script that worked in 10 is below and I cannot see what I would need to change to get it to work in 10.1. 

Any help would be greatly appreciated!

Cheers,
Michelle


# AUTOMATING LIVEBOARD MAPS FOR COURT  # Author: M.Convey - 20.01.2012     # Versions: ArcGIS 10.  Python 2.6      # Python script to allow the automatic production of a liveaboard map for the Enforcement team # The user clicks on the script / button and then clicks on the map at the point at which their boat is # The user then completes the attributes presented to them: Boat name, index number, canal, nearest town # After the user has then selected where to save the PDF, clicking GO will begin the script # Changes should not be saved   # Import arcpy module import arcpy  # Load required toolboxes arcpy.ImportToolbox("G:/GIS_Admin/zNamed_folders/Michelle/Projects/Enforcement/Enforcement_10.tbx")  # Workspace arcpy.env.Workspace = r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb" wsp = arcpy.env.Workspace  # Overwrite Output arcpy.env.overwriteOutput = True  # Sets the mxd to the one currently in use mapDoc = arcpy.mapping.MapDocument("CURRENT")  # Parameters LiveaboardBoats = r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb\LiveaboardBoats" LiveaboardBoatsCopy = r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb\LiveaboardBoatsCopy" lyr = r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Boat Location.lyr"  # Append the new liveboard to the 'master' copy of the boats so that have a record arcpy.Append_management(LiveaboardBoatsCopy, LiveaboardBoats)  # Script arguments # This worked fine in 10: Feature_Set = arcpy.GetParameterAsText(0) if Feature_Set == '#' or not Feature_Set:     Feature_Set = "in_memory\\{475E88CB-9AAC-48ED-B772-D04A526AD1F6}" # provide a default value if unspecified   # Get pdf file path to create outputPDFPath = arcpy.GetParameterAsText(1) if outputPDFPath == '#' or not outputPDFPath:     arcpy.AddError("Cannot proceed without specifying an output path for the pdf file")     #return      # Copy the feature set to the temporary holding feature class arcpy.CopyFeatures_management (Feature_Set, LiveaboardBoatsCopy)  # Fix broken data sources that arise when copy (?) for lyr in arcpy.mapping.ListBrokenDataSources(mapDoc):     if lyr.supports("DATASOURCE"):         if lyr.dataSource == r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb\LiveaboardBoatsCopy":             lyr.replaceDataSource(r"G:\_Directorate\Marketing\Enforcement\Liveaboard Maps\Liveaboard_Arc10.mdb", "ACCESS_WORKSPACE", "LiveaboardBoatsCopy")             lyr.name = "LiveaboardBoatsCopy"  # Do other mapp based stuff here...  # Refresh active view arcpy.RefreshActiveView()  # Export arcpy.AddMessage("  Saving as PDF") arcpy.mapping.ExportToPDF(mapDoc,outputPDFPath)  del mapDoc
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KevinHibma
Esri Regular Contributor
Are you saying the problem is : you need to associate attributes with the point you click on the map?
Feature Sets at 10.1 are now based entirely off of Feature Templates (what you'd set up when performing edits).
You can set default symbologies and attributes for your input features.
Since you've shown in the tool dialog a point that says something along the lines of "click a point on the map".. its initializing the feature set correctly. If its a matter of getting those attributes into the point feature, you have a few choices:
a) right click on the point feature and supply values. Any point you click on the map will then be populated with those defaults
b) after creating features, right click on the layer in the ToC and open the attribute table and fill in the details.

I'd give a quick read of this quick tour of FS help topic. As well as setting the schema (more information about feature templates on this page).

View solution in original post

0 Kudos
6 Replies
T__WayneWhitley
Honored Contributor
I think you are saying that you cannot even get to the point where you launch the tool because the script window interface must initialize from a location you pick on the map, is that correct?  You said this is a script tool, not an add-in.

If that's the situation, then I think it's the initialization that is going a little awry, not the script you have attached that runs when you run the tool... if I'm on the right track, there may be some code that misfires in the ToolValidator class - can you please send that code?
You'll find it if you'll right-click on the script tool and select 'properties', then go to the 'Validation' tab.  If there is custom code loaded there, can you copy and paste it here?

The ToolValidator class contains the function definitions below (the below shows the default [v. 10 and at 10.1 the class may be modified], essentially adding no custom tool behavior):
class ToolValidator:
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""
 
  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    import arcpy
    self.params = arcpy.GetParameterInfo()

  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    return
 
  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parmater
    has been changed."""
    return
 
  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return


EDIT:  If you're interested, here is one of the 10.1 help references on the ToolValidator:

Customizing script tool behavior
Desktop » Geoprocessing » Creating tools » Creating tools with Python » Creating script tools in a custom toolbox
http://resources.arcgis.com/en/help/main/10.1/index.html#//00150000000t000000
0 Kudos
MichelleConvey
Deactivated User
Hi Wayne,

Thanks for your prompt reply.  I will have a look at the link you sent over the weekend.

In the meantime, I have included the code below as you suggested and it does look like it is the equivalent of the default.  Do you know what I may be missing from here?

Thanks!


class ToolValidator:
  """Class for validating a tool's parameter values and controlling
  the behavior of the tool's dialog."""

  def __init__(self):
    """Setup arcpy and the list of tool parameters."""
    import arcpy
    self.params = arcpy.GetParameterInfo()

  def initializeParameters(self):
    """Refine the properties of a tool's parameters.  This method is
    called when the tool is opened."""
    return

  def updateParameters(self):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parmater
    has been changed."""
    return

  def updateMessages(self):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return
0 Kudos
T__WayneWhitley
Honored Contributor
OK, then that isn't it.  Good though to eliminate that as a potential source of the problem.  Now to look closer at the script -- so you are having problems after you launch the tool, right?  So what error messages are being returned, if any?  (you may have to go to your Results window and get those msgs)

EDIT:  Ah, I think I see what's going on - your feature set isn't getting 'read' properly when you start your tool --- it's supposed to be geared to run from what you have selected, isn't that correct?  So I would start with looking at you tool's input parameters and make sure it is set properly - could be it was inadvertently dropped when you migrated to 10.1.  If you want, any way you could zip and attach just the toolbox this tool resides in?  I may not be able to open it (I have 10) but maybe I can just look at your script tool param settings.

Just saw Kevin Hibma's post below - that sounds like your problem!
0 Kudos
KevinHibma
Esri Regular Contributor
Are you saying the problem is : you need to associate attributes with the point you click on the map?
Feature Sets at 10.1 are now based entirely off of Feature Templates (what you'd set up when performing edits).
You can set default symbologies and attributes for your input features.
Since you've shown in the tool dialog a point that says something along the lines of "click a point on the map".. its initializing the feature set correctly. If its a matter of getting those attributes into the point feature, you have a few choices:
a) right click on the point feature and supply values. Any point you click on the map will then be populated with those defaults
b) after creating features, right click on the layer in the ToC and open the attribute table and fill in the details.

I'd give a quick read of this quick tour of FS help topic. As well as setting the schema (more information about feature templates on this page).
0 Kudos
MichelleConvey
Deactivated User
Hi Kevin & Wayne,

I hadn't appreciated the reliance on the feature templates and the way in which the users would need to interact in order to update attributes so thanks very much for that.

I have added in a couple of string variables and an update cursor as this will be the most appropriate method for my users and am happy with that so thanks once again for your time.

Cheers,
Michelle
0 Kudos
GeoNZ
by
Frequent Contributor

This is a bug though. Even with tools supplied by ESRI (i.e. Terrain Profile tool), the feature template will work the first time and allow you to draw a line as input. However, any subsequent times after saving the mxd and re-opening it, instead of the draw tool, the select tool will show.

The only way around it, is to copy all layers to a new mxd and re-run the tool....of course this means that you loose a lot of information.

Pretty frustrating to be honest.

0 Kudos