I am new to python, am debugging one of existing python code, where am facing an error "'module' object has no attribute 'SdeWorkspaceFactory". Earlier this code was working fine but suddenly does not work.
am using sde connection file from path
"C:\Users\user1\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Connection.sde
I could able to connect this using sde file using Arcatalog.
Environment : ArcGIS 10.1
I cannot provide entire code base, however most of code looks like correct.
Please provide me a pointer?
def OpenFeatureClass(sWorkspace, sFCName):
import comtypes.gen.esriGeoDatabase as esriGeoDatabase
import comtypes.gen.esriDataSourcesGDB as esriDataSourcesGDB
#pWSF = NewObj(esriDataSourcesGDB.FileGDBWorkspaceFactory, esriGeoDatabase.IWorkspaceFactory)
pWSF = NewObj(esriDataSourcesGDB.SdeWorkspaceFactory, esriGeoDatabase.IWorkspaceFactory)
pWS = pWSF.OpenFromFile(sWorkspace, 0)
pFWS = CType(pWS, esriGeoDatabase.IFeatureWorkspace)
pFC = pFWS.OpenFeatureClass(sFCName)
return pFC
Best Answer
You may get better help by changing the tags from arcpy to ArcObjects as this has nothing to do with arcpy, you are accessing ArcObjects using python's comtypes module.
Regarding your error, you may need to reload all your ArcObjects Object Library files (*.olb) files. I was able to successfully get the IWorkspaceFactory2 pointer from your code:
See if reloading the ArcObjects libraries helps.
EDIT: The object libraries need to updated any time you change versions in ArcGIS. The safe thing is to go into your comtypes "gen" folder and delete everything but the "init.py" script and run the load all function (in below code). Here are some helper functions: