+ Reply to Thread
Results 1 to 5 of 5

Thread: array.removeAll()

  1. #1
    Michael Fedak
    Join Date
    Jan 2011
    Posts
    6
    Points
    0
    Answers Provided
    0


    0

    Default array.removeAll()

    I have an Array object I would like to clear using array.removeAll() however I keep getting the error:
    Code:
    <type 'exceptions.TypeError'>: unbound method removeAll() must be called with Array instance as first argument (got nothing instead)
    

  2. #2
    Jason Scheirer

    Join Date
    Oct 2009
    Posts
    516
    Points
    494
    Answers Provided
    69


    0

    Default Re: array.removeAll()

    Could you paste a larger code snippet for context?

  3. #3
    Michael Fedak
    Join Date
    Jan 2011
    Posts
    6
    Points
    0
    Answers Provided
    0


    0

    Default Re: array.removeAll()

    Sorry, here is the code till the line where it fails. I based it on the fourth example here: http://help.arcgis.com/en/arcgisdesk...0000003000000/
    Code:
    import arcpy,os
    #Declare Variables
    mxd = arcpy.GetParameter(0)
    outLocation = arcpy.GetParameterAsText(1)
    outName= arcpy.GetParameterAsText(2)+".shp"
    outPath = os.path.join(outLocation,outName)
    featureList = []
    ar=arcpy.Array
    
    #Export the table values to a string
    maps=mxd.exportToString()
    #Remove field delimiters
    maps = maps.replace("'",'').strip()
    arcpy.AddMessage(maps)
    maplist= maps.split(';')
    arcpy.AddMessage(maplist)
    
    #Cycle through list of maps
    
    for mapp in maplist:	
    	
    	arcpy.AddMessage(mapp)
    	mxd1 = arcpy.mapping.MapDocument(mapp)
    	
    	frames = arcpy.mapping.ListDataFrames(mxd1)
    	
    	#Cycle through the list
    	for df in frames:		
    		#Creates a polygon object 
    		poly = arcpy.Polygon(ar([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]),
    									df.spatialReference)									
    		featureList.append(poly)
    		
    		#Remove the array for the next polygon 
    		ar.removeAll(ar)

  4. #4
    Jason Scheirer

    Join Date
    Oct 2009
    Posts
    516
    Points
    494
    Answers Provided
    69


    0

    Default Re: array.removeAll()

    You don't need to clear it out each time the way you are, each instance of Array is a stand-alone object:

    Code:
    for df in frames:		
    		#Creates a polygon object 
    		poly = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]),
    									df.spatialReference)									
    		featureList.append(poly)
                    # All done

  5. #5
    Michael Fedak
    Join Date
    Jan 2011
    Posts
    6
    Points
    0
    Answers Provided
    0


    0

    Default Re: array.removeAll()

    Excellent, thank you.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts