POST
|
For anybody interested, I figured out how to complete my task. First my previous response didn't quite solve my problem. It created a separate map layout page then a separate report page which then combined into a two page document. However, I wanted the report to be on the same layout page. So my solution was the following: I used ExportReport to create the report as a tif image. Then, with an existing picture element on the page layout, I simply remapped the picture source to the newly created tif source path. Then I simply exported the page layout with the included report to a pdf document (of course this can be included in a loop for multiple areas/items...which is in fact what I did). However, there is one caveat....when the code attempts to remove all the temporary tifs I get the error that the last tif is in use because, it is in fact in use. Yet, my task is complete because the pdf of the page layout with the report included was successfully created. (Poor programming I know, but I'm not a coder and it does what I need it to do.) If anyone is interested in seeing the code I am more than glad to provide it. Cheers.
... View more
10-17-2016
10:31 AM
|
0
|
0
|
442
|
POST
|
For whatever unknown reason I got a more complex script to work. However, instead of exporting to emf, I exported the page layout to pdf and then combined that with the report pdf.
... View more
10-12-2016
11:31 AM
|
0
|
0
|
442
|
POST
|
Dan, Sorry about the formatting. I couldn't figure it out....I thought that was what the <code></code> tags were for. Thanks for the link.
... View more
10-12-2016
08:05 AM
|
0
|
0
|
442
|
POST
|
I'm trying to write a script to export a report that includes a map in the output pdf. While the script will create the pdf report and a separate .emf file, the script won't include the emf image in the pdf document. I have copy/pasted the example from the Desktop help (search for ExportReport to see to what I am referring to) with only minor edits to the script. See below: import arcpy, os
path = os.getcwd() #a relative path allowing for easy packaging
#Create PDF and remove if it already exists
pdfPath = path + r"\States_SubRegions.pdf"
if os.path.exists(pdfPath):
os.remove(pdfPath)
pdfDoc = arcpy.mapping.PDFDocumentCreate(pdfPath)
subRegionList = ["744","760"]
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "BuildingSpace_A")[0]
pageCount = 1
for region in subRegionList:
#Generate image for each sub region
## whereClause = "facilityID = '" + region + "'"
## lyr.definitionQuery = whereClause
## arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
## df.extent = lyr.getSelectedExtent()
## arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION"
arcpy.mapping.ExportToBMP(mxd, path + "\RegionalPicture.bmp", df) #single file
#Generate report
arcpy.mapping.ExportReport(report_source=lyr, report_layout_file=path + r"\custodial_areas.rlf", output_file=path + r"\temp" + str(pageCount) + ".pdf", dataset_option="USE_RLF",starting_page_number=pageCount)
#Append pages into final output
pdfDoc.appendPages(path + r"\temp" + str(pageCount) + ".pdf")
#os.remove(path + r"\temp.pdf")
pageCount = pageCount + 1
pdfDoc.saveAndClose()
del mxd Maybe I don't understand the purpose of the script?? Your help is greatly appreciated and thanks in advance for any help. Cheers I'm using v. 10.3.1 for Desktop 32 bit windows with 32 bit ESRI
... View more
10-12-2016
07:38 AM
|
0
|
5
|
1092
|
POST
|
Matthew, Thanks. Inititially I thought:
row=rows.next()
while row:
code....
row=rows.next()
would work regardless of the version, but it doesn't seem so. The confusing thing is that when I run it in my XP VM machine using 9.3, it works fine for me, but other users report that it's not working for them...?? So, I can't confirm that this is infact the problem with my code, but the error message seems to imply that it is. I'm starting to think maybe there is something wrong with my ftrClsList = gp.ListFeatureClasses(), but why does it work for me??? I'm at my wits end... Any more ideas is greatly appreciated. Cheers
... View more
06-26-2012
11:03 PM
|
0
|
0
|
526
|
POST
|
With help from the forum, I thought I figured out how to write a cursor to work in 9.3 and 10 but users report not. Here's my code:
import arcgisscripting, sys, os, string, traceback
gp = arcgisscripting.create(9.3)
# Set to write over previous outputs if they exist
gp.overwriteoutput = False
def which30(two6ftrcls):
two6FC = two6ftrcls
whereclause = "Two6FCs = '" + two6FC + "'"
gp.AddMessage("whereclause is " +whereclause)
crosswalk = ShellPath + "/Two630FC_IDPKxwalk.dbf"
# The variables row and rows are initially set to None, so that they
# can be deleted in the finally block regardless of where (or if)
# script fails.
row, rows = None, None
Three0ftrlst = []
FC_26namelst = []
row, rows = None, None
Three0ftrlst = []
FC_26namelst = []
rows = gp.SearchCursor(crosswalk,whereclause)
row = rows.next()
if (row == None):
gp.AddMessage("check the Two630FC_IDPKxwalk.dbf table for Two6FCs -->" +two6FC)
elif (row != None):
while row:
if not row.isNull("Three0FCs"):
Three0ftr=row.getValue("Three0FCs")
gp.AddMessage("Three0ftr is " +Three0ftr)
Three0ftrlst.append(str(Three0ftr))
FC_26name = row.getValue("FC_26")
FC_26namelst.append(str(FC_26name))
row = rows.next()
if row: del row
if rows: del rows
return Three0ftrlst, FC_26namelst
Works in 10 but not in 9.3 (so I'm told). Attached is a screenshot of the error message.
... View more
06-26-2012
05:42 AM
|
0
|
4
|
2650
|
POST
|
Mark, Wow...I'm glad I got someone with your knowledge to respond. So, how do I write it to be used in both versions. Incidentally, the only reason my code calls rows.next() is because early on in the development I was checking if rows was == None, which it never is because it always returns an object. So, I had to advance to a row to see if the row was == None. Do you follow? (Also, have you figured out that I barely know what I'm doing....probably.) Again, any help is greatly appreciated. Feel free to email me at: turnerkyle@hotmail.com
... View more
06-22-2012
05:38 AM
|
0
|
0
|
281
|
POST
|
Can anyone explain why my code fails with "geoprocessing object not iterable" in 9.3 but works in 10. Are there some compatibility issues going on? I wrote the python code in 10 but made sure not to make any calls to arcpy. I invoked, gp = arcgisscripting.create(9.3) My understanding is before 9.3, python didn't use 'real' lists, so calling list methods would obviously fail. Is that wrong? Is 9.3 not able to use list methods? The following code, I believe, is where the problem is...I think?? # function to return appropriate 3.0 feature class for given 2.6 feature class # and it returns the name of the fieldname, FC_26_name def which30(two6ftrcls): two6FC = two6ftrcls whereclause = "Two6FCs = '" + two6FC + "'" gp.AddMessage("whereclause is " +whereclause) crosswalk = ShellPath + "/Two630FC_IDPKxwalk.dbf" # The variables row and rows are initially set to None, so that they # can be deleted in the finally block regardless of where (or if) # script fails. row, rows = None, None Three0ftrlst = [] FC_26namelst = [] rows = gp.SearchCursor(crosswalk,whereclause) row = rows.next() if (row == None): gp.AddMessage("check the Two630FC_IDPKxwalk.dbf table for Two6FCs -->" +two6FC) elif (row != None): rows = gp.SearchCursor(crosswalk,whereclause) for row in rows: if not row.isNull("Three0FCs"): Three0ftr=row.getValue("Three0FCs") Three0ftrlst.append(str(Three0ftr)) FC_26name = row.getValue("FC_26") FC_26namelst.append(str(FC_26name)) if row: del row if rows: del rows return Three0ftrlst, FC_26namelst
... View more
06-21-2012
11:10 PM
|
0
|
2
|
386
|
POST
|
Where do I put my setprogressor statements to get a realistic progress bar? I initially thought it should be in the outermost loop, but now I'm not sure. Right now I have something to the effect of:
try:
for ds in DSs:
listFCs = gp.ListFeatureClasses("","",ds)
fcCount = len(listFCs)
gp.SetProgressor("step", "Listing Feature Classes...", 0, fcCount, 1)
for fcs in listFCs:
gp.SetProgressorLabel("Calculating fields for... " + fcs)
gp.SetProgressorPosition()
do stuff
then a bunch of other imbedded if/thens and for in within the above for in statement
except:
your typical messages
finally:
gp.resetprogressor()
(Hopefully the above "code" makes sense/is useful.) Thanks in advance for your help. Cheers.
... View more
04-09-2012
03:17 AM
|
0
|
1
|
706
|
POST
|
No worries. I'm very familiar with counting from zero. Thanks anyways, never hurts to be sure.
... View more
04-02-2012
11:14 AM
|
0
|
0
|
284
|
POST
|
It looks like a scope problem. try setting each parameter to a variable using GetParameterAsText outside the expression string, and use the variables inside the string. As it stands, you are referenceing a property of the gp inside a tool running in the gp (the gp.GetParameterAsText(n) is not evaluated until it has already been passed as an expression parameter to CalculateField). to wit: param2 = gp.GetParameterAsText(2)
param3 = gp.GetParameterAsText(3)
expression = "autoIncrement(param2, param3)" Mark, Thanks for the help. I tried that and it tells me that the variable is not defined(or whatever the verbiage is... I'm at home now and don't have access to my work PC). Your efforts are greatly appreciated; maybe I'm not executing it properly??? (just flailing about at this point). Thanks
... View more
04-02-2012
10:10 AM
|
0
|
0
|
284
|
POST
|
First, I'm using Arc10, but calling import arcgisscripting gp = arcgisscripting.create(9.3) because I am making a script for other users. I get the following error when I try to use a codeblock/expression to calculate a field. ERROR 000539: Error running expression: autoIncrement(gp.GetParameterAsText(2),gp.GetParameterAsText(3)) <type 'exceptions.NameError'>: name 'gp' is not defined Failed to execute (CalculateField). It seems that I can't pass in variables to my calc field code. e.g. gp.CalculateField_management(FCls30, IDPK, expression, "PYTHON", codeblock) where expression = "autoIncrement(gp.GetParameterAsText(2),gp.GetParameterAsText(3))" If I pass in a string for each argument, then no problems. Please help. Thanks
... View more
04-02-2012
07:38 AM
|
0
|
4
|
425
|
POST
|
Thanks for your help gentlemen. Chris, I tried your getcount_management option, but it seems that you can only use it on a layer/fc. I tried count = int(gp.getcount_management(rows).getoutput(0))......which fails. I suppose I could have made a layer, but I figured out another way. Here's how I fixed it: rows = gp.SearchCursor(fc,query) row = rows.next() if not (row == None): do what you need to do elif (row == None): well, then someone needs to fix the dataset. Thanks again gentlemen for your time. Cheers.
... View more
02-02-2012
11:20 PM
|
0
|
0
|
1241
|
POST
|
If your cursor is empty, it will never step in. Nothing in the loop for row in rows: will execute because there is no row in rows, if you follow. So I tested your code and came back with 4 rows, is that right? i am confused, I thought you wanted to test if the cursor object was empty? Duh...I should have tested for row == None outside the for/loop, being sure to set row = None before the call to Searchcursor....duh. Yes, the code as shown will find something, because "AirfieldSurface" is in the dbf. However, change the FCls30 variable to something like, ZZZ, and see what happens. Thanks again.
... View more
02-02-2012
11:26 AM
|
0
|
0
|
5308
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|