+ Reply to Thread
Results 1 to 3 of 3

Thread: inserting text in map layout

  1. #1
    Daniel Abera
    Join Date
    Nov 2010
    Posts
    20
    Points
    0
    Answers Provided
    1


    0

    Default inserting text in map layout

    Hi Guys,

    I was wondering if it is possible to insert all possible values of a loop into map layout as a text element. The script I have prints only one value or line. Here is part of my code. Thanks for your help !!

    Daniel A.

    Code:
    arcpy.AddMessage('Adding Text Elements...')
    
    arcpy.AddMessage('*************************')
    
    # search input feature
    rows=arcpy.SearchCursor(inputFc)
    
    # Retrieve the first record from the list
    row=rows.next()
    
    # set field value list
    FieldValList = []
    
    # loop through the field ATS
    while row:
          feat=row.shape      
          total=total+feat.area
          ATS = row.getValue("ATS")  
         
                
    
          # make sure its unique
          if not ATS in FieldValList:
                        FieldValList.append(ATS)                
                          
                                         
                                     
                
          # next field
          row=rows.next()        
                   
                        
                    
    
          # add text elemets to the map layout 
          for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
              if elm.name == "ATSList":
    
                   elm.elementPositionX = 6.5 
                   elm.elementPositionY = 1.0
    
                   for ATS in FieldValList:
               
                       elm.text = "Within Theoretical: " + "\n" + ATS

  2. #2
    Mathew Coyle

    Join Date
    Feb 2011
    Posts
    1,387
    Points
    966
    Answers Provided
    151


    1
    This post is marked as the answer

    Default Re: inserting text in map layout

    I know there is a better way to do this, I just can't remember what it is. Something like this should get the result you want I believe.

    Code:
        for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
            if elm.name == "ATSList":
                elm.elementPositionX = 6.5
                elm.elementPositionY = 1.0
                entry = "\r\n".join(FieldValList)
                elm.text = "Within Theoretical:\r\n{0}".format(entry)
    Edit: Maybe that is better

    Edit2: If they are not string values in your list try this.
    Code:
    "\r\n".join(map(str, FieldValList))
    Last edited by mzcoyle; 12-05-2012 at 02:24 PM.
    Mathew Coyle, EADA10
    GIS Analyst
    Alberta-Pacific Forest Industries Inc.
    ArcGIS 10.2.2 Testing
    ArcGIS 10.1 SP1
    Desktop, Server, ArcPad
    Windows 7 SP1 64-bit

  3. #3
    Daniel Abera
    Join Date
    Nov 2010
    Posts
    20
    Points
    0
    Answers Provided
    1


    0

    Default Re: inserting text in map layout

    Perfect !!!!! This is exactly what I was looking for.

    Thanks Mathew.

+ Reply to Thread

Tags for this 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