I know how to use the IExternalCommandAvailability for PushButtons, but now I've added a TextBox to my Ribbon and want that to follow the same Enabled/Disabled status as my PushButtons. How can I dynamically control the TextBox.Enabled property based on the Zero Document State?
Solved! Go to Solution.
Solved by atiefenbach. Go to Solution.
Dear Atiefenbach,
Thank you for your query.
I really cannot say off-hand.
Quite probably, the Revit API does not provide this functionality.
If it does not, it might be possible to implement something reliable using the unofficial and undocumented functionality provided by the .NET Automation library and the Revit AdWindows .NET assembly DLL.
For instance, if you have a push button that needs to react in the same manner as the text box, you might be able to use an availability class for the former and then add some kind of event handler to react to changes to its state and propagate those to the text box.
I hope this helps.
Please let us know how it goes for you.
Thank you!
Good luck and have fun.
Best regards,
Jeremy
@Anonymous wrote:For instance, if you have a push button that needs to react in the same manner as the text box, you might be able to use an availability class for the former and then add some kind of event handler to react to changes to its state and propagate those to the text box.
Thanks Jeremy. As always, you've put me on the right track. I was simply overthinking my solutions. I created an IExternalCommandAvailability that I apply to my PushButtons that now sets my TextBox.Enabled = false, when ActiveUIDocument == null.
I use the code below and store my created TextBox in variable: Variables.ribbonTextBox, and I assign the "myNameSpace.DocumentRequired" to my PushButtonData.AvailabilityClassName.
public class Variables { public static RibbonItem ribbonTextBox = null; } public class DocumentRequired : IExternalCommandAvailability { public bool IsCommandAvailable(UIApplication a, CategorySet b) { bool val = true; if (a.ActiveUIDocument == null) val = false; Variables.FamilySeekTextBox.Enabled = val; return val; } }
Thanks!!
Dear Atiefenbach,
Thank you for your update, confirmation and appreciation.
I am very glad it helped.
You could make your code slightly shorter and even more readable like this, at least IMHO:
bool enable = (null != a.ActiveUIDocument); return Variables.FamilySeekTextBox.Enabled = enable;
Best regards,
Jeremy