Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.

Revit API Forum

Reply
Post 1 of 5
Accepted Solution

Disable TextBox (RibbonItem) in Zero Document State

115 Views, 4 Replies
04-04-2016 10:32 AM

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

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

Post 2 of 5

Re: Disable TextBox (RibbonItem) in Zero Document State

04-10-2016 11:56 AM 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

Post 3 of 5

Re: Disable TextBox (RibbonItem) in Zero Document State

04-11-2016 08:07 AM in reply to: jeremytammik

jeremytammik 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
Post 4 of 5

Re: Disable TextBox (RibbonItem) in Zero Document State

04-12-2016 11:10 PM 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

Post 5 of 5

Re: Disable TextBox (RibbonItem) in Zero Document State

04-14-2016 04:26 AM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post

Revit Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Revit helps you achieve greater speed, accuracy, and automation from concept to manufacturing.