Select to view content in your preferred language

Layout Picture Element Method SetSourcePath Doesn't Update Picture

1648
14
09-28-2022 09:19 AM
Jimmy_Simpson
Regular Contributor

The layout PictureElement SetSourcePath method only updates the path in element properties, but not the picture in the layout. If you click inside the source path in the element properties, the picture does chance. However I am trying to automate this process across multiple pictures in multiple layouts and this workaround is time consuming.

I have tried forcing the layout to refresh after the update

layoutView.Refresh());

 without success. I also contacted support and they submitted a BUG and someone posted the workaround below:

To refresh the layout and update the pictures, add these lines after changing the layout:

//Force layout refresh var lyt_cim = lyt.GetDefinition(); lyt.SetDefinition(lyt_cim);

I have tried this with the same result - appears visually to do the same things as "Refresh" or just clicking the refresh button at the bottom of the layout.

Anyone have an idea for a workaround? I will add I believe this problem started in 3.0.

0 Kudos
14 Replies
Jimmy_Simpson
Regular Contributor

Below is the code I am using.

		IEnumerable<LayoutProjectItem> layouts = Project.Current.GetItems<LayoutProjectItem>();
            foreach (LayoutProjectItem layoutItem in layouts)
                if (layoutItem != null)
                {
                    await QueuedTask.Run(() =>
                    {
                        Layout layout = layoutItem.GetLayout();
                        if (layout != null)
                        {
                            if (layout.FindElement("Client Logo") is PictureElement picElm)
                            {
                                if (Equals(Module1.LayoutLogo, picElm.SourcePath.ToString()))
                                {
                                }
                                else
                                {
                                    try
                                    {
                                        if (Module1.LayoutLogo != null)
                                        {
                                            picElm.SetSourcePath($@"{Module1.LayoutLogo}");
                                            var lyt_cim = layout.GetDefinition();
                                            layout.SetDefinition(lyt_cim);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Incorrect Client Logo File Path", "Failure", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning);
                                    }
                                }
                            }
                        }
                    });
                }
0 Kudos
JeffBarrette
Esri Regular Contributor

This issue has been addressed and we hope to include it in a 3.0 patch (targeting 3.0.4).  I was able to use the following as a work around to force a refresh.

Layout lyt = LayoutView.Active.Layout;
await QueuedTask.Run(() =>
{
Element elm = lyt.FindElement("Picture");
var pic = elm as PictureElement;
var pic_URL = pic.SourcePath;
string imagePathNew = @"C:\Active\Layout\SDK\BUGS\BUG-000151182\sample.png";
pic.SetSourcePath(imagePathNew);

//Force layout refresh
var lyt_cim = lyt.GetDefinition();
lyt.SetDefinition(lyt_cim);
});

 

 

Jeff - Layout and arcpy.mp teams.

0 Kudos
Jimmy_Simpson
Regular Contributor

@JeffBarrette - Thanks so much for the reply. I am glad to hear it is going to be fixed soon.

As far as your workaround, if you look at my code I have those 2 lines after SetSourcePath and I can confirm that it does in fact refresh the layout, but for me that does not update the picture displayed on the layout. Can you look at my code above and confirm I am not doing anything else wrong that would cause your workaround not to work? The Module1.LayoutLogo variable is just a string that contains the full path of the picture I am trying to update the picture element to.

0 Kudos
JeffBarrette
Esri Regular Contributor

@Jimmy_Simpson I did see your code and support may have given you that information because I provided it to them.  It works for me.  I don't know of another work around.

Jeff

0 Kudos
imrankhadri
Occasional Contributor

I have been using Pro Version 3.0.2 and the issue still persists even after including the below code. Kindly assist

var lyt_cim = lyt.GetDefinition();//not working
lyt.SetDefinition(lyt_cim); //not working

0 Kudos
Jimmy_Simpson
Regular Contributor

I tried again several times and ever tried fresh add-in and new APRX. No go. I think we are just going to have to wait for 3.0.4 or 3.1 for the backend to get fixed. They changed the way they handle pictures in layouts for 3.0 according to the documentation so I'm betting just an oversight on their part. They also updated by BUG report as FIXED with a fixed version of 3.1.

@JeffBarrette - Thank you so much for your assistance. I really appreciate your time and effort.

0 Kudos
KeithAddison1
Frequent Contributor

Pro 3.1, I'm having the same problem.  If I open each picture element individually and click around, it eventually refreshes.  Problem is I have several hundred of these needing refresh.  Code doesn't work.  Should have listened and not upgraded to 3.0.

0 Kudos
Jimmy_Simpson
Regular Contributor

@JeffBarrette - Can you provide any help on this?

I can confirm that the BUG I logged for this issue is on the list as being fixed in version 3.1, but it for sure is not fixed. I have done a couple hours of testing on 3.1 and below is what I have found.

  • SetSourcePath will update the image 90% of the time if the layout is open and active.
  • It will update the image about 50% of the time if the layout is open but not active.
  • If the layout is not open, it will rarely update the image. I have noticed updating the image in maybe 1 closed layout, I believe the last closed layout.
  • Sometimes it will update the image, but when you zoom in and out, the image will switch between the old image and new image depending on zoom scale, even though the source path is still set to the new image. If exported to PDF, it almost always retains the old image.
  • Sometimes when I close and reopen the Pro project, all the images revert back to "old" images. Sometimes even reverts back to images from several changes ago.
  • It appears to be the only for sure way and updating the actual image and making the change stick and print is to click inside the image source path and back out of it, or manually changing the source path.
  • Whatever changes were made for version 3.1 for sure did not fix the issue, and to be honest, have made the issue worse, because now I can never tell if the image is correct or not, since sometimes the image that is displayed is not the image that will print with the layout.
  • I have also tried the above listed "workaround" in version 3.1 and just like in 3.0 I can't tell that it does anything.

I was going to give ESRI support a call today and re-log the BUG. I am just not sure I have to patience to spend a month or so hand holding a level 1 support person and teaching them what I am doing so they can even log the BUG. For me to even get this BUG logged last time was the most ridiculous and time consuming support process I have ever had. Someone who has been using GIS for 15 years shouldn't have to spend a month going back and forth with a level 1 support person just to get a simple BUG logged.

0 Kudos
JeffBarrette
Esri Regular Contributor

@Jimmy_Simpson I'm so sorry to hear your frustration!  I'm moving back to 3.1 final and will try to reproduce the situation.  

Jeff = layout and arcpy.mp teams

0 Kudos