Skip to content

Instantly share code, notes, and snippets.

@geographika
Created April 17, 2011 11:31
Show Gist options
  • Save geographika/923954 to your computer and use it in GitHub Desktop.
Save geographika/923954 to your computer and use it in GitHub Desktop.
ArcObjects and Python
def AppendPaths(paths):
"""Append all the paths with DLLs to be used by the script to the Python Path"""
import sys
for p in paths:
sys.path.append(p)
def AddReferences(refs):
"""Add references to the required DLLs"""
import clr
for r in refs:
clr.AddReference(r)
def Init():
"""
Initialise ArcObjects and licensing
"""
from ESRI.ArcGIS.esriSystem import AoInitializeClass, esriLicenseProductCode
init = AoInitializeClass()
init.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView)
def CreateApplication():
"""Open and instance of ArcMap"""
from ESRI.ArcGIS.ArcMapUI import MxDocumentClass
doc = MxDocumentClass()
app = doc.Parent
app.Visible = True
return app
def ListNetworks():
"""
List geometric networks in a geodatabase using methods written in
a custom VB.NET / ArcObjects DLL
"""
from MyArcObjectsDLL import NetworkGeodatabase
print dir(NetworkGeodatabase)
dbpath = r"D:\Data\Databases\network_geodatabase.mdb"
gdb = NetworkGDB(dbpath) #create a new instance of custom class
networks = gdb.ListNetworks()
for n in networks:
print n
paths = [r"C:\Python27\Lib\pythonnet-2.0-alpha2-clr2.0_131_py27_UCS2",
r"C:\Program Files\ArcGIS\DeveloperKit10.0\DotNet",
r"D:\Projects\Sourcecode\MyArcObjectsDLL\bin\Debug"]
AppendPaths(paths)
AddReferences(["MyArcObjectsDLL","ESRI.ArcGIS.System"])
Init()
CreateApplication()
ListNetworks()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment