<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic ArcMap 10, ArcObjects, and Python:&amp;nbsp; very cool, but help with a couple of problems? in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210822#M5483</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;VITALS:&amp;nbsp; ArcGIS 10.0 - ArcView, Python 2.6.5, comtypes 0.6.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am writing an external Python script that needs to access the running ArcMap 10 application; therefore, I am getting my app reference through the AppROT object, which is working fine, as far as that goes.&amp;nbsp; So, here are my problems/questions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1)&amp;nbsp; What object type is returned when I execute the line&amp;nbsp; pApp=pAppROT.Item(i)?&amp;nbsp; I definitely get an IApplication for ArcMap but on what object exactly?&amp;nbsp; I thought it was IApplication in the esriArcMapUI.olb, but that may not be the case ... esriFramework.olb maybe?&amp;nbsp; [BTW, pAppROT is the IAppROT interface on the AppROT object.]&amp;nbsp; It makes a difference, because I later QI to IMxDocument and get an error that the module (esriArcMapUI) has no attribute IMxDocument.&amp;nbsp; This may all relate to my 2nd question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2)&amp;nbsp; I am building Python wrappers for ESRI olb's on the fly using the GetModule function in comtypes.&amp;nbsp; The problem is that wrappers are not being built for all of the olb's I specify, or rather the wrapper .py modules (the ones with the long GUID names) are empty.&amp;nbsp; esriFramework, esriGeometry, esriSystem, and esriSystemUI build just fine.&amp;nbsp; esriArcMapUI, esriCarto, and esriGeoDatabase &lt;/SPAN&gt;&lt;STRONG&gt;do not&lt;/STRONG&gt;&lt;SPAN&gt; build.&amp;nbsp; Has anyone else had this problem?&amp;nbsp; If so, how did you fix it ... if you did , that is?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you all for the help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-- Ti&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 Oct 2010 14:21:34 GMT</pubDate>
    <dc:creator>TiCrossman</dc:creator>
    <dc:date>2010-10-26T14:21:34Z</dc:date>
    <item>
      <title>ArcMap 10, ArcObjects, and Python:  very cool, but help with a couple of problems?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210822#M5483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;VITALS:&amp;nbsp; ArcGIS 10.0 - ArcView, Python 2.6.5, comtypes 0.6.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am writing an external Python script that needs to access the running ArcMap 10 application; therefore, I am getting my app reference through the AppROT object, which is working fine, as far as that goes.&amp;nbsp; So, here are my problems/questions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1)&amp;nbsp; What object type is returned when I execute the line&amp;nbsp; pApp=pAppROT.Item(i)?&amp;nbsp; I definitely get an IApplication for ArcMap but on what object exactly?&amp;nbsp; I thought it was IApplication in the esriArcMapUI.olb, but that may not be the case ... esriFramework.olb maybe?&amp;nbsp; [BTW, pAppROT is the IAppROT interface on the AppROT object.]&amp;nbsp; It makes a difference, because I later QI to IMxDocument and get an error that the module (esriArcMapUI) has no attribute IMxDocument.&amp;nbsp; This may all relate to my 2nd question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2)&amp;nbsp; I am building Python wrappers for ESRI olb's on the fly using the GetModule function in comtypes.&amp;nbsp; The problem is that wrappers are not being built for all of the olb's I specify, or rather the wrapper .py modules (the ones with the long GUID names) are empty.&amp;nbsp; esriFramework, esriGeometry, esriSystem, and esriSystemUI build just fine.&amp;nbsp; esriArcMapUI, esriCarto, and esriGeoDatabase &lt;/SPAN&gt;&lt;STRONG&gt;do not&lt;/STRONG&gt;&lt;SPAN&gt; build.&amp;nbsp; Has anyone else had this problem?&amp;nbsp; If so, how did you fix it ... if you did , that is?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you all for the help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-- Ti&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Oct 2010 14:21:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210822#M5483</guid>
      <dc:creator>TiCrossman</dc:creator>
      <dc:date>2010-10-26T14:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap 10, ArcObjects, and Python:  very cool, but help with a couple of problems</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210823#M5484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;1. Your first problem is related to you second:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. If you run the following (this will generate wrappers for every ESRI com lib):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
import comtypes.client
# change com_dir to whatever it is for you
com_dir = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\com'
coms = [os.path.join(com_dir, x) for x in os.listdir(com_dir) if os.path.splitext(x)[1].upper() == '.OLB']
map(comtypes.client.GetModule, coms)

# check add whatever you want here.
import comtypes.gen.esriArcMapUI
import comtypes.gen.esriGeodatabase

print dir(comtypes.gen.esriArcMapUI)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you get anything from the dir?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If not then run this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import logging
# grab rootlogger
_loggy = logging.getLogger()
_loggy.setLevel(logging.DEBUG)
_loggy.addHandler(logging.FileHandler("derpdebug.log"))
import os
import comtypes.client
# change com_dir to whatever it is for you
com_dir = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\com'
coms = [os.path.join(com_dir, x) for x in os.listdir(com_dir) if os.path.splitext(x)[1].upper() == '.OLB']
map(comtypes.client.GetModule, coms)

# check add whatever you want here.
import comtypes.gen.esriArcMapUI
import comtypes.gen.esriGeodatabase

print dir(comtypes.gen.esriArcMapUI)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There should now be a derpdebug.log file now (where ever you ran it from), open it up and look for, anything that indicates an error, also make sure you see the GetModule call for esriArcMapUI.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Worst case, delete everything in &amp;lt;PYTHON_DIR&amp;gt;\comtypes\gen directory (python_dir is your python installation path). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If still this does not work, let me know.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:23:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210823#M5484</guid>
      <dc:creator>FrankPerks</dc:creator>
      <dc:date>2021-12-11T10:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap 10, ArcObjects, and Python:  very cool, but help with a couple of problems</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210824#M5485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Frank,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you so much for your help.&amp;nbsp; Your solutions worked like a charm.&amp;nbsp; When I ran your script, the dir listed everything in the __dict__ of esriArcMapUI, as it should.&amp;nbsp; esriArcMapUI.py was intact.&amp;nbsp; With help from the person who wrote the example code that I used as a base, I have discovered that the comtypes generation of wrappers for ArcObjects occasionally fails, creating blank wrapper files.&amp;nbsp; This seems to happen when a wrapper file already exists and GetModule() is called to build it again.&amp;nbsp; I tested the wrapping process many more times, with both existing wrappers and a cleared out gen cache directory.&amp;nbsp; I got a failure once, and that was for an existing wrapper.&amp;nbsp; No failures for an empty cache.&amp;nbsp; Also, the failures all produced readable but empty files.&amp;nbsp; I have not encountered any instances of missing wrappers (where there should be one) or of corrupted, unreadable wrappers.&amp;nbsp; I did also run your second, debug script quite a few times, and dir() reported as expected.&amp;nbsp; The debug logs also showed no errors.&amp;nbsp; So, I have modified my code to check for existing (the more secure open(&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;filepath&lt;/SPAN&gt;&lt;SPAN&gt;) way) wrappers and whether those existing modules are blank or not before I make any calls to GetModule().&amp;nbsp; Works great.&amp;nbsp; I'll just be sure to rerun the wrapping process after ArcObjects updates.&amp;nbsp; Thanks, again, Frank.&amp;nbsp; I only wish I could give you some MVP points.&amp;nbsp; Grrrr.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ti&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GIS Specialist&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Durham, NH&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Oct 2010 01:16:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210824#M5485</guid>
      <dc:creator>TiCrossman</dc:creator>
      <dc:date>2010-10-30T01:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap 10, ArcObjects, and Python:  very cool, but help with a couple of problems</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210825#M5486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Frank,&lt;BR /&gt;&lt;BR /&gt;Thank you so much for your help.&amp;nbsp; Your solutions worked like a charm.&amp;nbsp; When I ran your script, the dir listed everything in the __dict__ of esriArcMapUI, as it should.&amp;nbsp; esriArcMapUI.py was intact.&amp;nbsp; With help from the person who wrote the example code that I used as a base, I have discovered that the comtypes generation of wrappers for ArcObjects occasionally fails, creating blank wrapper files.&amp;nbsp; This seems to happen when a wrapper file already exists and GetModule() is called to build it again.&amp;nbsp; I tested the wrapping process many more times, with both existing wrappers and a cleared out gen cache directory.&amp;nbsp; I got a failure once, and that was for an existing wrapper.&amp;nbsp; No failures for an empty cache.&amp;nbsp; Also, the failures all produced readable but empty files.&amp;nbsp; I have not encountered any instances of missing wrappers (where there should be one) or of corrupted, unreadable wrappers.&amp;nbsp; I did also run your second, debug script quite a few times, and dir() reported as expected.&amp;nbsp; The debug logs also showed no errors.&amp;nbsp; So, I have modified my code to check for existing (the more secure open(&lt;SPAN style="font-style:italic;"&gt;filepath&lt;/SPAN&gt;) way) wrappers and whether those existing modules are blank or not before I make any calls to GetModule().&amp;nbsp; Works great.&amp;nbsp; I'll just be sure to rerun the wrapping process after ArcObjects updates.&amp;nbsp; Thanks, again, Frank.&amp;nbsp; I only wish I could give you some MVP points.&amp;nbsp; Grrrr.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Ti&lt;BR /&gt;GIS Specialist&lt;BR /&gt;Durham, NH&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The way comtypes generates modules is a goldmine of horrors. GetModule only checks if the module is importable (via importerror), and does not check if the module actually finished generation. Technically it should hold off of writing the modules until all other linked modules are finished processing, sadily it does not (this bug has been in their bug tracker for quite awhile last time i checked.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are deploying a script that uses comtypes, the safest way is to modify the distutils setup.py file(if your not using one then make a script that is run once, when the script is installed). So:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Nuke the comtypes.gen folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. call GetModule() on all of the comlibs in the ArcGIS/com folder.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This prevents the need for GetModule() to be used within your actual program. Which hopefully makes things a little easier.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Nov 2010 17:00:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210825#M5486</guid>
      <dc:creator>FrankPerks</dc:creator>
      <dc:date>2010-11-03T17:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap 10, ArcObjects, and Python:  very cool, but help with a couple of problems</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210826#M5487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Frank,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm only just learning ArcObjects, and I'm hoping you can throw a little advice my way. Based on what I've read so far, I &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;thought &lt;/SPAN&gt;&lt;SPAN&gt; the following would work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import comtypes
import comtypes.client
import comtypes.gen.esriDataSourcesNetCDF

ws_factory = comtypes.client.CreateObject("esriDataSourcesNetCDF.NetCDFWorkspaceFactory", interface = esriDataSourcesNetCDF.INetCDFWorkspaceFactory)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, this throws an error since there is "no attribute 'INetCDFWorkspaceFactory'. As I understand it, Step 1 is to create a workspace factory. Step 2 is to create the workspace. And Step 3 is to instantiate the file of interest (in this case a NetCDF file) so I can play with the data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you steer me back on course?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:23:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210826#M5487</guid>
      <dc:creator>PhilMorefield</dc:creator>
      <dc:date>2021-12-11T10:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: ArcMap 10, ArcObjects, and Python:  very cool, but help with a couple of problems</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210827#M5488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this.&amp;nbsp; It should work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import comtypes.gen.esriDataSourcesNetCDF as esriDataSourcesNetCDF&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import comtypes.gen.esriGeoDatabase as esriGeoDatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ws_factory = comtypes.client.CreateObject("esriDataSourcesNetCDF.NetCDFWorkspaceFactory", interface = esriGeoDatabase.IWorkspaceFactory)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In AO, a class may be in 1 library, and an interface to that class may be in another.&amp;nbsp; Also, do the imports like I did above--it will help your IDE to follow what's going on and help you with autocompletes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2010 01:34:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/arcmap-10-arcobjects-and-python-nbsp-very-cool-but/m-p/210827#M5488</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2010-12-10T01:34:55Z</dc:date>
    </item>
  </channel>
</rss>

