POST
|
Zorba, I'm having the same issue. There's no examples of the "deleteFeatures" request syntax anywhere. So frustrating.
... View more
02-25-2015
07:44 AM
|
0
|
0
|
598
|
POST
|
OK, here's what I finally figured out. It all comes down to the "Zoom To Percentage" in the map layout. All along I???ve noticed that printing to a PDF file seemed to build the layout tables correctly, but the table would be too small. In ArcMap: [ATTACH=CONFIG]27486[/ATTACH] The resulting Output PDF: [ATTACH=CONFIG]27487[/ATTACH] However when I changed the "Zoom to Percentage" in the layout, the results looked like this: In ArcMap: [ATTACH=CONFIG]27488[/ATTACH] The resulting Output PDF: [ATTACH=CONFIG]27489[/ATTACH] Go figure as to why, but it works! For me my magic number was 245%. I think it'll vary for each user depending on how they have their toolbars setup, etc. This value also applied to both 8.5x11 and 11x17 landscape layouts. So as a recap I used this script to launch ArcMap and open the MXD file: import arcpy import subprocess strArcMapPath = r"C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\ArcMap.exe" strMxd = r"D:\Users\Products\PSA Map Updates\Automation\PSA Location Map - Final.mxd" objNewProcess = subprocess.Popen([strArcMapPath, strMxd]) objNewProcess.wait() # this line will wait for the new process to end print "Script completed successfully." Then this one as my Python AddIn script: import arcpy import pythonaddins class ExtensionClass1(object): """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def openDocument(self): mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT") Now I was orignally trying to close ArcMap in order to execute the PrintMap function before close, however this method works at open. I still can't believe it. Keep in mind that this process requires a PDF print driver of some sort in order to work. I have Adobe Acrobat installed which includes an "Adobe PDF" driver, however there are a few freebies out there that shouldwork just as well (i.e. CutePDF, etc...) I plan to forward this to out customer support rep to see if that will help move things along with the bug fix. Thanks for all the input, and assistance. If anyone has any questions feel free to contact me.
... View more
09-16-2013
09:55 AM
|
0
|
0
|
2503
|
POST
|
Stacy, I've had some success. I'm running late getting out of the office today, but I plan to write it all up on Monday. Your never going to believe how I got it to work. Sorry to leave you hanging in suspense over the weekend. Eric
... View more
09-13-2013
11:42 AM
|
0
|
0
|
802
|
POST
|
Stacy, Thanks again. I ran through the tests that you recommended and unfortunately didn't have any luck. At this point I've tested all the steps that need to be run in ArcMap's command window, Python Idle, and Python Command line. That's why I'm in the situation that I'm currently in. Maybe it'll help if I explain why I'm having to do all of these steps using just the right method and order. For a few years now, ESRI has not responded to a bug that's been reported multiple times (NIM062177 and NIM063441 - "ExportToPDF using arcpy does not export a layer attribute table embedded in a layout"). They claim that the bug was rejected because it is "beyond the design of the software". However, the ExportToPDF function works fine with layouts without tables. So it appears that it was never fully tested. So, as a result I am trying to work around the bug, and get my layouts with embeded attribute tables to produce PDF files. What I do know is that if I open my MXD manually in ArcMap and Export to a PDF it drops the wireframe around the tables (but produces the data. If I do this through code only, I get no data). However, if I use the Adobe PDF print driver and print to a file, it works. So, from this I know that I have to do the following things in this exact order and timing. 1. Open the MXD in ArcMap 2. Wait for the Layout to fully assemble 3. Print to file using the Adobe PDF print driver 4. Close ArcMap (hopefully) The reason I opted to use a Python AddIn Extension is it can be executed within the ArcMap application, and not through code only (which doesn't work). So as it stands I have 2 Python scripts. One that launches ArcMap, and opens an MXD, and another which runs in the AddIn Extension: Open the MXD in ArcMap: [HTML]import arcpy import subprocess strArcMapPath = r"C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\ArcMap.exe" strMxd = r"D:\Users\Products\PSA Map Updates\Automation\PSA Location Map - Final.mxd" objNewProcess = subprocess.Popen([strArcMapPath, strMxd]) objNewProcess.wait() # this line will wait for the new process to end print "Script completed successfully."[/HTML] Execute Python AddIn Extension: [HTML]import arcpy import pythonaddins import os import time class ExtensionClass1(object): """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def openDocument(self): mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': layers = arcpy.mapping.ListLayers(mxd, "", "Layers"): print layers time.sleep(1) os.system('taskkill /IM Arcmap*') def beforeCloseDocument(self): arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")[/HTML] As ArcMap opens, the AddIn Extension executes another Python script (shown above) which queries the MXD properties for a piece of text "Print to PDF" to determine if the map should be Printed To a PDF. If the Description Property does not meet the query it just opens as usual, if it does, I'd like for it to roll into the PrintMap function which produces the PDF file. The kicker here is that I'm limited to the functions available within the extension class (at least according to the documentation). These functions appear to be run only if a certain event occurs (i.e openDocument, beforeCloseDocument, closeDocument, etc.). That being said I'm trying to figure out a way to execute the "arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")" function inside the extension class as the result of an occurence. When I do this after openDocument, it runs too quickly and the tables do not get added to the PDF correctly. When I try to stall the PrintMap function at openDocument (using ListLayers, time.sleep(), etc.) the actual opening of the file gets stalled. So I opted to try to generate the PDF beforeCloseDocument which is ultimately why I started this thread. I have to programatically close the MXD in order for the PrintMap function to execute. Maybe there's a way to build a custom extension class function that'll do all this, however, my knowledge of Python is limited to what I've been able to do so far. Hopefully this will help you (or anyone out there) understand what I trying to accomplish.
... View more
09-12-2013
05:36 AM
|
0
|
0
|
1702
|
POST
|
Stacy, Thanks again. At this point in my development I'm way past testing each stage of what I'm trying to do (although I did do as you asked and tested each piece but had no luck). That's why I'm in the situation that I'm currently in. Maybe it'll help if I explain why I'm having to do all of these steps in just the right method and order. For a few years now, ESRI has not responded to a bug that's been reported multiple times (NIM062177 and NIM063441 - "ExportToPDF using arcpy does not export a layer attribute table embedded in a layout"). They claim that the bug was rejected because it is "beyond the design of the software". However, the ExportToPDF function works fine with layouts without tables. So it appears that it was never fully tested. So, as a result I am trying to work around the bug, and get my layouts with embeded attribute tables to produce PDF files. What I do know is that if I open my MXD manually in ArcMap and Export to a PDF it drops the wireframe around the tables (but produces the data. If I do this through code only, I get no data). However, if I use the Adobe PDF print driver and print to a file, it works. So, from this I know that I have to do the following things in this exact order and timing. 1. Open the MXD in ArcMap 2. Wait for the Layout to fully assemble 3. Print to file using the Adobe PDF print driver 4. Close ArcMap (hopefully) The reason I opted to use a Python AddIn Extension is it can be executed within the ArcMap application, and not through code only (which doesn't work). So as it stands I have 2 Python scripts. One that launches ArcMap, and opens an MXD, and another which runs in the AddIn Extension: Open the MXD in ArcMap: [HTML]import arcpy import subprocess strArcMapPath = r"C:\Program Files (x86)\ArcGIS\Desktop10.1\bin\ArcMap.exe" strMxd = r"D:\Users\Products\PSA Map Updates\Automation\PSA Location Map - Final.mxd" objNewProcess = subprocess.Popen([strArcMapPath, strMxd]) objNewProcess.wait() # this line will wait for the new process to end print "Script completed successfully."[/HTML] Execute Python AddIn Extension: [HTML]import arcpy import pythonaddins import os import time class ExtensionClass1(object): """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def openDocument(self): mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': layers = arcpy.mapping.ListLayers(mxd, "", "Layers"): print layers time.sleep(1) os.system('taskkill /IM Arcmap*') def beforeCloseDocument(self): arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")[/HTML] As ArcMap opens, the AddIn Extension executes another Python script (shown above) which queries the MXD properties for a piece of text "Print to PDF" to determine if the map should be Printed To a PDF. If the Description Property does not meet the query it just opens as usual, if it does, I'd like for it to roll into the PrintMap function which produces the PDF file. The kicker here is that I'm limited to the functions available within the extension class (at least according to the documentation). These functions appear to be run only if a certain event occurs (i.e openDocument, beforeCloseDocument, closeDocument, etc.). That being said I'm trying to figure out a way to execute the "arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")" function inside the extension class as the result of an occurence. When I do this after openDocument, it runs too quickly and the tables do not get added to the PDF correctly. When I try to stall the PrintMap function at openDocument (using ListLayers, time.sleep(), etc.) the actual opening of the file gets stalled. So I opted to try to generate the PDF beforeCloseDocument which is ultimately why I started this thread. I have to programatically close the MXD in order for the PrintMap function to execute. Maybe there's a way to build a custom extension class function that'll do all this, however, my knowledge of Python is limited to what I've been able to do so far. Hopefully this will help you (or anyone out there) understand what I trying to accomplish.
... View more
09-12-2013
05:33 AM
|
0
|
0
|
1702
|
POST
|
Stacy, I think you're on to something. When I test each of the pieces in the Python command window within ArcMap they do as expected. However, linking everything together based on timing is the difficult part. So up until now I've been going with the idea of using a Python AddIn Extension so that my code executes within the MXD after a certain event (i.e openDocument, beforeCloseDocument, closeDocument, and even itemAdded). No matter what I try I can't seem to get my main function "arcpy.mapping.PrintMap" to execute at the right time. I took some of your advice and tried this: [HTML]import arcpy import pythonaddins import os import time class ExtensionClass1(object): """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def openDocument(self): mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': layers = arcpy.mapping.ListLayers(mxd, "", "Layers"): print layers time.sleep(1) os.system('taskkill /IM Arcmap*') def beforeCloseDocument(self): arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")[/HTML] So while opening the MXD it's listing the layers, but the file isn't continuing to open as this process occurs. ArcMap waits until all the layers have been listed before it completely assembles the layout. When I added the os.system('taskkill /IM Arcmap*') it would list all the layers then crush ArcMap before it could execute the arcpy.mapping.PrintMap. It's all about timing, and I can't seem to control when things happen. 😞
... View more
09-11-2013
10:27 AM
|
0
|
0
|
1702
|
POST
|
Mark, thanks for the suggestions. I've tried running the "arcpy.mapping.PrintMap" function in the "def openDocument(self): " function. However, I can't get the process to stall long enough for the layout to fully assemble the tables before the PrintMap executes. What I get are tiny tables, or incomplete ones. I tried to use time.sleep() to pause the script while the MXD is opening, but all that does is pause the open process and not the script. Any ideas how I can properly pause the script while the MXD is opening and assembling?
... View more
09-10-2013
06:46 AM
|
0
|
0
|
1702
|
POST
|
Thanks for the info Stacey. I'm able to get the ArcMap process to teminate using [HTML]os.system('taskkill /IM Arcmap*'[/HTML], but I can't seem to get it to run after a delay. You'll see in my posted code, that I'm using an AddIn Extension that runs as soon as the MXD opens. However, the process executes too soon, and tries to kill ArcMap before the MXD fully opens. When I add time.sleep() or similar it just delays the openeing of the document, not the next part of the script which is the arcpy.mapping.PrintMap function. Because of the limitations with AddIn functions, PrintToPDF has to run before the document closes in order to capture all the tables after they've fully loaded. The whole thing has to be timed just right so that the layout fully assembles, then the PritnToPDF function executes.
... View more
09-10-2013
02:47 AM
|
0
|
0
|
1702
|
POST
|
I've written a couple of Python scripts that open ArcMap, run a Python AddIn Extension, then hopefully close ArcMap. As an MXD document is opened, the AddIn extension runs the [HTML]def beforeCloseDocument(self):[/HTML] function. However I can't seem to figure out how to close ArcMap after the MXD has completely opened. Basically I'm trying to work around a known bug in which the ExportToPDF and PrintMap functions will not work correctly with layouts that have attribute tables embeded in them. Here's the code from my AddIn Extension. Any advice would be much apprciated. I'm hitting a wall here, and just can't seem to get anywhere with this. [HTML]import arcpy import pythonaddins import os import time class ExtensionClass1(object): """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def openDocument(self): mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': #time.sleep(30) #os.system("pause") os.system('taskkill /IM Arcmap*')#is killing it too soon #time.sleep(15) pass def beforeCloseDocument(self): #mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT") pass[/HTML]
... View more
09-09-2013
03:58 AM
|
0
|
15
|
3632
|
POST
|
Matt, Yea I looked at Report Labs a couple of years ago when I first started with this mess. It seemed to be way to complicated just get some tables into a PDF. From what I remember the process involved building the tables piece by piece using graphics (lines) for the wireframe of the table, then inserting dynamic text into the spaces between the lines. In my case I have ten tables in my layout. SO the task would be too difficult. I just wish that afetr several years of users submitting bug reports that ESRI would fix it instead of just rejecting the bug as a known software limitation, and saying that it's out of the scope of design. Obviously it's not.
... View more
09-05-2013
03:02 AM
|
0
|
0
|
609
|
POST
|
Thanks for the suggestion Matt. I tried the arcpy.RefreshActiveView, but it didn't seem to work. With or without it, the PDF will build, however the tables end up printing out about a third of the original size in the PDF. The only way that I've gotten it to work so far is if I run the arcpy.mapping.PrintMap function before the document closes (instead of at open). I just have to figure out how to close the MXD (or ArcMap). I've tried "killing" the app, but it ends up trying to shtudown before the MXD has opened. Even with a time.sleep() added to stall it. import arcpy
import pythonaddins
import os
import time
class ExtensionClass1(object):
"""Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def beforeCloseDocument(self):
#this works but runs before file fully opens
mxd = arcpy.mapping.MapDocument("CURRENT")
if mxd.description == 'Print to PDF':
arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT")
time.sleep(25)
os.system('taskkill /IM Arcmap*')
... View more
09-04-2013
03:09 AM
|
0
|
0
|
609
|
POST
|
OK, well I managed to get the code to execute after the MXD opens using an AddIn Extension. However, the code runs before the MXD can fully assemble the layout. It's running the PrintToPDF function so I need the layout to be complete before it runs so that the PDF generates correctly. I've tried using time.sleep to stall it while the file opens, but that doesn't seem to work. It seems to just stall the actual opening of the file. Anyone have any ideas on how to get the arcpy.mapping.PrintMap function to run after the MXD fully opens, and assembles the map layout? Here's the code I'm trying: import arcpy import pythonaddins import os import time class ExtensionClass1(object): """Implementation for PrintToPDF_AddIn_addin.extension2 (Extension)""" def __init__(self): # For performance considerations, please remove all unused methods in this class. self.enabled = True def openDocument(self): time.sleep(10) mxd = arcpy.mapping.MapDocument("CURRENT") if mxd.description == 'Print to PDF': arcpy.mapping.PrintMap(mxd, r"Adobe PDF", "PAGE_LAYOUT") pass
... View more
09-03-2013
04:47 AM
|
0
|
0
|
609
|
POST
|
Thanks Cosmin, The os.system('taskkill /IM Arcmap*') was what I needed.
... View more
08-29-2013
06:47 AM
|
0
|
0
|
618
|
POST
|
Thanks Jason. That's exactly what I ended up doing yesterday. I wrote a Python AddIn Extension that runs the arcpy.mapping.PrintMap function right before the document closes. This allows the MXD to open and fully assemble the geometry and tables before producing the PDF file. Today I plan to put it all together in one script that opens the MXD, runs the extension to produce the PDF, and closes the MXD. All this will be attached to a scheduled task so that the data and masp are updated on a regular basis. This is a heck of a work around for bugs (NIM062177 and NIM063441). Supposedly my "Ideas" posting about them has to get a lot of attention in order for the issue to be fixed. I'd post the link, but there's no easy way to share (without having to generate yet another account) as far as I can tell. Just search for "Export to PDF Drops Embeded Attribute Tables".
... View more
08-29-2013
02:50 AM
|
0
|
0
|
609
|
POST
|
Is it possible to have Python code execute in ArcMap after an MXD has opened? I have a way to open an MXD through Python, but I then want another piece of code to execute once the MXD file has opened. Any ideas?
... View more
08-28-2013
03:57 AM
|
0
|
9
|
2014
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|