Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Disable TextBox (RibbonItem) in Zero Document State

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
atiefenbach
560 Views, 4 Replies

Disable TextBox (RibbonItem) in Zero Document State

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?

Anthony Tiefenbach
BIM Manager
HuntonBrady Architects
4 REPLIES 4
Message 2 of 5
jeremytammik
in reply to: atiefenbach

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5
atiefenbach
in reply to: jeremytammik


@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!!

Anthony Tiefenbach
BIM Manager
HuntonBrady Architects
Message 4 of 5
jeremytammik
in reply to: atiefenbach

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 5
atiefenbach
in reply to: jeremytammik

Correct. I changed that after I copy/pasted in the code. Just got lazy on the post. Thanks again!
Anthony Tiefenbach
BIM Manager
HuntonBrady Architects

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community