I'm a bit lost here, so my answer may be off base. When you say you want the ExtentID
, that appears to be the name of the Dataframe you're exporting the extent of. If this is the case (which is what your code is doing to my best guess), you don't need the [x] index when printing it. :
for el in arcpy.mapping.ListLayoutElements(mxd2, "DATAFRAME_ELEMENT"):
ExtentIDStore = str(el.name)
#print x, y, z <--- You don't need to print x y and z. They are unrelated at this point.
print ExtentIDStore #used to see which item to add to the shape file
print ExtentIDStore[x] # <- This will just print an indexed character in the string
By the time you reach the loop above, your code is only concerned with the Dataframe Element in question, so there is no need to do any indexing for storage. ExtendIDStore
should be what you add to the shapefile row.
Your error which results at this line:
row.strField = str(x)
Is probably because you are not referencing a field that exists. What comes after the row reference is the name of the Field. In this case, it should be:
row.ExtentID = ExtentIDStore
File name you can get via the filePath
property of the MapDocument class and the os.path.basename
method, i.e.:
filepath = mxd2.filePath # Gets full path of MXD used in your dataframe loop
filename = os.path.basename(filepath) # Extracts the file name and extension
row.FileRef = filename
If you don't want the extension, use filename.strip(".mxd")
to remove it.
Scale would be:
scale = el.scale # Scale of the dataframe referenced in the loop
row.Scale = scale
And that should fill in the rows you're looking for.
For the new problem, I think you are misusing the insert cursor. The second argument should be a spatial reference, which cannot be gleaned via an MXD. I would recommend creating the cursor with only one argument (the output file or dfStore). You also forgot the last (and most important) line:
rows.insertRow(row)
Without that your data never gets put into the table. Put that down at the end of the row loop so that the data is actually inserted after all the variables are set.
For more information about accessing Dataframe, layer, and map properties (scale, name, current position), check out the mapping module. The scale property of the Dataframe class can be seen on the classes page of the same name.
Best Answer
You have set
TEname
to a list of text element objects when you do this:To get a single text element object from that list use an index of 0 on that list: