3

I am relatively new working with python and arcobjects. Under normal limitations I know that you cannot create a Legend or any arcobject with arcpy.mapping. Is there a generic example of creating a legend or an arcobject using comtypes to get me in the right direction?

I am trying to create as script to automate several maps and export them to jpg after. (All the code is figured out outside the codeblocks with comtypes)

I was able to figure out (with some search) how create a MXD but not sure which arcobjects to be replace for creating a legend with CreateObject.

import arcpy, os
from comtypes.client import GetModule, CreateObject
from Snippets import GetStandaloneModules, InitStandalone

arcpy.env.workspace = r"E:\foo"
wksp = arcpy.env.workspace

# Code that is out of the scope of the question

# Get the Carto module
esriCarto = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriCarto.olb")


for boro in boros:
    # Create a map document object
    mxdobj = CreateObject(esriCarto.MapDocument, interface=esriCarto.IMapDocument)
    # Create a new borough mxd with mapping.MapDocument
    print "Creating Wifi_{}.mxd".format(boro)
    path = r"{}\Wifi_{}.mxd".format(wksp,boro)
    print path
    # Creates mxd
    mxdobj.new(path)
    #delete obj
    del mxdobj

# Rest of the code
5
  • There's a few examples on this site, have a search for python and ArcObjects, a good one is gis.stackexchange.com/questions/142734/… which deals with similar objects to legend objects. If you're not already familiar with ArcObjects have a read of this answer gis.stackexchange.com/questions/129456/… about how to read the ArcObjects documentation to find your way from one object to another. – Michael Stimson May 8 '16 at 21:49
  • Is there a reason why you want to code using python? If you are using ArcObjects it will be easier in VB or C#? Unless you are trying to tie everything up into the geo-processing framework? Just curious? – Hornbydd May 8 '16 at 22:32
  • This is a project I am working on for my GIS programming class. I know it would be easier for doing ArcObjects in .net but the class was run in python. I would like to know how to do this so I can use it for my thesis proposal I have to write soon as well. – Brett May 8 '16 at 22:44
  • And for an arcobjects approach: gis.stackexchange.com/a/73167/59 – Kirk Kuykendall May 8 '16 at 23:08
  • Thanks. That did help me figure out a few more things on what I needed to do even though I found the Arcobjecs API for this a bit confusing vs than the arcpy's API – Brett May 14 '16 at 21:04