Combining two projects
This is a exploratory post for creating a Powershell GIS Cmdlet. I have taken basic examples of Creating Powershell Cmdlet and creating a ArcGIS Console Application. I have tried to combine the code to create a cmdlet which returns the Map names and the Feature layer names.
SourceCode for the projects
Link to the tutorials
ArcGIS Console Application
Powershell Cmdlet Tutorial
Create a ArcGIS class library project
Follow the procedure to add references as per the Powershell tutorial
Hint: If you are on x64 machine System.Management.Automation is found under
c:\program files (x86)\reference assemblies\microsoft\WindowsPowershell\v1.0
Rename the Class1.cs file to "GetLayerName" and click on Yes when asked to update all references
Add the "LicenseInitializer.cs" from the ArcGIS Console Application Source-code to GetLayerNameCmdlet project.
Open the LicenseInitializer.cs file and update the namespace to GetLayerNamesCmdlet, click yes when asked to update references.
`
We can Pipe this output to other commands.
Run Visual Studio as an Administrator and build the code.
Open the Powershell command windows. ( I am using Console2, its awesome! check out Scott Hanselman's take on Console2)
Use the Import-Module command to import the developed DLL. Use the Get-Module command to verify.
Use the command Get-LayerNames and pass the MXD file path as a parameter
The command displays the Map name as "Layers" and the Feature Layers participating in the map.
Please post your comments and ideas for new cmdlets.
This is a exploratory post for creating a Powershell GIS Cmdlet. I have taken basic examples of Creating Powershell Cmdlet and creating a ArcGIS Console Application. I have tried to combine the code to create a cmdlet which returns the Map names and the Feature layer names.
SourceCode for the projects
Link to the tutorials
ArcGIS Console Application
Powershell Cmdlet Tutorial
Create a ArcGIS class library project
Hint: If you are on x64 machine System.Management.Automation is found under
c:\program files (x86)\reference assemblies\microsoft\WindowsPowershell\v1.0
Rename the Class1.cs file to "GetLayerName" and click on Yes when asked to update all references
Add the "LicenseInitializer.cs" from the ArcGIS Console Application Source-code to GetLayerNameCmdlet project.
Open the LicenseInitializer.cs file and update the namespace to GetLayerNamesCmdlet, click yes when asked to update references.
Lets have a look at the GetLayerName.cs file
`
We can Pipe this output to other commands.
Run Visual Studio as an Administrator and build the code.
Open the Powershell command windows. ( I am using Console2, its awesome! check out Scott Hanselman's take on Console2)
Use the Import-Module command to import the developed DLL. Use the Get-Module command to verify.
Use the command Get-LayerNames and pass the MXD file path as a parameter
The command displays the Map name as "Layers" and the Feature Layers participating in the map.
Please post your comments and ideas for new cmdlets.
No comments:
Post a Comment