Okay, I have a somewhat working script, but it's not complete just yet.
import arcpy
import arcpy.mapping as map
from arcpy import env
import datetime
mxd = map.MapDocument("CURRENT")
mapName = str(mxd.filePath).split('\\')[-1:][0][:-4]
nodeFeatures = r'OSP Mapping Layers\Node Locations'
circuitIDTable = r'Circuit ID Table'
strandsPerNode = 6
numIDs = strandsPerNode/2
targetTBL = circuitIDTable
targetFields = ['SimpleID', 'ExtendedID', 'InternalID', 'ExternalID', 'Termination', 'ProjectRegion', 'ProjectState', 'ProjectName', 'ProjectCustomer', 'NodeGUID']
sourceFC = nodeFeatures
sourceFields = ['SimpleID', 'ExtendedID', 'InternalID', 'ExternalID', 'Termination', 'ProjectRegion', 'ProjectState', 'ProjectName', 'ProjectCustomer', 'GlobalID']
with arcpy.da.InsertCursor(targetTBL, targetFields) as targetCursor:
with arcpy.da.SearchCursor(sourceFC, sourceFields) as sourceCursor:
for row in sourceCursor:
for i in range(1, numIDs+1):
targetCursor.insertRow(row)
Everything up to this point works just fine. The script takes the value that will be entered by the user, derives the correct number of IDs needed, and then generates the appropriate number of entries, as well as porting over the appropriate attributes into their corresponding fields:
In this image here you can see that the tool recognized that each site needed 3 entries per site (reference the GUIDs), and it ported over the appropriate information for Region, State, and Name (others pulled over too, just keeping image small).
However, at this point the Circuit ID field is blank. This field is a concatenation of the InternalID, Termination, and ProjectCustomer fields, and then a 2 digit number. So I added the following code to generate the Circuit ID's (row 1 here is the same as row 22 above):
with arcpy.da.InsertCursor(targetTBL, targetFields) as targetCursor:
with arcpy.da.SearchCursor(sourceFC, sourceFields) as sourceCursor:
for row in sourceCursor:
for i in range(1, numIDs+1):
targetCursor.insertRow(row)
calcTable = circuitIDTable
calcField = "CircuitID"
if i < 10:
IDnumber = "0" + str(i)
else:
IDnumber = i
expression = "'(' + row[2] + ')-(' + row[4] + ')-(' + row[8] + ')-(' + str(IDnumber) + ')'"
arcpy.CalculateField_management(calcTable, calcField, expression, "PYTHON_9.3")
In this image you can see that it calculated the Circuit ID as desired:
However, the operation stops at this point and I get this error:
Essentially I have everything I need with the code that I have, but I need to tweak it to continue through the iteration and create the rest of the Circuit ID's. The desired result would look like this:
Thanks!