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.
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);
}
}
}
}
});
}
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.
@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.
@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
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
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.
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.
@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.
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.
@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