Python Code is running out of order?

247
6
Jump to solution
07-17-2024 08:54 AM
MDPWSB
by
New Contributor II

Hi Everyone! I am in the process of automating a layout and have the code up and running for the most part. The problem I'm having is that although I have the layout exporting to PDF at the end of the code, it seems my layout is exporting before the symbology and title update and I'm not sure why. My code is not in a for loop and the layout updates the symbology and title once the code finishes executing. Any thoughts? Not able to share code. 

0 Kudos
1 Solution

Accepted Solutions
MDPWSB
by
New Contributor II

Hi Cody,

so it seems that all I needed to do was add an aprx.save() at the end of each of those blocks of code for it to work and show on the PDF. So this problem is solved however I have another problem now. Instead of the label in the legend being replaced with the next area I'm mapping in the layout, it just adds the new polygon to the legend with the previous ones. I'm also afraid to keep touching this code lol.

 

 

Edit:

I think I also solved this problem. I think I have to delete each feature layer after each PDF is exported

View solution in original post

6 Replies
CodyPatterson
Regular Contributor

Hey @MDPWSB 

Since you're not able to share code it makes it a little tricky, there is a possibility that the symbology and title may attempting to update, but is updating it to something that could be missed and it is completing "normally". Are there any try except catches in your code that could be passing that portion?

Edit:

If this is in a Notebook, I would try to separate the for loop with static data, and test a single run to ensure that it is doing what it should do. If it is not in a Notebook, you may try using another Python document to attempt and use static data to run this only once with the same data, and have it end with the title change, just to be sure it's not skipping.

Cody

0 Kudos
MDPWSB
by
New Contributor II

Hi Cody,

I am currently running a single block of code, not a for loop. I am using the Python window in ArcGIS Pro. The code shows no errors, but it seems the layout is exported before or faster than it takes the symbology and title to update. I've tried switching the order of commands but to no effect. 

0 Kudos
MDPWSB
by
New Contributor II

I do think you're on to something about it attempting to update but then being missed. As the code runs I see the layer extent changing before the symbology and title are updated, even though I have the symbology and title update prior to the layer extent in the code.

0 Kudos
CodyPatterson
Regular Contributor

Hey @MDPWSB 

I missed that part seemingly about it not being in a for loop, that was my bad. Would it be possible to separate the title and symbology change to its own function and checking if that runs normally?

Cody

0 Kudos
MDPWSB
by
New Contributor II

Hi Cody,

so it seems that all I needed to do was add an aprx.save() at the end of each of those blocks of code for it to work and show on the PDF. So this problem is solved however I have another problem now. Instead of the label in the legend being replaced with the next area I'm mapping in the layout, it just adds the new polygon to the legend with the previous ones. I'm also afraid to keep touching this code lol.

 

 

Edit:

I think I also solved this problem. I think I have to delete each feature layer after each PDF is exported

CodyPatterson
Regular Contributor

Hey @MDPWSB 

Great stuff! Glad you got it fixed!

Cody

0 Kudos