Select to view content in your preferred language

cut & paste annotations

2220
28
09-06-2013 05:39 AM
MikeYoung5
New Contributor
Can Python be used to cut & paste Annotations?  I have read through arcpy.CopyFeatures_management and arcpy.Copy_management ESRI help docs.  I have been unable to find anything that mentions cut & paste Annotations.
Tags (2)
0 Kudos
28 Replies
markdenil
Regular Contributor II
What do you mean by "cut & paste annotations"?
Copy Features respects feature selections on layers....
0 Kudos
MikeYoung5
New Contributor
What do you mean by "cut & paste annotations"?
Copy Features respects feature selections on layers....


I want to cut and paste from one annotation layer to another.  Basically, I want the same functionality as the cut & paste buttons from the standard toolbar.

import arcpy

mxd = arcpy.mapping.MapDocument ("CURRENT")
df = arcpy.mapping.ListDataFrames (mxd)[0]
pa = arcpy.mapping.ListLayers(mxd, "PropertyAnno", df)[0]
oa = arcpy.mapping.ListLayers(mxd, "OwnerAnno", df)[0]
arcpy.AddMessage(pa.name)
arcpy.AddMessage(oa.name)

arcpy.CopyFeatures_management(pa, oa)

An ExecuteError is thrown.  ExecuteError: Failed to execute.  Parameters are not valid.  ERROR 840: The value is not a Feature Class.
0 Kudos
MikeYoung5
New Contributor
Does anyone have a suggestion on how to fix the CopyFeatures_management statement?  The input and outputs are specified.  What else is missing?  Also, I am using Feature Classes instead of layers.
0 Kudos
markdenil
Regular Contributor II
The output of CopyFeatures is a feature class, not a layer.

oa is a layer, not a Feature Class.
0 Kudos
MikeYoung5
New Contributor
The output of CopyFeatures is a feature class, not a layer.

oa is a layer, not a Feature Class.


Mark,

How is oa not a Feature Class?  ArcCatalog and  ArcMap list the Data Type as a File Geodatabase Feature Class.
0 Kudos
RichardFairhurst
MVP Honored Contributor
Mark,

How is oa not a Feature Class?  ArcCatalog and  ArcMap list the Data Type as a File Geodatabase Feature Class.


The feature layer at its core is a feature class, but the layer itself is on top of that and is a Desktop display wrapper that defines its output location as a layer designed for placement in a map dataframe, not as a feature class file in a directory.  This geoprocessing tool cannot use the layer wrapper that hides the feature class information from the tool.

That is why when you interactively complete the tool you cannot drag a layer into the output text box of the CopyFeatures tool or type a layer name into the output of the tool.  You have to navigate directories to fill in that part of the tool dialog with a full feature class path or you must only connect raw feature class variables or tool outputs that store direct pointers to a feature class path.  Layers are only an indirect pointer to a feature class, not a direct pointer.

Although many people use the term layer indiscriminately to refer to both what you see in the TOC of a Desktop map and the underlying data in ArcCatalog, technically the term is actually only correctly used to refer to what you see in a Desktop map TOC.  The data stored on disk seen in ArcCatalog is only a feature class that has its own independent existence even if it was never used to create a layer in a Desktop map TOC.  Likewise, layers can exist without a feature class (when a layer has a red exclamation mark due to a lost data connection it is still a layer even though it has no feature class and virtually no real functionality).
0 Kudos
MikeYoung5
New Contributor
The feature layer at its core is a feature class, but the layer itself is on top of that and is a Desktop display wrapper that defines its output location as a layer designed for placement in a map dataframe, not as a feature class file in a directory.  This geoprocessing tool cannot use the layer wrapper that hides the feature class information from the tool.

That is why when you interactively complete the tool you cannot drag a layer into the output text box of the CopyFeatures tool or type a layer name into the output of the tool.  You have to navigate directories to fill in that part of the tool dialog with a full feature class path or you must only connect raw feature class variables or tool outputs that store direct pointers to a feature class path.  Layers are only an indirect pointer to a feature class, not a direct pointer.

Although many people use the term layer indiscriminately to refer to both what you see in the TOC of a Desktop map and the underlying data in ArcCatalog, technically the term is actually only correctly used to refer to what you see in a Desktop map TOC.  The data stored on disk seen in ArcCatalog is only a feature class that has its own independent existence even if it was never used to create a layer in a Desktop map TOC.  Likewise, layers can exist without a feature class (when a layer has a red exclamation mark due to a lost data connection it is still a layer even though it has no feature class and virtually no real functionality).


Layers can refer to anything with the ArcMap TOC (as you mention) and files with the .lyr extension. 

Your logic makes sense.  For a tool to run, the input and output folder locations are required.

Therefore, once the environment is set, an error is still returned saying pa does not exist or is not supported.  Only one environment is set, since the input and output locations are the same, and the file names remain the same(both are stored within the same File Geodatabase).  Is the issue with overwriting the output file?
0 Kudos
MikeYoung5
New Contributor
I am confused as to why the script does not work.  I believe something is wrong my CopyFeatures_management statement.

import arcpy

arcpy.env.workSpace = "C:\Working\MyData\Python.gdb"
arcpy.env.overwriteOutput = 'True'

mxd = arcpy.mapping.MapDocument ("CURRENT") 
df = arcpy.mapping.ListDataFrames (mxd)[0] 
pa = arcpy.mapping.ListLayers(mxd, "PropertyAnno", df)[0]
oa = arcpy.mapping.ListLayers(mxd, "OwnerAnno", df)[0]
arcpy.AddMessage(pa.name)
arcpy.AddMessage(oa.name)

arcpy.CopyFeatures_management("pa", "oa")


Yet, if I write a basic script the CopyFeatures_management works.  I only want to copy selected features & paste into an existing Feature Class, not create a new Feature Class.

import arcpy
try:
    arcpy.env.workspace = "C:\Working\MyData\Python.gdb"

    arcpy.CopyFeatures_management("HomeValue", "Test")
except:
    print arcpy.GetMessages()
0 Kudos
markdenil
Regular Contributor II
pa = arcpy.mapping.ListLayers(mxd, "PropertyAnno", df)[0]
#      pa is the input: it is a layer in arcMap. 
#      Copy Features accepts a layer as input, 
#      so you can have selected or query defined subsets of the FC features

oa = arcpy.mapping.ListLayers(mxd, "OwnerAnno", df)[0]
#      oa is supposed to be the output: it is a layer in arcMap. 
#      Copy Features cannot accept a layer as output; it must write to a fc on disc
#      since the oa layer is in your open ArcMap session, the underlying FC is locked
#      so you cannot write to the underlyng FC either

fc = r"C:\Working\MyData\Python.gdb\AnAnnotationFC"
#      fc is an annotation FC in the same gdb, but is NOT in the open mxd
#      try writing to that


arcpy.CopyFeatures_management(pa, fc)
0 Kudos