I am trying to create an AddIn with two buttons where the state is controlled with conditions. This is working but the button state is Disabled on program startup. I need a way to have one of the buttons Enabled on startup. I can't seem to find any code to allow me to have the button Enabled on startup.
Solved! Go to Solution.
Success!! I found the following code and was able to get it to work.
protected override bool Initialize() //Called when the Module is initialized. { ProjectOpenedEvent.Subscribe(OnProjectOpened); //subscribe to Project opened event return base.Initialize(); } private void OnProjectOpened(ProjectEventArgs obj) //Project Opened event handler { MessageBox.Show($"{Project.Current} has opened"); //show your message box //Put the button code here to activate or deactivate } protected override void Uninitialize() //unsubscribe to the project opened event { ProjectOpenedEvent.Unsubscribe(OnProjectOpened); //unsubscribe return; } Thank you so much for your help..... AWESOME!!!!!!!!!!
Hi Sam
By default, an add-in's module is set to be loaded just-in-time (JIT). So when Pro application loads, your logic to enable the button is not invoked yet. You can change this by modifying the "autoload" attribute in the config.daml - Set this to false.
<modules>
<insertModule id="acme_mainModule" caption="Acme"
className="MainModule" autoLoad="false">
<!--Declare additional customizations here..-->
</insertModule>
</modules>
Thanks
Uma
Thanks Uma for the response. I have tried that and also set my button's loadOnClick="false" as well. I think that the problem is that I am using a custom condition.
<insertCondition id="Controls_Button_condition" caption="Button Controls">
<!-- our condition is set true or false based on this underlying state -->
<state id="button_state"/>
</insertCondition>
I believe that the condition is evaluated to be false or disabled button at startup. I have no way of setting "button_state" on startup. I have successfully changed the state after running the program and the button will switch between enabled and disabled as I want it to. I just need the button to be enabled on startup and currently, the button starts out disabled.
Thanks in advance for your help.
Sam
Hi Sam,
One way you can do this -
In your Module class' Initialize override, you can subscribe to an event such as the ProjectOpenedEvent. The event handler can set your custom state. This way when a project opens, your states will get evaluated immediately.
This sounds hopeful.... I'm not sure how to accomplish what you are suggesting. There is an override in my module now:
protected override bool CanUnload()
{
//TODO - add your business logic
//return false to ~cancel~ Application close
return true;
}
Can I use this one or do I need to define another override? Also, I am not sure how to subscribe to the ProjectOpenedEvent or how to use the event handler. I guess I am in a little over my head on this one.
Success!! I found the following code and was able to get it to work.
protected override bool Initialize() //Called when the Module is initialized. { ProjectOpenedEvent.Subscribe(OnProjectOpened); //subscribe to Project opened event return base.Initialize(); } private void OnProjectOpened(ProjectEventArgs obj) //Project Opened event handler { MessageBox.Show($"{Project.Current} has opened"); //show your message box //Put the button code here to activate or deactivate } protected override void Uninitialize() //unsubscribe to the project opened event { ProjectOpenedEvent.Unsubscribe(OnProjectOpened); //unsubscribe return; } Thank you so much for your help..... AWESOME!!!!!!!!!!