-
Notifications
You must be signed in to change notification settings - Fork 120
ProSnippets Content
Language: C#
Subject: Content
Contributor: ArcGIS Pro SDK Team <[email protected]>
Organization: Esri, http://www.esri.com
Date: 7/13/2015
ArcGIS Pro: 1.1
Visual Studio: 2013, 2015
##New project
//Create an empty project. The project will be created in the default folder
//It will be named MyProject1, MyProject2, or similar...
await Project.CreateAsync();
##New project with specified name
//Settings used to create a new project
CreateProjectSettings projectSettings = new CreateProjectSettings();
//Sets the name of the project that will be created
projectSettings.Name = @"C:\Data\MyProject1\MyProject1.aprx";
//Create the new project
await Project.CreateAsync(projectSettings);
##New project using a particular template
//Settings used to create a new project
CreateProjectSettings projectSettings = new CreateProjectSettings();
//Sets the project template that will be used to create the new project
projectSettings.TemplatePath = @"C:\Data\MyProject1\CustomTemplate.aptx";
//Create the new project
await Project.CreateAsync(projectSettings);
##Open project
//Opens an existing project or project package
await Project.OpenAsync(@"C:\Data\MyProject1\MyProject1.aprx");
##Current project
//Gets the current project
var project = Project.Current;
##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;
##Get the project's default gdb path
var projGDBPath = Project.Current.DefaultGeodatabasePath;
##Save project
//Saves the project
await Project.Current.SaveAsync();
##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");
##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.
##Adds item to the current project
//Adding a folder connection
string folderPath = "@C:\\myDataFolder";
var folder = await Project.Current.AddAsync(ItemFactory.Create(folderPath));
//Adding a Geodatabase:
string gdbPath = "@C:\\myDataFolder\\myData.gdb";
var newlyAddedGDB = await Project.Current.AddAsync(ItemFactory.Create(gdbPath));
##How to add a new map to a project
await QueuedTask.Run(() =>
{
var map = MapFactory.CreateMap("New Map", ArcGIS.Core.CIM.MapType.Map, ArcGIS.Core.CIM.MapViewingMode.Map, Basemap.Oceans);
ProApp.Panes.CreateMapPaneAsync(map);
});
##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;
##Get all the project items
IEnumerable<ProjectItem> allProjectItems = Project.Current.GetItems<ProjectItem>();
foreach (var pi in allProjectItems)
{
//Do Something
}
##Gets all the "MapProjectItems"
IEnumerable<MapProjectItem> newMapItemsContainer = project.GetItems<MapProjectItem>();
foreach (var mp in newMapItemsContainer)
{
//Do Something with the map. For Example:
await QueuedTask.Run(() =>
{
Map myMap = mp.GetMap();
});
}
##Gets a specific "MapProjectItem"
MapProjectItem mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("EuropeMap"));
##Gets all the "StyleProjectItems"
IEnumerable<StyleProjectItem> newStyleItemsContainer = null;
newStyleItemsContainer = Project.Current.GetItems<StyleProjectItem>();
foreach (var styleItem in newStyleItemsContainer)
{
//Do Something with the style.
}
##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");
##Gets all the "GDBProjectItems"
IEnumerable<GDBProjectItem> newGDBItemsContainer = null;
newGDBItemsContainer = Project.Current.GetItems<GDBProjectItem>();
foreach (var GDBItem in newGDBItemsContainer)
{
//Do Something with the GDB.
}
##Gets a specific "GDBProjectItem"
GDBProjectItem GDBProjItem = Project.Current.GetItems<GDBProjectItem>().FirstOrDefault(item => item.Name.Equals("myGDB"));
##Gets all the "ServerConnectionProjectItem"
IEnumerable<ServerConnectionProjectItem> newServerConnections = null;
newServerConnections = project.GetItems<ServerConnectionProjectItem>();
foreach (var serverItem in newServerConnections)
{
//Do Something with the server connection.
}
##Gets a specific "ServerConnectionProjectItem"
ServerConnectionProjectItem serverProjItem = Project.Current.GetItems<ServerConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myServer"));
##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.
}
##Gets a specific folder connection
//Gets a specific folder connection in the current project
ProjectItem myProjectFolder = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(folderPI => folderPI.Name.Equals("myDataFolder"));
##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)
await Project.Current.RemoveAsync(folderToRemove);
##Gets a specific "LayoutProjectItem"
LayoutProjectItem layoutProjItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("myLayout"));
##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
}
##Gets a specific "GeoprocessingProjectItem"
GeoprocessingProjectItem GPProjItem = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(item => item.Name.Equals("myToolbox"));
##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
}
##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(await folderItem.SearchAsync(".mxd"));
}
}
##Get The Default Project Folder
var defaultProjectPath = System.IO.Path.Combine(
System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments),
@"ArcGIS\Projects");
##Method to Return The Default Template Folder
public static string GetDefaultTemplateFolder() {
string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
string root = dir.Split(new string[] { @"\bin" }, StringSplitOptions.RemoveEmptyEntries)[0];
return System.IO.Path.Combine(root, @"Resources\ProjectTemplates");
}
##Get The List of Installed Templates
public static Task<List<string>> GetDefaultTemplatesAsync() {
return Task.Run(() => {
string templatesDir = GetDefaultTemplateFolder();
return
Directory.GetFiles(templatesDir, "*", SearchOption.TopDirectoryOnly)
.Where(f => f.EndsWith(".ppkx") || f.EndsWith(".aptx")).ToList();
});
}
##Create Project With Template
var templates = await GetDefaultTemplatesAsync();
var projectFolder = System.IO.Path.Combine(
System.Environment.GetFolderPath(
Environment.SpecialFolder.MyDocuments),
@"ArcGIS\Projects");
CreateProjectSettings ps = new CreateProjectSettings() {
Name = "MyProject",
LocationPath = projectFolder,
TemplatePath = templates[2]//2D "Map" template
};
var project = await Project.CreateAsync(ps);
Home | API Reference | Requirements | Download | Samples
-
Create an empty project
-
Create a new project with specified name
-
Create new project using Pro's default settings
-
New project using a custom template file
-
Create a project using template available with ArcGIS Pro
-
Open an existing project
-
Get the Current project
-
Get location of current project
-
Get the project's default gdb path
-
Save project
-
Check if project needs to be saved
-
SaveAs project
-
Close a project
-
Add a new map to a project
-
Get Recent Projects
-
Clear Recent Projects
-
Remove a Recent Project
-
Get Pinned Projects
-
Clear Pinned Projects
-
Pin / UnPin Projects
-
Get Recent Project Templates
-
Clear Recent Project Templates
-
Remove a Recent Project Template
-
Get Pinned Project Templates
-
Clear Pinned Project Templates
-
Pin / UnPin Project Templates
-
Add a folder connection item to the current project
-
Get all project items
-
Get all "MapProjectItems" for a project
-
Get a specific "MapProjectItem"
-
Get all "StyleProjectItems"
-
Get a specific "StyleProjectItem"
-
Get the "Favorite" StyleProjectItem
-
Get all "GDBProjectItems"
-
Get a specific "GDBProjectItem"
-
Get all "ServerConnectionProjectItems"
-
Get a specific "ServerConnectionProjectItem"
-
Get all folder connections in a project
-
Get a specific folder connection
-
Remove a specific folder connection
-
Gets a specific "LayoutProjectItem"
-
Get all layouts in a project
-
Get a specific "GeoprocessingProjectItem"
-
Get all GeoprocessingProjectItems in a project
-
Search project for a specific item
-
Get the Default Project Folder
-
Refresh the child item for a folder connection Item
-
Get Item Categories
-
Using Item Categories
-
Create Project with Template
-
Select project containers - for use with SelectItemAsync
-
ProjectItem: Get an Item or Find an Item
-
Select an item in the Catalog pane
-
Add a Favorite - Folder
-
Insert a Favorite - Geodatabase path
-
Add a Favorite - Style project item
-
Toggle the flag IsAddedToAllNewProjects for a favorite
-
Get the set of favorites and iterate
-
Remove All Favorites
-
FavoritesChangedEvent
-
Item: Get its IMetadata interface
-
Item: Get an item's metadata: GetXML
-
Item: Set the metadata of an item: SetXML
-
Item: Check the metadata can be edited: CanEdit
-
Item: Updates metadata with the current properties of the item: Synchronize
-
Item: Copy metadata from the source item's metadata: CopyMetadataFromItem
-
Item: Delete certain content from the metadata of the current item: DeleteMetadataContent
-
Item: Updates metadata with the imported metadata - the input path can be the path to an item with metadata, or a URI to a XML file: ImportMetadata
-
Item: Updates metadata with the imported metadata: ImportMetadata
-
Item: export the metadata of the currently selected item: ExportMetadata
-
Item: export the metadata of the currently selected item: ExportMetadata
-
Item: Save the metadata of the current item as XML: SaveMetadataAsXML
-
Item: Save the metadata of the current item as HTML: SaveMetadataAsHTML
-
Item: Save the metadata of the current item using customized XSLT: SaveMetadataAsUsingCustomXSLT
-
Item: Upgrade the metadata of the current item: UpgradeMetadata
-
Get The Full List of All Available Unit Formats
-
Get The List of Unit Formats for the Current Project
-
Get A Specific List of Unit Formats for the Current Project
-
Get The List of Default Formats for the Current Project
-
Get A Specific Default Unit Format for the Current Project
-
Set a Specific List of Unit Formats for the Current Project
-
Set the Defaults for the Project Unit Formats
-
Update Unit Formats for the Project