In .NET maybe it is hard to capture every possible user "oops".
In Java, it's straight-forward.
DecimalFormat.. DateFormat.. fun stuff.
If you enter junk into this text field, it will default to 0.00// Create an instance of DecimalFormat to limit the number of integers the user can type into certain fields. DecimalFormat temperatureFormat = new DecimalFormat("##0.00"); ftfTemperature = new JFormattedTextField(new DefaultFormatterFactory(new NumberFormatter(temperatureFormat),new NumberFormatter(temperatureFormat),new NumberFormatter(temperatureFormat))); ftfTemperature.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { ftfTemperature.selectAll(); } }); } }); ftfTemperature.setBounds(120, 8, 85, 20); panel.add(ftfTemperature);
public class Console {
public static void main(String[] args) {
EngineInitializer.initializeEngine();
initializeArcGISLicenses();
try {
IAppROT aprot = new AppROT();
IApplication application = aprot.getItem(0);
System.out.println(application.getDocument().getTitle());
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
static void initializeArcGISLicenses() {
try {
com.esri.arcgis.system.AoInitialize ao = new com.esri.arcgis.system.AoInitialize();
if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcView) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcView);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Lines of Python code to restrict a script tool field to a long: Define the input as a Long.
Lines of Python code to restrict a script tool field to a date: Define the input as a Date.
Hard to get any simpler than that.
This prints the title of the only mxd open on my machine, index = 0. You would probably have to make sure you have the right mxd application name by iterating over the count of open mxds and getting the title.public class Console { public static void main(String[] args) { EngineInitializer.initializeEngine(); initializeArcGISLicenses(); try { IAppROT aprot = new AppROT(); IApplication application = aprot.getItem(0); System.out.println(application.getDocument().getTitle()); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } static void initializeArcGISLicenses() { try { com.esri.arcgis.system.AoInitialize ao = new com.esri.arcgis.system.AoInitialize(); if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcView) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable) ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeArcView); } catch (Exception e) { e.printStackTrace(); } } }
Doesn't python have an OS module that you can call?
os.system(your application, your parameter)
from subprocess import check_call check_call(["DesktopConsoleApplication1.exe", "Collision_Segment_Diagram2.mxd"])
using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Framework;
namespace DesktopConsoleApplication1
{
class Program
{
private static LicenseInitializer m_AOLicenseInitializer = new DesktopConsoleApplication1.LicenseInitializer();
[STAThread()]
static void Main(string[] args)
{
//ESRI License Initializer generated code.
m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeArcView, esriLicenseProductCode.esriLicenseProductCodeArcEditor, esriLicenseProductCode.esriLicenseProductCodeArcInfo },
new esriLicenseExtensionCode[] { });
//ESRI License Initializer generated code.
try
{
IAppROT aprot = new AppROT();
IApplication application = null;
for(int a = 0; a < aprot.Count; a++)
{
application = aprot.get_Item(a);
System.Console.WriteLine("Application Title = " + application.Document.Title);
foreach (string curItem in args)
{
System.Console.WriteLine("Args: " + curItem);
if (application.Document.Title == curItem)
{
System.Console.WriteLine("The map was found! Do something!");
}
else
{
System.Console.WriteLine("The open map does not match that title.");
}
}
}
if (aprot.Count == 0)
{
System.Console.WriteLine("No ArcMap application is open");
}
//System.Console.ReadLine(); //Uncomment this line if you want to have the console pause before closing.
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
//Do not make any call to ArcObjects after ShutDownApplication()
m_AOLicenseInitializer.ShutdownApplication();
}
}
}
In .NET maybe it is hard to capture every possible user "oops".
In Java, it's straight-forward.
DecimalFormat.. DateFormat.. fun stuff.
If you enter junk into this text field, it will default to 0.00// Create an instance of DecimalFormat to limit the number of integers the user can type into certain fields. DecimalFormat temperatureFormat = new DecimalFormat("##0.00"); ftfTemperature = new JFormattedTextField(new DefaultFormatterFactory(new NumberFormatter(temperatureFormat),new NumberFormatter(temperatureFormat),new NumberFormatter(temperatureFormat))); ftfTemperature.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { ftfTemperature.selectAll(); } }); } }); ftfTemperature.setBounds(120, 8, 85, 20); panel.add(ftfTemperature);
Leo:
Could you screen shot what this code actually produces as far as an interface that the user would see?
Searching help on Java Add-ins has left me completely in the dark on what this code would end up looking like or how it launches or anything.
Is the Java IDE environment text based only for defining the form or does it have visual drag and drop tools? I need the real basics to get oriented to decide if I want to even attempt to go down this path.
How is building a Java add-in any different from building a .Net add-in?