+ Reply to Thread
Results 1 to 7 of 7

Thread: Accessing ArcObjects through Python

  1. #1

    Join Date
    Apr 2010
    Posts
    12
    Points
    0
    Answers Provided
    0


    0

    Default Accessing ArcObjects through Python

    Anyone know if there's an efficient way to use ArcObjects in a Python script?

    If not, does anyone know if there's a way to convert a VBA macro to a tool/script? I need to use ArcObjects to perform some calculations, but doing this through a macro saved in an mxd (like I do now) is definitely not the most efficient method...I guess I could take the time to learn C# but if there's a simpler way, that would be ideal. Anyone got suggestions?

  2. #2
    Brad Posthumus
    Join Date
    Apr 2010
    Posts
    66
    Points
    1
    Answers Provided
    0


    0

    Default

    Yes, it is possible. First of all, however, see if there's a way to convert it using just Python and the geoprocessor object. But if you absolutely need to use ArcObjects in Python, this should get you started:
    1. Install comtypes on your machine from here: http://sourceforge.net/projects/comtypes/files/ (get the most recent version, it will detect your version of Python when you install)
    2. Take a look at the "Using ArcObjects in Python" presentation from Mark Cederholm on this page: http://www.pierssen.com/arcgis/upload/misc/. He also has sample code on the same page. This man must be a genius.
    3. Read this thread from Frank Perks (another genius) for a different example: http://forums.esri.com/Thread.asp?c=...=289397#927436
    I'm astounded these fellows were able to figure this out. I've attempted it on-and-off for several years now but could never get a foothold on it. With there information, I'm now using Python to extract layer information and symbology from an MXD. It's very, very slow compared to ArcObjects in VBA, but it works. (Hopefully the arcpy module when alleviate this need at some point.)

    If you need a hand getting started, let us know and I can attempt to throw some code your way.

    Brad Posthumus
    Last edited by bposthumus; 04-14-2010 at 08:19 AM.

  3. #3

    Join Date
    Apr 2010
    Posts
    12
    Points
    0
    Answers Provided
    0


    0

    Default

    Thanks, this is just what I was looking for. I can do the majority of what I need with the native geoprocessor, it's just I want to use a couple specific objects. But this is excellent, now I can use them in python.

  4. #4
    Brad Posthumus
    Join Date
    Apr 2010
    Posts
    66
    Points
    1
    Answers Provided
    0


    0

    Default

    Yes, it opens up a whole new world of functionality to Python users! For anyone who has ever asked if MXD's can be created or altered through Python, there's a good chance the answer is "yes" if you use comtypes.

  5. #5
    Stefan Offermann
    Join Date
    Feb 2010
    Posts
    86
    Points
    1
    Answers Provided
    0


    0

    Default

    Quote Originally Posted by bposthumus View Post
    For anyone who has ever asked if MXD's can be created or altered through Python, there's a good chance the answer is "yes" if you use comtypes.
    It is a new feature of arcpy to get access to mxds and its contents with ArcGIS 10, isn't it?

    Have a look at the new "mapping" module: http://help.arcgis.com/en/arcgisdesk...0032000000.htm

    Best regards, Stefan
    Stefan Offermann
    software engineer at con terra GmbH, Germany
    st3fan_de

  6. #6
    Brad Posthumus
    Join Date
    Apr 2010
    Posts
    66
    Points
    1
    Answers Provided
    0


    0

    Default

    Quote Originally Posted by offermann View Post
    It is a new feature of arcpy to get access to mxds and its contents with ArcGIS 10, isn't it?

    Have a look at the new "mapping" module: http://help.arcgis.com/en/arcgisdesk...0032000000.htm
    True enough, but for those of us who have at least another year to wait before having to ArcGIS 10 -in our case due to a general corporate roll-out lag, or for others who won't be upgrading any time soon- it's nice to have this option now rather than later.
    Last edited by bposthumus; 04-19-2010 at 05:58 AM. Reason: fix quote tag

  7. #7
    Frank Perks
    Join Date
    Apr 2010
    Posts
    59
    Points
    5
    Answers Provided
    0


    0

    Default

    Quote Originally Posted by bposthumus View Post
    [*]Read this thread from Frank Perks (another genius) for a different example: http://forums.esri.com/Thread.asp?c=...=289397#927436
    [
    I feel special now.

    It's very, very slow compared to ArcObjects in VBA, but it works. (Hopefully the arcpy module when alleviate this need at some point.)
    Last set of benchmarks i saw, basically put comtypes 3x times faster then arcpy

    But overall its actually extremely useful IMO. Its a really really easy way to basically or throw something togther extremely quickly just to see if it works. As for comtypes pretty much everything from ESRI's API you can access there is a handful of things that comtypes does not like, simply because of how they are implemented. Hopefully after exams, i can actually finish making my more friendly arcgis comtypes library. (theres bugs, esri does not follow standards for iterable interfaces, comtypes does not handle esri hresult markup, etc.

+ 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