Cannot use arcpy.da to add junction features to geometric network

2124
5
04-24-2013 12:42 PM
MarkCederholm
Occasional Contributor III
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:

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 iTotal


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:

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


Is there a limitation to arcpy.da that I can't find in the documentation?
Tags (2)
0 Kudos
5 Replies
ChrisSnyder
Regular Contributor III
Any schema locks? From the help:

"An exclusive lock is required to modify a geometric network's connectivity rules, add a feature class to the geometric network, or delete a geometric network. An exclusive lock can only be acquired for a geometric network if the feature classes that participate in the network can also be locked. Therefore, if a user has an exclusive or shared lock on any of the feature classes in a geometric network, then the properties of the geometric network can't be edited."

I've never built/managed a Geometric Network via Python, but as a last resort you could probably drop the network, add your features, and then rebuild... or just use the "old" python cursors (assuming they work).
0 Kudos
MarkCederholm
Occasional Contributor III
I guess my wording was poor.  I'm adding features to a feature class that already participates in a geometric network, not making modifications to the network definition itself.  As I said, I can do it just fine using ArcObjects instead of arcpy.da, or arcpy.da works fine if the feature class does not participate in the network.
0 Kudos
CallumSmith
New Contributor III

Hi

I know its a long time ago now but I was wondering if you managed to find a solution to this. I am trying to use a insertCursor (da) to add features to a feature class that participates in geometric network and are getting this error:

error return without exception set

If I remove the Geometric Network the code works fine. I cant remove the geometric network form the Production database.

Is it possible to use the data access insertcursor to insert records into a featureclass that participates in a geometric network??

cheers

Callum

0 Kudos
MarkCederholm
Occasional Contributor III

It's in the system as bug NIM-102778 (currently unresolved).  Esri gives the following workaround:

The Append tool works fine for features participating in a geometric network.

1. Fill an empty feature class outside the geometric network with records using an insert cursor.

2. Use the Append tool to add the records to the feature class in the geometric network.

0 Kudos
DanPatterson_Retired
MVP Emeritus

EDIT moved to live thread

0 Kudos