|
POST
|
Thanks for the reply Kirk. I like your idea but I do not think our IT department will go for it. They are already very unhappy that we are creating an extension in addition to a custom toolbar so I seriously doubt they are going to let us run a service in the background on their Citrix server. Whatever solution I end up using, it has to be contained within my extension or .dll file. Ideally, the logic my boss wants to see is: Track anything the user adds from the Add Data button that is on an Enterprise server (not local data), write this to an Access or Oracle table and keep a running total of how many times each particular data set is loaded so we can detect the most popular ones for inclusion on the forms. I thought about adding a timer so that I can fire code to see what is in the TOC say every 5 minutes but I strongly suspect this would adversely affect performance as this was the case once before when I tried using timers through Citrix.
... View more
07-06-2010
07:14 AM
|
0
|
0
|
776
|
|
POST
|
James, Thanks for the reply. Unfortunately, it is not working correctly. The code in the customization filter detects when the Add Data button is pressed and then immediately executes your line of code before the user even adds anything to the TOC. if (pCommandItem.Name.ToString() == "File_AddData")
{
MessageBox.Show("Add Command Executed");
IApplication pApplication = ClsHelper.GetArcGISApplication();
IMxDocument pMxDocument = (IMxDocument)pApplication.Document;
IMap pMap = pMxDocument.FocusMap;
IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
MessageBox.Show("Layer name: " + pFeatureLayer.FeatureClass.AliasName);
}
... View more
07-06-2010
06:30 AM
|
0
|
0
|
776
|
|
POST
|
Hi everyone, We have a custom toolbar with lots of forms to make loading enterprise wide data more user friendly, especially for non-GIS staff. From time to time we send out surverys asking the users if there are additional data sets they wish added to our forms. Since few people return the surveys, we thought a better way of tracking this is to see what data users are adding themselves through the Add Data button on the Standard toolbar. My first attempt, was to create an extension and listen for the IActiveViewEvents::ItemAdded event. This works great but I get layers recorded that I do not want to track. We have predefined load sets which contain all the most common layers used by a particular group of users. Right now we have about a dozen different load sets. I already know which layers are in these load sets so I do not need to track them but IActiveViewEvents::ItemAdded tracks everything. My second attempt was to use a customization filter to trap when the Add Data button is pressed and again this works great. However, as others have pointed out in previous posts, you cannot get anything in return from a built-in command so while I can detect the user pressing the Add Data button, I have no way of detecting what they added. I thought about creating my own Add Data button but cannot figure out how to remove the built-in Add Data button and replace it with my own. Plus this seems like overkill. Does anyone have an idea how to best get around this problem? I could stick with IActiveViewEvents::ItemAdded and just ignore the layers from the load sets but was hoping for something more efficient as I suspect running queries to see if I layer has already been loaded would slow down the whole code and since the code has to run through Citrix, performance is a big issue. Thanks, Carlos
... View more
07-06-2010
05:35 AM
|
0
|
8
|
1347
|
|
POST
|
Thanks Ken, I'll try to make sense of it all and give it a try. I'll let you know what happens. Carlos
... View more
06-17-2010
09:28 AM
|
0
|
0
|
769
|
|
POST
|
Ken, Thanks for the reply! Being that this is my first attempt at writing an extension, I am trying to follow an ESRI example as closely as possible because I still don't understand everything that is going on in the code. In their example, they initialize m_extensionState at the top so I left it there. I tried to not setting it to a value at the start (private esriExtensionState m_extensionState) and that caused another problem. If I didn't set m_extensionState to disabled at the start, the else if disabled code would run in the state property regardless if the extension was checked on or off in the extension manager. Could you send me your code so I can see where you are setting m_extensionState? Thanks, Carlos In the extension I developed, I used the same ESRI example as you did. One thing that is different between our code is when you initialize the variable m_extensionState. When you initialize it, you're also setting it to disabled. In my code, the variable gets set to either disabled or enabled in the State Property.
... View more
06-17-2010
05:23 AM
|
0
|
0
|
769
|
|
POST
|
I got my extension almost running perfectly by have one more hurdle to overcome. If the extension is turned off when ArcMap starts, the user can turn on/off the extension and all the code runs fine. My problem occurs when the user leaves the extension turned on, exists ArcMap and then starts ArcMap up again. When this happens, the extension is already checked on in the Extension Manager dialog and the code that I need to have run, does not fire because ArcMap is not totally loaded at the time (IApplicationStatus). In the code below, CheckToolbarValidity has a couple of checks to verify that ArcMap is fully initialized and that the extension is turned on. If it passes these two checks, it calls SetupEvents which turns on the listeners for IActivewView::AddItem. Here lies my problem. If the extension is already turned on when ArcMap starts up, m_appStatus.Initialized returns false and the method exits before it can call SetupEvents. My extension follows the AcmeExt ESRI sample pretty closely with the main difference being that I don't call SetupEvents from IExtension::Startup. The reason I don't do this is because if did, the event listener would be turned on every time ArcMap starts regardless if my extension was turned on or not. I was thinking I could put a timer in CheckToolbarValidity so that it loops until m_appStatus.Initialized returns true. Problem here is that I never have tried to do timer in C# before. Does anyone think this is a bad idea and if so, do you have a suggestion for how to get around my problem? Thanks, Carlos public class Extension : IExtension, IExtensionConfig, IPersistVariant
{
private IApplication m_application;
private IMxDocument m_mxDocument;
private esriExtensionState m_extensionState = esriExtensionState.esriESDisabled;
private IApplicationStatus m_appStatus;
private IApplicationStatusEvents_Event m_mapStatusEvents;
private IActiveViewEvents_Event m_mapEvents;
#region IExtension Members
/// <summary>
/// Name of extension. Do not exceed 31 characters
/// </summary>
public string Name
{
get
{
return "RegGSS Extension";
}
}
public void Shutdown()
{
m_application = null;
}
public void Startup(ref object initializationData)
{
m_application = initializationData as IApplication;
if (m_application == null)
return;
m_appStatus = m_application as IApplicationStatus;
}
#endregion
#region IExtensionConfig Members
public string Description
{
get
{
return "RegGSS 9.3\r\n" +
"Copyright © SFWMD 2010\r\n\r\n" +
"Environmental Resource Regulation\r\n" +
"Regulatory Support - GIS Section";
}
}
/// <summary>
/// Friendly name shown in the Extension dialog
/// </summary>
public string ProductName
{
get
{
return "RegGSS";
}
}
public esriExtensionState State
{
get
{
return m_extensionState;
}
set
{
if (m_extensionState != 0 && value == m_extensionState)
return;
//Check if ok to enable or disable extension
esriExtensionState requestState = value;
if (requestState == esriExtensionState.esriESEnabled)
{
//Cannot enable if it's already in unavailable state
if (m_extensionState == esriExtensionState.esriESUnavailable)
{
throw new COMException("Cannot enable extension");
}
//Determine if state can be changed
esriExtensionState checkState = StateCheck(true);
m_extensionState = checkState;
CheckToolbarValidity();
}
else if (requestState == 0 || requestState == esriExtensionState.esriESDisabled)
{
//Determine if state can be changed
esriExtensionState checkState = StateCheck(false);
if (checkState != m_extensionState)
m_extensionState = checkState;
MessageBox.Show("Disabled");
UnloadEvents();
}
}
}
#endregion
/// <summary>
/// Determine extension state
/// </summary>
/// <param name="requestEnable">true if to enable; false to disable</param>
private esriExtensionState StateCheck(bool requestEnable)
{
//Turn on or off extension directly
if (requestEnable)
return esriExtensionState.esriESEnabled;
else
return esriExtensionState.esriESDisabled;
}
private void SetupEvents()
{
// Make sure we're dealing with ArcMap
if (m_application.Document.Parent is IMxApplication)
{
m_mxDocument = m_application.Document as IMxDocument;
m_mapEvents = m_mxDocument.FocusMap as IActiveViewEvents_Event;
m_mapEvents.ItemAdded += new IActiveViewEvents_ItemAddedEventHandler(OnItemAdded);
m_mapStatusEvents = m_application.Document.Parent as IApplicationStatusEvents_Event;
m_mapStatusEvents.Initialized += new IApplicationStatusEvents_InitializedEventHandler(OnInitialized);
}
}
// Called when the framework is fully initialized
// After this event fires, it is safe to make UI customizations
void OnInitialized()
{
CheckToolbarValidity();
}
void OnItemAdded(object Item)
{
//MessageBox.Show("Item Added");
IFeatureLayer pFeatureLayer;
if (Item is IFeatureLayer)
{
pFeatureLayer = Item as IFeatureLayer;
MessageBox.Show("Layer name: " + pFeatureLayer.Name);
}
}
private void CheckToolbarValidity()
{
// Wait for framework to initialize before making UI customizations
// Check framework initialization flag
if (!m_appStatus.Initialized)
return;
// Make sure the extension is enabled
if (m_extensionState != esriExtensionState.esriESEnabled)
return;
SetupEvents();
}
private void UnloadEvents()
{
//m_mapEvents.ItemAdded -= new IActiveViewEvents_ItemAddedEventHandler(OnItemAdded);
}
}
... View more
06-15-2010
01:11 PM
|
0
|
4
|
1123
|
|
POST
|
Kirk, I solved it! The problem was with this line of code at the top of the extension: private esriExtensionState m_enableState; should be: private esriExtensionState m_enableState = esriExtensionState.esriESDisabled; I guess I must have copied/pasted wrong when I copied the example. Thanks again for your help! It is always greatly appreciated! Carlos
... View more
06-15-2010
06:33 AM
|
0
|
0
|
581
|
|
POST
|
Thanks Kirk, I will give it a try. In your code, what code should method AMethodThatMightThrowAnException contain?
... View more
06-15-2010
03:39 AM
|
0
|
0
|
1509
|
|
POST
|
Kirk, Thanks for the reply. You are correct, as far as I can tel, IApplicationStatus.Initialized is indeed false in the startup method. How do I correct this? I am using the AcmeExt (Applying user interface customizations at startup) ESRI example along with the default code that comes with the ApplicationExtension template and I must admit I don't understand some of it but figured if it is in their example, I should not mess with it. Last night as a test, I installed the ESRI example, put message boxes in the same locations as in my code and when I started ArcMap, I got the same result, message box displaying in the disabled code eventhough I had not yet turned on the extension. I'm beginning to think that the problem might be with the example. Anyhow, below is my entire extension as it currently stands. Can you please take a look at it and see if you can tell what the problem is and how I can fix it? I will look at JIT extension and see if that might work better for me. Hopefully I can find some examples of those. Thanks a lot! Carlos namespace RegGSS
{
[Guid("21fee823-6e9a-43af-a452-f5c8678b6e99")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("RegGSS.Extension")]
public class Extension : IExtension, IExtensionConfig, IPersistVariant
{
private IApplication m_application;
private IMxDocument m_mxDocument;
private esriExtensionState m_enableState;
private IApplicationStatus m_appStatus;
private IApplicationStatusEvents_Event m_mapStatusEvents;
private IActiveViewEvents_Event m_mapEvents;
#region IExtension Members
/// <summary>
/// Name of extension. Do not exceed 31 characters
/// </summary>
public string Name
{
get
{
//TODO: Modify string to uniquely identify extension
return "RegGSS Extension";
}
}
public void Shutdown()
{
//TODO: Clean up resources
m_application = null;
//m_docEvents = null;
}
public void Startup(ref object initializationData)
{
m_application = initializationData as IApplication;
if (m_application == null)
return;
//TODO: Add code to initialize the extension
m_appStatus = m_application as IApplicationStatus;
}
#endregion
#region IExtensionConfig Members
public string Description
{
get
{
//TODO: Replace description (use \r\n for line break)
return "RegGSS 9.3\r\n" +
"Copyright © SFWMD 2010\r\n\r\n" +
"Environmental Resource Regulation\r\n" +
"Regulatory Support - GIS Section";
}
}
/// <summary>
/// Friendly name shown in the Extension dialog
/// </summary>
public string ProductName
{
get
{
//TODO: Replace
return "RegGSS";
}
}
public esriExtensionState State
{
get
{
return m_enableState;
}
set
{
if (m_enableState != 0 && value == m_enableState)
return;
//Check if ok to enable or disable extension
esriExtensionState requestState = value;
if (requestState == esriExtensionState.esriESEnabled)
{
//Cannot enable if it's already in unavailable state
if (m_enableState == esriExtensionState.esriESUnavailable)
{
throw new COMException("Cannot enable extension");
}
//Determine if state can be changed
esriExtensionState checkState = StateCheck(true);
m_enableState = checkState;
MessageBox.Show("Enabled");
CheckToolbarValidity();
SetupEvents();
}
else if (requestState == 0 || requestState == esriExtensionState.esriESDisabled)
{
//Determine if state can be changed
esriExtensionState checkState = StateCheck(false);
if (checkState != m_enableState)
m_enableState = checkState;
MessageBox.Show("Disabled");
UnloadCustomizations();
//Remove event
m_mapEvents.ItemAdded -= new IActiveViewEvents_ItemAddedEventHandler(OnItemAdded);
}
}
}
#endregion
/// <summary>
/// Determine extension state
/// </summary>
/// <param name="requestEnable">true if to enable; false to disable</param>
private esriExtensionState StateCheck(bool requestEnable)
{
//TODO: Replace with advanced extension state checking if needed
//Turn on or off extension directly
if (requestEnable)
return esriExtensionState.esriESEnabled;
else
return esriExtensionState.esriESDisabled;
}
#region IPersistVariant Members
public UID ID
{
get
{
UID typeID = new UIDClass();
typeID.Value = GetType().GUID.ToString("B");
return typeID;
}
}
public void Load(IVariantStream Stream)
{
//TODO: Load persisted data from document stream
Marshal.ReleaseComObject(Stream);
}
public void Save(IVariantStream Stream)
{
//TODO: Save extension related data to document stream
Marshal.ReleaseComObject(Stream);
}
#endregion
private void SetupEvents()
{
// Make sure we're dealing with ArcMap
if (m_application.Document.Parent is IMxApplication)
{
m_mxDocument = m_application.Document as IMxDocument;
m_mapEvents = m_mxDocument.FocusMap as IActiveViewEvents_Event;
m_mapEvents.ItemAdded += new IActiveViewEvents_ItemAddedEventHandler(OnItemAdded);
m_mapStatusEvents = m_application.Document.Parent as IApplicationStatusEvents_Event;
m_mapStatusEvents.Initialized += new IApplicationStatusEvents_InitializedEventHandler(OnInitialized);
}
}
// Called when the framework is fully initialized
// After this event fires, it is safe to make UI customizations
void OnInitialized()
{
CheckToolbarValidity();
MessageBox.Show("Initialized");
}
void OnItemAdded(object Item)
{
MessageBox.Show("Item Added");
IFeatureLayer pFeatureLayer;
if (Item is IFeatureLayer)
{
pFeatureLayer = Item as IFeatureLayer;
MessageBox.Show("Layer name: " + pFeatureLayer.Name);
}
}
private void CheckToolbarValidity()
{
// Wait for framework to initialize before making ui customizations
// Check framework initialization flag
if (!m_appStatus.Initialized)
return;
// Make sure the extension is enabled
if (m_enableState != esriExtensionState.esriESEnabled)
return;
// Perform the customization
LoadCustomizations();
}
private void LoadCustomizations()
{
}
private void UnloadCustomizations()
{
}
}
}
... View more
06-15-2010
03:28 AM
|
0
|
0
|
581
|
|
POST
|
Hi everyone, I've been struggling with creating my first extension for over a week now and have made some progress but now I am seeing behavior that I don't quite understand. I'm using Visual Studio 2008 with C#. I used the ESRI ApplicationExtension template to create my extension and followed the AcmeExt ESRI example. The code below is the State snippet from IExentsionConfig exactly as it comes in when you first create an extension from the template. The only code I have added are the two message boxes so I could see when things fired. I originally had more code in there listening to the AddItem event but stripped it down to the minimum for simplicity of posting here. Much to my surprise, the Disabled message box (esriExtensionState.esriESDisabled) pops up now every time I open ArcMap and it does not matter if my extension is checked on or not in the extensions dialog. Is this normal behavior? I thought this code would only fire when my extension is either turned on or off. My extension is going to be deployed on a Citrix server for everyone in our organization to use (1700+ people) and I don't want my code firing every time ArcMap opens, only when my extension is checked on. Sorry if this is a dumb question, but extensions have always been a bit of a mystery to me and my total experience with trying to write one is only one week plus long. I've been pouring through the forums but have not found an answer. Thanks, Carlos public esriExtensionState State
{
get
{
return m_enableState;
}
set
{
if (m_enableState != 0 && value == m_enableState)
return;
//Check if ok to enable or disable extension
esriExtensionState requestState = value;
if (requestState == esriExtensionState.esriESEnabled)
{
//Cannot enable if it's already in unavailable state
if (m_enableState == esriExtensionState.esriESUnavailable)
{
throw new COMException("Cannot enable extension");
}
//Determine if state can be changed
esriExtensionState checkState = StateCheck(true);
m_enableState = checkState;
MessageBox.Show("Enabled");
}
else if (requestState == 0 || requestState == esriExtensionState.esriESDisabled)
{
//Determine if state can be changed
esriExtensionState checkState = StateCheck(false);
if (checkState != m_enableState)
m_enableState = checkState;
MessageBox.Show("Disabled");
}
}
}
... View more
06-14-2010
12:49 PM
|
0
|
3
|
1205
|
|
POST
|
Thanks Kirk, I think I understand what you are saying. I will give it a try. Do you have an example I can follow? Thanks, Carlos
... View more
06-14-2010
12:22 PM
|
0
|
0
|
1509
|
|
POST
|
Hi Ken, Got it working with your code. Thanks a bunch! Here's the code in C# in case in helps someone else. public override bool Enabled { get { UID pUID = new UIDClass(); pUID.Value = "RegGSS.Extension"; IExtensionConfig pExtension = m_application.FindExtensionByCLSID(pUID) as IExtensionConfig; if (pExtension == null) return false; if (pExtension.State == esriExtensionState.esriESEnabled) return true; else return false; } }
... View more
06-14-2010
05:23 AM
|
0
|
0
|
1509
|
|
POST
|
Ken, Thanks for the reply. I think I understand what you are saying and I will give it try. Do you have a code example where you are using the previous code you sent me so I can see how to set it up properly? Thanks again for your help. Carlos As you state, OnCreate is only fired when the command is created, whereas Enabled is fired continuously (which is also why you shouldn't have any extensive code in that subroutine). This will react to any changes in the environment, like enabling the extension.
... View more
06-14-2010
03:02 AM
|
0
|
0
|
1509
|
|
POST
|
Ken, Thanks for the reply. Unless I am not understanding correctly, your code is doing the same thing mine is doing, disabling the commands on the toolbar if the extension is turned off. My problem is if the user turns on the toolbar first and then the extension, the commands on the toolbar stay disabled because the code to enable/disable the command in on the "on create" for the command and since the toolbar is already on, the "on create" code does not excute again. I was thinking I could refresh the command somehow but can't figure out how to do that. Thanks again for your help! Carlos
... View more
06-10-2010
12:19 PM
|
0
|
0
|
1509
|
|
POST
|
Hi everyone, I am working on my first extension and have run into a problem. I am sure this problem is something simple, but I have been fighting with this for 2 days now and have looked at every example on the forums to do with extensions plus all the sample ESRI code I could find with no luck. My extension works in conjuction with a custom toolbar. I have placed the code below in every command on the toolbar to disable it if the extension is turned off and this works fine. If the user turns on the extension first, then the toolbar, everything works fine but if the user turns on the toolbar first, then the extension, all of commands stay disabled. What I think I need to do is activate the commands from the extension enabled code but can't figure out how to do this. All of my commands were created using the BaseCommand templates in C#. Thanks, Carlos public override void OnCreate(object hook) { if (hook == null) return; m_application = hook as IApplication; //Disable if it is not ArcMap if (hook is IMxApplication) base.m_enabled = true; else base.m_enabled = false; //Disable if RegGSS extension not turned on. UID pUID = new UIDClass(); pUID.Value = "RegGSS.Extension"; IExtensionConfig pExtension = m_application.FindExtensionByCLSID(pUID) as IExtensionConfig; if (pExtension == null) return; if (pExtension.State == esriExtensionState.esriESEnabled) base.m_enabled = true; else base.m_enabled = false; }
... View more
06-10-2010
11:34 AM
|
0
|
9
|
1983
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-11-2016 06:06 AM | |
| 1 | 08-07-2015 10:13 AM | |
| 2 | 06-29-2015 12:45 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|