Select to view content in your preferred language

I Want to delete some text element but my script is not working

2627
4
Jump to solution
10-02-2013 09:20 AM
OLANIYANOLAKUNLE
Frequent Contributor
I created some text element by cloning the original text element, I intend to delete all the cloned text elements after using them but after running my script it does not work at all, any suggestions. The cloned text elements are named Table Text_clone1, Table text_clone2 etc, see my code below


>>> mxd = arcpy.mapping.MapDocument("Current") >>> tableText = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TableText")[0] >>> for elm in arcpy.mapping.ListLayoutElements(mxd, wildcard="_clone"): ...     elm.delete() ... 
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MattSayler
Frequent Contributor
Think I figured it out. Wildcard needs a wildcard:
mxd = arcpy.mapping.MapDocument("Current") tableText = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TableText")[0] for elm in arcpy.mapping.ListLayoutElements(mxd, wildcard="*_clone"):     print elm.name #just to double check you're actually getting results in the list     elm.delete()

View solution in original post

0 Kudos
4 Replies
MattSayler
Frequent Contributor
What version of ArcGIS are you on (10.0 and under don't have the delete() method)?
0 Kudos
OLANIYANOLAKUNLE
Frequent Contributor
What version of ArcGIS are you on (10.0 and under don't have the delete() method)?


Version 10.1
0 Kudos
MattSayler
Frequent Contributor
Think I figured it out. Wildcard needs a wildcard:
mxd = arcpy.mapping.MapDocument("Current") tableText = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TableText")[0] for elm in arcpy.mapping.ListLayoutElements(mxd, wildcard="*_clone"):     print elm.name #just to double check you're actually getting results in the list     elm.delete()
0 Kudos
OLANIYANOLAKUNLE
Frequent Contributor
Think I figured it out. Wildcard needs a wildcard:
mxd = arcpy.mapping.MapDocument("Current")
tableText = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TableText")[0]
for elm in arcpy.mapping.ListLayoutElements(mxd, wildcard="*_clone"):
    print elm.name #just to double check you're actually getting results in the list
    elm.delete()


Thanks it worked perfectly!!! Although i added an extra *
for elm in arcpy.mapping.ListLayoutElements(mxd, wildcard="*_clone*"):
0 Kudos