change programmatically orientation of page layout c#

552
1
Jump to solution
12-16-2022 12:15 PM
Ruben_DarioCalero_Clavijo
New Contributor II

Hello, Esri Team

I trying to create programmatically in ArcGIS Pro SDK C#, a Button that create and open a Page Layout ; I already could create and open the page layout but I can’t find the code to change the Page orientation (Portrait, landscape) in the classes (CIMPage Class, Layout Class, LayoutFactory Class).

Does exist some class that I can use to change the orientation property of the Page Layout?.

My code:

 

protected override async void OnClick()
{

Layout newLayout = await QueuedTask.Run<Layout>(() =>
            {
                // Create a new CIM page
                CIMPage newPage = new CIMPage();

                // Add properties
                newPage.Width = 17;
                newPage.Height = 11;
                newPage.Units = LinearUnit.Inches;

                // Add rulers
                newPage.ShowRulers = true;
                newPage.SmallestRulerDivision = 0.5;
                              
                // Apply the CIM page to a new layout and set name
                newLayout = LayoutFactory.Instance.CreateLayout(newPage);
                newLayout.SetName("Layout Carta");
                
                return newLayout;
            });

            var layoutPane = await ProApp.Panes.CreateLayoutPaneAsync(newLayout);

            MessageBox.Show("Layout Creado.");

        }

 

 

Thanks

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

To change page orientation set the page height to the page width and the width to the height.

You then have two choices:

Set the changed page back on the layout and resize all page content to "fit" on the changed page orientation - or - (edit - this option is available at 3.1)

Resize the page and leave page content "as is" - potentially page content may no longer fit on the page after a page resize but their dimensions and positions are unchanged (this option is available at 3.0 and 2.x)

Here's a snippet u can fiddle with:

 

private void SwitchPageOrientation() {

 if (LayoutView.Active == null)
   return;
 var layout = LayoutView.Active.Layout;
     
 QueuedTask.Run(() => {
   var page = layout.GetPage();
   //what is the orientation?
   var orientation = page.Height > page.Width ? PageOrientation.Portrait :
           PageOrientation.Landscape;
   //TODO - use orientation as needed

   //switch portrait->landscape or vice versa
   var wd = page.Width;
   var ht = page.Height;

   page.Height = wd;
   page.Width = ht;

   //Available at 3.1
   layout.SetPage(page, true);//resize the page elements
   //Available at 3.0 and 2.x
   //layout.SetPage(page);<-- use this flavor for no element resizing
   //layout.SetPage(page, false);<-- or set the resize flag false
 });
}

 

 

 

View solution in original post

0 Kudos
1 Reply
CharlesMacleod
Esri Regular Contributor

To change page orientation set the page height to the page width and the width to the height.

You then have two choices:

Set the changed page back on the layout and resize all page content to "fit" on the changed page orientation - or - (edit - this option is available at 3.1)

Resize the page and leave page content "as is" - potentially page content may no longer fit on the page after a page resize but their dimensions and positions are unchanged (this option is available at 3.0 and 2.x)

Here's a snippet u can fiddle with:

 

private void SwitchPageOrientation() {

 if (LayoutView.Active == null)
   return;
 var layout = LayoutView.Active.Layout;
     
 QueuedTask.Run(() => {
   var page = layout.GetPage();
   //what is the orientation?
   var orientation = page.Height > page.Width ? PageOrientation.Portrait :
           PageOrientation.Landscape;
   //TODO - use orientation as needed

   //switch portrait->landscape or vice versa
   var wd = page.Width;
   var ht = page.Height;

   page.Height = wd;
   page.Width = ht;

   //Available at 3.1
   layout.SetPage(page, true);//resize the page elements
   //Available at 3.0 and 2.x
   //layout.SetPage(page);<-- use this flavor for no element resizing
   //layout.SetPage(page, false);<-- or set the resize flag false
 });
}

 

 

 

0 Kudos