async public static Task <Layout> CreateCIMLayout(double width, double height, LinearUnit units, string LayoutName) { Layout CIMlayout = null; await QueuedTask.Run(() => { //Set up a page CIMPage newPage = new CIMPage(); //required newPage.Width = width; newPage.Height = height; newPage.Units = units; //optional rulers newPage.ShowRulers = true; newPage.SmallestRulerDivision = 5; //optional guides newPage.ShowGuides = true; CIMGuide guide1 = new CIMGuide(); guide1.Position = 25; guide1.Orientation = Orientation.Vertical; CIMGuide guide2 = new CIMGuide(); guide2.Position = 185; guide2.Orientation = Orientation.Vertical; CIMGuide guide3 = new CIMGuide(); guide3.Position = 25; guide3.Orientation = Orientation.Horizontal; CIMGuide guide4 = new CIMGuide(); guide4.Position = 272; guide4.Orientation = Orientation.Horizontal; List <CIMGuide> guideList = new List <CIMGuide>(); guideList.Add(guide1); guideList.Add(guide2); guideList.Add(guide3); guideList.Add(guide4); newPage.Guides = guideList.ToArray(); Layout layout = LayoutFactory.Instance.CreateLayout(newPage); layout.SetName(LayoutName); }); //Open the layout in a pane await ProApp.Panes.CreateLayoutPaneAsync(CIMlayout); return(CIMlayout); }
async public void snippets_ProjectItems() { #region Reference layout project items //A layout project item is an item that appears in the Layouts folder in the Catalog pane //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("MyLayout")); #endregion #region Open a layout project item in a new view //A layout project item may be in a project but it may not be open in a view and/or active //First get the layout associated with the layout project item Layout layout = layoutItem.GetLayout(); //Open a new pane ILayoutPane iNewLayoutPane = await ProApp.Panes.CreateLayoutPaneAsync(layout); #endregion #region Activate an already open layout view //A layout view may exist but it may not be active //Iterate through each pane in the application and check to see if the layout is already open and if so, activate it foreach (var pane in ProApp.Panes) { var layoutPane = pane as ILayoutPane; if (layoutPane == null) //if not a layout view, continue to the next pane { continue; } if (layoutPane.LayoutView.Layout == layout) //if there is a match, activate the view { (layoutPane as Pane).Activate(); return; } } #endregion #region Reference the active layout view //First check to see if the current, active view is a layout view. If it is, use it LayoutView activeLayoutView = LayoutView.Active; if (activeLayoutView != null) { // use activeLayoutView } #endregion #region Create a new, basic layout and open it //Create a new layout project item layout in the project Layout newLayout = await QueuedTask.Run <Layout>(() => { newLayout = LayoutFactory.Instance.CreateLayout(8.5, 11, LinearUnit.Inches); newLayout.SetName("New 8.5x11 Layout"); return(newLayout); }); //Open new layout on the GUI thread await ProApp.Panes.CreateLayoutPaneAsync(newLayout); #endregion #region Create a new layout using a modified CIM and open it //Create a new layout project item layout in the project Layout newCIMLayout = await QueuedTask.Run <Layout>(() => { //Set up a CIM page CIMPage newPage = new CIMPage { //required parameters Width = 8.5, Height = 11, Units = LinearUnit.Inches, //optional rulers ShowRulers = true, SmallestRulerDivision = 0.5, //optional guides ShowGuides = true }; CIMGuide guide1 = new CIMGuide { Position = 1, Orientation = Orientation.Vertical }; CIMGuide guide2 = new CIMGuide { Position = 6.5, Orientation = Orientation.Vertical }; CIMGuide guide3 = new CIMGuide { Position = 1, Orientation = Orientation.Horizontal }; CIMGuide guide4 = new CIMGuide { Position = 10, Orientation = Orientation.Horizontal }; List <CIMGuide> guideList = new List <CIMGuide> { guide1, guide2, guide3, guide4 }; newPage.Guides = guideList.ToArray(); //Create a new page newCIMLayout = LayoutFactory.Instance.CreateLayout(newPage); newCIMLayout.SetName("New 8.5x11 Layout"); return(newCIMLayout); }); //Open new layout on the GUI thread await ProApp.Panes.CreateLayoutPaneAsync(newCIMLayout); #endregion #region Import a pagx into a project //Create a layout project item from importing a pagx file IProjectItem pagx = ItemFactory.Instance.Create(@"C:\Temp\Layout.pagx") as IProjectItem; Project.Current.AddItem(pagx); #endregion #region Remove a layout project item //Remove a layout from the project completely Project.Current.RemoveItem(layoutItem); #endregion }