Esempio n. 1
0
        private async void AddFolderToProject(string addFolderPath)
        {
            try
            {
                // Add a folder to the Project
                var folderToAdd = ItemFactory.Instance.Create(addFolderPath);
                await QueuedTask.Run(() => Project.Current.AddItem(folderToAdd as IProjectItem));

                // find the folder project item
                FolderConnectionProjectItem folder = Project.Current.GetItems <FolderConnectionProjectItem>().FirstOrDefault(f => f.Path.Equals(addFolderPath, StringComparison.CurrentCultureIgnoreCase));
                if (folder == null)
                {
                    return;
                }

                // do the search
                IEnumerable <Item> folderFiles = null;
                await QueuedTask.Run(() => folderFiles = folder.GetItems().Where(f => f.Path.EndsWith(Filter, StringComparison.CurrentCultureIgnoreCase)));

                // search MXDs
                lock (_lockMxdItemCollection)
                {
                    _mxdItems.Clear();
                    foreach (var newItem in folderFiles)
                    {
                        _mxdItems.Add(newItem);
                    }
                }
                NotifyPropertyChanged(() => MxdItems);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error adding folder to project: " + ex.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Performs the search
        /// </summary>
        /// <returns>A Task to the search function</returns>
        private async Task Search()
        {
            // reset the results
            SearchResults = null;

            // verify there is a folder
            if (string.IsNullOrEmpty(Folder))
            {
                return;
            }

            // find the folder project item
            FolderConnectionProjectItem folder = Project.Current.GetItems <FolderConnectionProjectItem>().FirstOrDefault(f => f.Path == Folder);

            if (folder == null)
            {
                return;
            }

            // do the search
            IEnumerable <Item> results = await folder.SearchAsync(SearchString);

            // assign to the results variable
            SearchResults = results.ToList();
        }
Esempio n. 3
0
        protected override async void OnClick()
        {
            // add a folder connection
            Item item = ItemFactory.Create(Module1.FolderPath);
            IEnumerable <ProjectItem> folders = await Project.Current.AddAsync(item);

            // double check - ensure it has been created
            FolderConnectionProjectItem folder = folders.First() as FolderConnectionProjectItem;

            if (folder != null)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Folder added " + folder.Path, "Project Items Lab", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
            }
            else
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("No folder added", "Project Items Lab", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
            }
        }
        public async void ContentSnippets2()
        {
            #region Create new project using Pro's default settings
            //Get Pro's default project settings.
            var defaultProjectSettings = Project.GetDefaultProjectSettings();
            //Create a new project using the default project settings
            await Project.CreateAsync(defaultProjectSettings);

            #endregion

            #region New project using a custom template file
            //Settings used to create a new project
            CreateProjectSettings projectSettings = new CreateProjectSettings()
            {
                //Sets the project's name
                Name = "New Project",
                //Path where new project will be stored in
                LocationPath = @"C:\Data\NewProject",
                //Sets the project template that will be used to create the new project
                TemplatePath = @"C:\Data\MyProject1\CustomTemplate.aptx"
            };
            //Create the new project
            await Project.CreateAsync(projectSettings);

            #endregion

            #region Create project using template available with ArcGIS Pro
            //Settings used to create a new project
            CreateProjectSettings proTemplateSettings = new CreateProjectSettings()
            {
                //Sets the project's name
                Name = "New Project",
                //Path where new project will be stored in
                LocationPath = @"C:\Data\NewProject",
                //Select which Pro template you like to use
                TemplateType = TemplateType.Catalog
                               //TemplateType = TemplateType.LocalScene
                               //TemplateType = TemplateType.GlobalScene
                               //TemplateType = TemplateType.Map
            };
            //Create the new project
            await Project.CreateAsync(proTemplateSettings);

            #endregion

            #region Open project
            //Opens an existing project or project package
            await Project.OpenAsync(@"C:\Data\MyProject1\MyProject1.aprx");

            #endregion

            #region Current project
            //Gets the current project
            var project = Project.Current;
            #endregion

            #region Get location of current project
            //Gets the location of the current project; that is, the path to the current project file (*.aprx)
            string projectPath = Project.Current.URI;
            #endregion

            #region Get the project's default gdb path
            var projGDBPath = Project.Current.DefaultGeodatabasePath;
            #endregion

            #region Save project
            //Saves the project
            await Project.Current.SaveAsync();

            #endregion

            #region SaveAs project
            //Saves a copy of the current project file (*.aprx) to the specified location with the specified file name,
            //then opens the new project file
            await Project.Current.SaveAsAsync(@"C:\Data\MyProject1\MyNewProject1.aprx");

            #endregion

            #region Close project
            //A project cannot be closed using the ArcGIS Pro API.
            //A project is only closed when another project is opened, a new one is created, or the application is shutdown.
            #endregion

            #region Adds item to the current project
            //Adding a folder connection
            string folderPath = "@C:\\myDataFolder";
            var    folder     = await QueuedTask.Run(() => {
                //Create the folder connection project item
                var item = ItemFactory.Instance.Create(folderPath) as IProjectItem;
                //If it is succesfully added to the project, return it otherwise null
                return(Project.Current.AddItem(item) ? item as FolderConnectionProjectItem : null);
            });

            //Adding a Geodatabase:
            string gdbPath       = "@C:\\myDataFolder\\myData.gdb";
            var    newlyAddedGDB = await QueuedTask.Run(() => {
                //Create the File GDB project item
                var item = ItemFactory.Instance.Create(gdbPath) as IProjectItem;
                //If it is succesfully added to the project, return it otherwise null
                return(Project.Current.AddItem(item) ? item as GDBProjectItem : null);
            });

            #endregion

            #region How to add a new map to a project
            await QueuedTask.Run(() =>
            {
                //Note: see also MapFactory in ArcGIS.Desktop.Mapping
                var map = MapFactory.Instance.CreateMap("New Map", MapType.Map, MapViewingMode.Map, Basemap.Oceans);
                ProApp.Panes.CreateMapPaneAsync(map);
            });

            #endregion

            #region Check if project needs to be saved
            //The project's dirty state indicates changes made to the project have not yet been saved.
            bool isProjectDirty = Project.Current.IsDirty;
            #endregion

            #region Get all the project items
            IEnumerable <Item> allProjectItems = Project.Current.GetItems <Item>();
            foreach (var pi in allProjectItems)
            {
                //Do Something
            }
            #endregion

            #region Gets all the "MapProjectItems"
            IEnumerable <MapProjectItem> newMapItemsContainer = project.GetItems <MapProjectItem>();

            await QueuedTask.Run(() =>
            {
                foreach (var mp in newMapItemsContainer)
                {
                    //Do Something with the map. For Example:
                    Map myMap = mp.GetMap();
                }
            });

            #endregion

            #region Gets a specific "MapProjectItem"
            MapProjectItem mapProjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("EuropeMap"));
            #endregion

            #region Gets all the "StyleProjectItems"
            IEnumerable <StyleProjectItem> newStyleItemsContainer = null;
            newStyleItemsContainer = Project.Current.GetItems <StyleProjectItem>();
            foreach (var styleItem in newStyleItemsContainer)
            {
                //Do Something with the style.
            }
            #endregion

            #region Gets a specific "StyleProjectItem"
            var container = Project.Current.GetItems <StyleProjectItem>();
            StyleProjectItem testStyle = container.FirstOrDefault(style => (style.Name == "ArcGIS 3D"));
            StyleItem        cone      = null;
            if (testStyle != null)
            {
                cone = testStyle.LookupItem(StyleItemType.PointSymbol, "Cone_Volume_3");
            }
            #endregion

            #region Gets all the "GDBProjectItems"
            IEnumerable <GDBProjectItem> newGDBItemsContainer = null;
            newGDBItemsContainer = Project.Current.GetItems <GDBProjectItem>();
            foreach (var GDBItem in newGDBItemsContainer)
            {
                //Do Something with the GDB.
            }
            #endregion

            #region Gets a specific "GDBProjectItem"
            GDBProjectItem GDBProjItem = Project.Current.GetItems <GDBProjectItem>().FirstOrDefault(item => item.Name.Equals("myGDB"));
            #endregion

            #region Gets all the "ServerConnectionProjectItem"
            IEnumerable <ServerConnectionProjectItem> newServerConnections = null;
            newServerConnections = project.GetItems <ServerConnectionProjectItem>();
            foreach (var serverItem in newServerConnections)
            {
                //Do Something with the server connection.
            }
            #endregion

            #region Gets a specific "ServerConnectionProjectItem"
            ServerConnectionProjectItem serverProjItem = Project.Current.GetItems <ServerConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myServer"));
            #endregion

            #region Gets all folder connections in a project
            //Gets all the folder connections in the current project
            var projectFolders = Project.Current.GetItems <FolderConnectionProjectItem>();
            foreach (var FolderItem in projectFolders)
            {
                //Do Something with the Folder connection.
            }
            #endregion

            #region Gets a specific folder connection
            //Gets a specific folder connection in the current project
            FolderConnectionProjectItem myProjectFolder = Project.Current.GetItems <FolderConnectionProjectItem>().FirstOrDefault(folderPI => folderPI.Name.Equals("myDataFolder"));
            #endregion

            #region Remove a specific folder connection
            // Remove a folder connection from a project; the folder stored on the local disk or the network is not deleted
            FolderConnectionProjectItem folderToRemove = Project.Current.GetItems <FolderConnectionProjectItem>().FirstOrDefault(myfolder => myfolder.Name.Equals("PlantSpecies"));
            if (folderToRemove != null)
            {
                Project.Current.RemoveItem(folderToRemove as IProjectItem);
            }
            #endregion

            #region Gets a specific "LayoutProjectItem"
            LayoutProjectItem layoutProjItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("myLayout"));
            #endregion

            #region Gets all layouts in a project:
            //Gets all the layouts in the current project
            var projectLayouts = Project.Current.GetItems <LayoutProjectItem>();
            foreach (var layoutItem in projectLayouts)
            {
                //Do Something with the layout
            }
            #endregion

            #region Gets a specific "GeoprocessingProjectItem"
            GeoprocessingProjectItem GPProjItem = Project.Current.GetItems <GeoprocessingProjectItem>().FirstOrDefault(item => item.Name.Equals("myToolbox"));
            #endregion

            #region Gets all GeoprocessingProjectItems in a project:
            //Gets all the GeoprocessingProjectItem in the current project
            var GPItems = Project.Current.GetItems <GeoprocessingProjectItem>();
            foreach (var tbx in GPItems)
            {
                //Do Something with the toolbox
            }
            #endregion

            #region Search project for a specific item
            List <Item> _mxd = new List <Item>();
            //Gets all the folder connections in the current project
            var allFoldersItem = Project.Current.GetItems <FolderConnectionProjectItem>();
            if (allFoldersItem != null)
            {
                //iterate through all the FolderConnectionProjectItems found
                foreach (var folderItem in allFoldersItem)
                {
                    //Search for mxd files in that folder connection and add it to the List<T>
                    //Note:ArcGIS Pro automatically creates and dynamically updates a searchable index as you build and work with projects.
                    //Items are indexed when they are added to a project.
                    //The first time a folder or database is indexed, indexing may take a while if it contains a large number of items.
                    //While the index is being created, searches will not return any results.
                    _mxd.AddRange(folderItem.GetItems());
                }
            }
            #endregion

            #region Get the Default Project Folder

            var defaultProjectPath = System.IO.Path.Combine(
                System.Environment.GetFolderPath(
                    Environment.SpecialFolder.MyDocuments),
                @"ArcGIS\Projects");

            #endregion
        }
Esempio n. 5
0
        /// <summary>
        /// Sample code for ProjectItem
        /// </summary>
        public async Task ProjectItemExamples()
        {
            // not to be included in sample regions
            var projectFolderConnection = (Project.Current.GetItems <FolderConnectionProjectItem>()).First();

            #region GetMapProjectItems

            /// Get all the maps in a project
            IEnumerable <MapProjectItem> projectMaps = Project.Current.GetItems <MapProjectItem>();

            #endregion //GetMapProjectItems

            #region GetFolderConnectionProjectItems

            /// Get all the folder connections in a project
            IEnumerable <FolderConnectionProjectItem> projectFolders = Project.Current.GetItems <FolderConnectionProjectItem>();

            #endregion //GetFolderConnectiontProjectItems

            #region GetServerConnectionProjectItems

            /// Get all the server connections in a project
            IEnumerable <ServerConnectionProjectItem> projectServers = Project.Current.GetItems <ServerConnectionProjectItem>();

            #endregion //GetServerConnectionProjectItems

            #region GetLocatorConnectionProjectItems

            /// Get all the locator connections in a project
            IEnumerable <LocatorsConnectionProjectItem> projectLocators = Project.Current.GetItems <LocatorsConnectionProjectItem>();

            #endregion //GetLocatorConnectionProjectItems


            #region GetProjectItemContent

            /// Get all the items that can be accessed from a folder connection. The items immediately
            /// contained by a folder, that is, the folder's children, are returned including folders
            /// and individual items that can be used in ArcGIS Pro. This method does not return all
            /// items contained by any sub-folder that can be accessed from the folder connection.
            FolderConnectionProjectItem folderConnection = Project.Current.GetItems <FolderConnectionProjectItem>()
                                                           .FirstOrDefault((folder => folder.Name.Equals("Data")));
            await QueuedTask.Run(() =>
            {
                IEnumerable <Item> folderContents = folderConnection.GetItems();
            });

            #endregion //GetProjectItems

            #region AddFolderConnectionProjectItem

            /// Add a folder connection to a project
            Item folderToAdd = ItemFactory.Instance.Create(@"C:\Data\Oregon\Counties\Streets");
            bool wasAdded    = await QueuedTask.Run(() => Project.Current.AddItem(folderToAdd as IProjectItem));

            #endregion //AddFolderConnectionProjectItem

            #region AddGDBProjectItem

            /// Add a file geodatabase or a SQLite or enterprise database connection to a project
            Item gdbToAdd         = folderToAdd.GetItems().FirstOrDefault(folderItem => folderItem.Name.Equals("CountyData.gdb"));
            var  addedGeodatabase = await QueuedTask.Run(() => Project.Current.AddItem(gdbToAdd as IProjectItem));

            #endregion //AddGDBProjectItem



            #region RemoveFolderConnectionFromProject

            /// Remove a folder connection from a project; the folder stored on the local disk
            /// or the network is not deleted
            FolderConnectionProjectItem folderToRemove = Project.Current.GetItems <FolderConnectionProjectItem>().FirstOrDefault(folder => folder.Name.Equals("PlantSpecies"));
            if (folderToRemove != null)
            {
                Project.Current.RemoveItem(folderToRemove as IProjectItem);
            }

            #endregion //RemoveFolderConnectionFromProject

            #region RemoveMapFromProject

            /// Remove a map from a project; the map is deleted
            IProjectItem mapToRemove           = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(map => map.Name.Equals("OldStreetRoutes"));
            var          removedMapProjectItem = await QueuedTask.Run(
                () => Project.Current.RemoveItem(mapToRemove));

            #endregion //RemoveMapFromProject



            #region ImportToProject

            /// Import a mxd
            Item mxdToImport = ItemFactory.Instance.Create(@"C:\Projects\RegionalSurvey\LatestResults.mxd");
            var  addedMxd    = await QueuedTask.Run(
                () => Project.Current.AddItem(mxdToImport as IProjectItem));

            /// Add map package
            Item mapPackageToAdd = ItemFactory.Instance.Create(@"c:\Data\Map.mpkx");
            var  addedMapPackage = await QueuedTask.Run(
                () => Project.Current.AddItem(mapPackageToAdd as IProjectItem));

            /// Add an exported Pro map
            Item proMapToAdd         = ItemFactory.Instance.Create(@"C:\ExportedMaps\Election\Districts.mapx");
            var  addedMapProjectItem = await QueuedTask.Run(
                () => Project.Current.AddItem(proMapToAdd as IProjectItem));

            #endregion //ImportToProject
        }