Set file name programatically before exporting layout

114
3
Jump to solution
2 weeks ago
PrashantKirpan
Occasional Contributor

Hi,

I want to change file name and path programatically while exporting layout. Is there any way to capture export layout button event and change properties before starting process? or access export layout pane and modify values ?

Any help would be appreciated,

Prashant

 

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You have to change the name of the Layout.  I used this snippet below in a button to change the Layout name, which in turn is then used as the default file name.  Just make sure that you don't use invalid file name characters (like ':').

protected override async void OnClick()
{
	Map map = null;
	await QueuedTask.Run(() =>
	{
		var layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(i => i.Name.Equals ("layout", StringComparison.OrdinalIgnoreCase));
		if (layoutItem != null)
		{
			var layout = layoutItem.GetLayout();
			var defLayout = layout.GetDefinition();
			var now = DateTime.Now.TimeOfDay;
			defLayout.Name = $@"msecs - {now.TotalMilliseconds}";
			layout.SetDefinition(defLayout);
		}
	});
}

 

View solution in original post

0 Kudos
3 Replies
MichaelBoyce
Esri Contributor

Hi @PrashantKirpan ,

Quick question...how good is your Python?
The best way to tackle this would be to write your own tool/script.
https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layout-class.htm
That way you can set it to pull the name from, say the name of the current map and use it as the name of the output file.

Hope this helps,

Thanks,

 

Michael

0 Kudos
PrashantKirpan
Occasional Contributor

Hi MichaelBoyce,

I'm good in python but I was trying to avoid rebuilding same export layout UI for just file name.

If there is no way to access export panel or event then I'll create own tool.

Thanks for the reply.

Prashant

 

 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You have to change the name of the Layout.  I used this snippet below in a button to change the Layout name, which in turn is then used as the default file name.  Just make sure that you don't use invalid file name characters (like ':').

protected override async void OnClick()
{
	Map map = null;
	await QueuedTask.Run(() =>
	{
		var layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(i => i.Name.Equals ("layout", StringComparison.OrdinalIgnoreCase));
		if (layoutItem != null)
		{
			var layout = layoutItem.GetLayout();
			var defLayout = layout.GetDefinition();
			var now = DateTime.Now.TimeOfDay;
			defLayout.Name = $@"msecs - {now.TotalMilliseconds}";
			layout.SetDefinition(defLayout);
		}
	});
}

 

View solution in original post

0 Kudos