When I attempt to use arcpy.da to add junction features to a geometric network, I get the error "error return without exception set." Here's the code in question:
The above code works fine if the target feature class does not participate in a geometric network. When I use ArcObjects instead of arcpy.da, I have no troubles:
Is there a limitation to arcpy.da that I can't find in the documentation?
Code:
def Migrate_GasLamp_DA():
sSourceClass = sSourceGDB + "/gaslight"
sTargetClass = "GasLamp"
SourceFieldList = ["SHAPE@", "PLACEMENT_CODE"]
TargetFieldList = ["SHAPE@", "ENABLED", "CREATIONUSER", \
"DATECREATED", "DATEMODIFIED", "LASTUSER"]
dtCreate = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
edit = da.Editor(sTargetGDB)
edit.startEditing(False, False)
edit.startOperation()
c = da.InsertCursor(sTargetClass, TargetFieldList)
iTotal = 0
i = 0
with da.SearchCursor(sSourceClass, SourceFieldList) as cursor:
for row in cursor:
iTotal += 1
i += 1
if i == 1000:
edit.stopOperation()
edit.startOperation()
i = 0
geom = row[0]
sPC = row[1]
tok = UserDateFromPC(sPC)
sUser = tok[0]
dtPC = tok[1]
newrow = [geom, 1, "Data Migration", dtCreate, \
dtPC, sUser]
c.insertRow(newrow)
del c
edit.stopOperation()
edit.stopEditing(True)
return iTotalCode:
def Migrate_GasLamp_AO():
GetESRIModule("esriGeoDatabase.olb")
GetESRIModule("esriDataSourcesGDB.olb")
import comtypes.gen.esriGeoDatabase as esriGeoDatabase
import comtypes.gen.esriDataSourcesGDB as esriDataSourcesGDB
pWSF = NewObj(esriDataSourcesGDB.FileGDBWorkspaceFactory, \
esriGeoDatabase.IWorkspaceFactory)
pSourceWS = pWSF.OpenFromFile(sSourceGDB, 0)
pSourceFWS = CType(pSourceWS, esriGeoDatabase.IFeatureWorkspace)
pTargetWS = pWSF.OpenFromFile(sTargetGDB, 0)
pTargetFWS = CType(pTargetWS, esriGeoDatabase.IFeatureWorkspace)
pSourceFC = pSourceFWS.OpenFeatureClass("gaslight")
pTargetFC = pTargetFWS.OpenFeatureClass("GasLamp")
iPC = pSourceFC.FindField("PLACEMENT_CODE")
iEn = pTargetFC.FindField("ENABLED")
iCU = pTargetFC.FindField("CREATIONUSER")
iDC = pTargetFC.FindField("DATECREATED")
iDM = pTargetFC.FindField("DATEMODIFIED")
iLU = pTargetFC.FindField("LASTUSER")
dtCreate = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
pFCursor = pSourceFC.Search(None, True)
iTotal = 0
i = 0
pEditWS = CType(pTargetWS, esriGeoDatabase.IWorkspaceEdit)
pEditWS.StartEditing(False)
pEditWS.StartEditOperation()
while True:
pSourceFeat = pFCursor.NextFeature()
if not pSourceFeat:
break
iTotal += 1
i += 1
if i == 1000:
pEditWS.StopEditOperation()
pEditWS.StartEditOperation()
i = 0
sPC = pSourceFeat.Value(iPC)
tok = UserDateFromPC(sPC)
sUser = tok[0]
dtPC = tok[1]
pTargetFeat = pTargetFC.CreateFeature()
pTargetFeat.Shape = pSourceFeat.Shape
pTargetFeat.Value[iEn] = 1
pTargetFeat.Value[iCU] = "Data Migration"
pTargetFeat.Value[iDC] = dtCreate
pTargetFeat.Value[iDM] = dtPC
pTargetFeat.Value[iLU] = sUser
pTargetFeat.Store()
pEditWS.StopEditOperation()
pEditWS.StopEditing(True)
return iTotal