AnsweredAssumed Answered

Add Layouts in Background to Project/Catalog

Question asked by mjk5000 on Aug 20, 2018
Latest reply on Sep 5, 2018 by jbarrette-esristaff

I want to add some layouts to my project from the code.  I have about 4 different export templates that I plan to use in a project, so if a user wants to export a selected Item, they select export, the code finds the layout from the Project-->Layouts, updates the text/map elements and saves or shows a pdf to the user.

 

The problem, is that i want to add these 4 Layouts to a users project if they don't exist.  I plan on putting the pagx files in the config.x file, then on loading a project I will add them to the layouts for a project if they don't exist.  But when I do this, it "Auto" opens the layout when I use additem or import item from the Project tools.  I just want them to be added in the background?   This code below adds the items to layout, but it also opens up the layout tabs for each, which i don't want.  

 

//1. See if the layouts have been imported to this Project
//Reference all the layout project items
IEnumerable<LayoutProjectItem> layouts = Project.Current.GetItems<LayoutProjectItem>();

//Or reference a specific layout project item by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("CurrentFieldMapHybrid"));

//*************************
//*************************
//THIS BELOW ADDS THE LAYOUT TO THE CATALOG, BUT OPENS UP THE LAYOUT TABS.  I JUST WANT THEM ADDED TO THE LAYOUT CATALOG.  BOTH AddItem AND ImportItem do this
//*************************
//*************************
                //If the layout is null, then import them
                if (layoutItem == null)
                {
                    #region Add new Layout if it doesn't exist

                    await QueuedTask.Run(() =>
                    {
                        //IProjectItem pagx = ItemFactory.Instance.Create(@"xxxxx\CurrentFieldMapHybrid.pagx") as IProjectItem;
                        //Project.Current.AddItem(pagx);

                        IProjectMultiItem pagx = ItemFactory.Instance.Create(@"xxxxx\CurrentFieldMapHybrid.pagx") as IProjectMultiItem;
                        Project.Current.ImportItem(pagx);
                    });

                    #endregion
                }

Outcomes