Gets all the presentation items in the current project
varprojectPresentations=Project.Current.GetItems<PresentationProjectItem>();foreach(varprojectIteminprojectPresentations){//Do Something with the presentation}
Reference an existing presentation
//Reference a presentation associated with an active presentation viewPresentationViewactivePresentationView=PresentationView.Active;if(activePresentationView!=null){Presentationpresentation=activePresentationView.Presentation;}
//Open a presentation project item in a new view.//A presentation project item may exist but it may not be open in a view. //Reference a presentation project item by namePresentationProjectItempresentationPrjItem=Project.Current.GetItems<PresentationProjectItem>().FirstOrDefault(item =>item.Name.Equals(presentationName));//Get the presentation associated with the presentation project itemPresentationpresentationToOpen=awaitQueuedTask.Run(()=>presentationPrjItem.GetPresentation());//Create the new paneIPresentationPaneiNewPresentationPane=awaitProApp.Panes.CreatePresentationPaneAsync(presentationToOpen);//GUI thread
Create and export Presentation
Create presentation
//Note: Call within QueuedTask.Run()awaitQueuedTask.Run(()=>{//Create a new presentation without parametersvarpresentation=PresentationFactory.Instance.CreatePresentation();// Use the new Presentation// Create a presentation specifying the name of the new presentationpresentation=PresentationFactory.Instance.CreatePresentation("New Presentation");// Use the new Presentation});
Export a presentation
//Note: Call within QueuedTask.Run()awaitQueuedTask.Run(()=>{//Create mp4 format with appropriate settingsMP4VideoFormatmp4Format=newMP4VideoFormat();mp4Format.Width=800;mp4Format.Height=600;mp4Format.OutputFileName=@"my folder\presentation.mp4";//Define Export OptionsPresentationExportOptionsoptions=newPresentationExportOptions{PageRangeOption=ExportPageOptions.ExportByPageRange,CustomPages="1,2,8"};//export as mp4presentation.Export(mp4Format,options);});
Presentation View
Activate a presentation view
//Assume we want to open a view for a particular presentation or activate a view if one is already open//A presentation project item is an item that appears in the Presentation folder in the Catalog pane.PresentationProjectItempresentationItem=Project.Current.GetItems<PresentationProjectItem>().FirstOrDefault(item =>item.Name.Equals(presentationName));//Reference a presentation associated with a presentation project itemif(presentationItem!=null){//Get the presentation associated with the presentationItemPresentationpresentationToOpen=awaitQueuedTask.Run(()=>presentationItem.GetPresentation());//Next check to see if a presentation view is already open that references the presentationforeach(varpaneinProApp.Panes){varprePane=paneasIPresentationPane;if(prePane==null)// Not a presentation view, continue to the next panecontinue;//if there is a match, activate the viewif(prePane.PresentationView.Presentation==presentationToOpen){(prePaneasPane).Activate();return;}}//No pane found, activate a new one - must be called on UIIPresentationPaneiNewPresentationPane=awaitProApp.Panes.CreatePresentationPaneAsync(presentationToOpen);//GUI thread}
Presentation Page
Blank page
//Note: Call within QueuedTask.Run()Presentationpresentation=PresentationView.Active.Presentation;//Must be on QueuedTaskawaitQueuedTask.Run(()=>{// add a blank page with with title and paragraph body text elementpresentation.AddBlankPage(BlankPageTemplateType.TitleAndParagraph,-1);});
Image page
//Must be on QueuedTaskawaitQueuedTask.Run(()=>{// add a new image page in current active presentationvarimagePage=presentation.AddImagePage("my image source",-1);// change the image sourceimagePage.SetImageSource("new image source");});
Video page
//Must be on QueuedTaskawaitQueuedTask.Run(()=>{// add a new video page in current active presentationvarvideoPage=presentation.AddVideoPage("my video file",-1);// change the image sourcevideoPage.SetVideoSource("new video source");// change the start time of video to 3svideoPage.SetStartTime(3.0);// change the end time of video to 10svideoPage.SetEndTime(10.0);});
Map page
//Must be on QueuedTaskawaitQueuedTask.Run(()=>{// retrieve a map from the project based on the map nameMapProjectItemmpi=Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m =>m.Name.Equals("Your Map Name",StringComparison.CurrentCultureIgnoreCase));Mapmap=mpi.GetMap();//create a map page using map's default extentpresentation.AddMapPage(map,-1);//create a page using map's bookmarkBookmarkbookmark=map.GetBookmarks().FirstOrDefault(
b =>b.Name=="Your bookmark");// get the bookmark based on the bookmark's namepresentation.AddMapPage(bookmark,-1);});
Map Page
Change map page camera settings
//Must be on the QueuedTaskawaitQueuedTask.Run(()=>{//Reference a map pagevarmpage=activePresentationView.Presentation.GetPage(4)asMapPresentationPage;//Set the map frame extent based on the new camera's X,Y, Scale and heading valuesCameracam=newCamera(329997.6648,6248553.1457,2403605.8968,24);mpage.SetCamera(cam);});
Zoom map page to extent of a single layer
//Must be on the QueuedTaskawaitQueuedTask.Run(()=>{//Reference map pagevarmpage=activePresentationView.Presentation.GetPage(4)asMapPresentationPage;//Reference map and layerMapProjectItemmp=Project.Current.FindItem("Page name")asMapProjectItem;Mapmap=mp.GetMap();FeatureLayerlyr=map.FindLayers("GreatLakes").First()asFeatureLayer;//Set the map frame extent to all features in the layermpage.SetCamera(lyr);});
Activate a map page
// Note: we are on the UI thread!// A presentation view must be activeif(PresentationView.Active==null)return;PresentationPageactivePage=activePresentationView.ActivePage;//check if the current page is a map pageif(activePageisMapPresentationPage){awaitactivePresentationView.ActivateMapPageAsync();}//move to the QueuedTask to do somethingawaitQueuedTask.Run(()=>{// TODO});
Presentation page design
// create customized margin and color CIMMarginpMargin=newCIMMargin(){Left=0.2,Right=0.3,Top=0.15,Bottom=0.25};CIMRGBColorpColor=newCIMRGBColor(){R=255,G=255,B=0,Alpha=50};//Reference a page and its transition varpage=activePresentationView.Presentation.GetPage(0);CIMPresentationTransitiontransition=page.Transition;// update the transition styletransition.TransitionType=PresentationTransitionType.Swipe;transition.Duration=2.0;transition.SwipeDirection=SwipeDirection.Top;//Must be on the QueuedTaskawaitQueuedTask.Run(()=>{//Set the new margin, new background color and new transition effectpage.SetMargin(pMargin);page.SetBackgroundColor(pColor);page.SetTransition(transition);});
Elements in presentations
Create elements on a presentation page
//Must be on QueuedTaskawaitQueuedTask.Run(()=>{//create a picture elementvarimgPath=@"https://www.esri.com/content/dam/esrisites/en-us/home/"+"homepage-tile-podcast-business-resilience-climate-change.jpg";//Build a geometry to place the pictureCoordinate2Dll=newCoordinate2D(3.5,1);Coordinate2Dur=newCoordinate2D(6,5);Envelopeenv=EnvelopeBuilderEx.CreateEnvelope(ll,ur);//create a picture element on the pagevargElement=PresentationElementFactory.Instance.CreatePictureGraphicElement(page,env,imgPath);//create a text element//Set symbology, create and add element to a presentation pageCIMTextSymbolsym=SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.RedRGB,15,"Arial","Regular");//use ElementInfo to set placement propertiesvarelemInfo=newElementInfo(){Anchor=Anchor.CenterPoint,Rotation=45};stringtextString="My text";vartextPos=newCoordinate2D(5,3).ToMapPoint();vartElement=PresentationElementFactory.Instance.CreateTextGraphicElement(page,TextType.PointText,textPos,sym,textString,"telement",false,elemInfo);//create a group element with elements created abovevarelmList=newList<Element>{gElement,tElement};GroupElementgrp1=PresentationElementFactory.Instance.CreateGroupElement(page,elmList,"My Group");});
Element selection and navigation
//Must be on QueuedTaskawaitQueuedTask.Run(()=>{// Find specific elements by namevarge_rect=page.FindElement("Rectangle")asGraphicElement;varelements=newList<string>();elements.Add("Text");elements.Add("Polygon");varelems=page.FindElements(elements);//Get elements retaining hierarchyvartop_level_elems=page.GetElements();//Flatten hierarchyvarall_elems=page.GetFlattenedElements();//Use LINQ with any of the collections//Retrieve just those elements that are Visiblevarsome_elems=all_elems.Where(ge =>ge.IsVisible).ToList();});
Element selection manipulation
//Must be on QueuedTaskawaitQueuedTask.Run(()=>{//Select/unselect some elements...varelems=activePage.GetFlattenedElements();//select any element not a group elementactivePage.SelectElements(elems.Where(e =>!e.Name.StartsWith("Group")));activePage.UnSelectElements(elems.Where(e =>!e.Name.StartsWith("Group")));//Select/unselect all visible, graphic elementsvarge_elems=elems.Where(ge =>ge.IsVisible).ToList();activePage.SelectElements(ge_elems);activePage.UnSelectElements(ge_elems);//Select/unselect a specific elementvarna=activePage.FindElement("My Text Element");activePage.SelectElement(na);activePage.UnSelectElement(na);//Select everythingactivePage.SelectElements(elems);//enumerate the selected elementsforeach(varsel_eleminactivePage.GetSelectedElements()){//TODO}});
Presentation events
Detect changes to the presentation
ArcGIS.Desktop.Presentations.Events.PresentationEvent.Subscribe((args)=>{varpresentation=args.Presentation;//The presentation that was changed//Check what triggered the event and take appropriate actionswitch(args.Hint){casePresentationEventHint.PropertyChanged://TODO handle presentation property changedbreak;casePresentationEventHint.PageAdded://TODO handle a new page addedbreak;casePresentationEventHint.PageRemoved://TODO handle a page removed from the presentationbreak;casePresentationEventHint.PageSettingChanged://TODO handle page settings changedbreak;}});
Detect changes to the presentation view
//For UI context changes associated with a presentation, subscribe to the PresentationView//event - views activated/deactivated, views opened/closedArcGIS.Desktop.Presentations.Events.PresentationViewEvent.Subscribe((args)=>{//get the affected view and presentationvarview=args.PresentationView;varpresentation=args.PresentationView?.Presentation;if(presentation==null){//FYI presentationview and/or presentation can be null...//eg closed, deactivation}//Check what triggered the event and take appropriate actionswitch(args.Hint){casePresentationViewEventHint.Activated:// Presentation view activatedbreak;casePresentationViewEventHint.Opened://A PresentationView has been initialized and openedbreak;casePresentationViewEventHint.Deactivated:// Presentation view deactivatedbreak;casePresentationViewEventHint.Closing://Set args.Cancel = true to prevent closingbreak;casePresentationViewEventHint.ExtentChanged://presentation view extent has changedbreak;casePresentationViewEventHint.DrawingComplete:break;casePresentationViewEventHint.PauseDrawingChanged:break;}});