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: 

Simple user input

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
jjesusdelpino
5772 Views, 5 Replies

Simple user input

jjesusdelpino
Advocate
Advocate

Hi there. I got this plugin that needs a simple string input by the user. I thought this was gonna be an easy task using something like TaskDialog but I haven´t found anything on the API or this forum to make this. I know that I can use windows form but I was wondering if there is something in the Revit API that I can use for this task so I can avoid using windows form and also be able to use this as a macro.

Thanks you. Regards.

0 Likes

Simple user input

Hi there. I got this plugin that needs a simple string input by the user. I thought this was gonna be an easy task using something like TaskDialog but I haven´t found anything on the API or this forum to make this. I know that I can use windows form but I was wondering if there is something in the Revit API that I can use for this task so I can avoid using windows form and also be able to use this as a macro.

Thanks you. Regards.

5 REPLIES 5
Message 2 of 6

yimin.chenTW
Alumni
Alumni
Accepted solution

Hi @jjesusdelpino ,

 

I guess the simplest way is to create a WinForm with textbox for users to input.

But if you really try to avoid using WinForm as much as possible, there is a workaround, you can try to add a textbox in your ribbon panel by adding code below:

TextBoxData itemData1 = new TextBoxData("itemName1");
Autodesk.Revit.UI.TextBox item1 = ribbonPanel.AddItem(itemData1) as Autodesk.Revit.UI.TextBox;
item1.Value = "Input something here...";
item1.ToolTip = itemData1.Name; // Can be changed to a more descriptive text.
Uri uriImage = new Uri(@"path of the image");
BitmapImage Image1 = new BitmapImage(uriImage);
item1.Image = Image1;
item1.ShowImageAsButton = true;
item1.EnterPressed += CallbackOfTextBox;

And your event:

public void CallbackOfTextBox(object sender, Autodesk.Revit.UI.Events.TextBoxEnterPressedEventArgs args)
{
	Autodesk.Revit.UI.TextBox textBox = sender as Autodesk.Revit.UI.TextBox;

	TaskDialog.Show(textBox.Value.ToString(), textBox.Value.ToString());
}

 

2019-12-07_12-39-31.png

 

Though I don't think it's a good way, and maybe there are some more ways to do but right now I can only think of this.

Hope this helps.

 

Yimin Chen
Developer Consultant
Developer Technical Services
Autodesk

Hi @jjesusdelpino ,

 

I guess the simplest way is to create a WinForm with textbox for users to input.

But if you really try to avoid using WinForm as much as possible, there is a workaround, you can try to add a textbox in your ribbon panel by adding code below:

TextBoxData itemData1 = new TextBoxData("itemName1");
Autodesk.Revit.UI.TextBox item1 = ribbonPanel.AddItem(itemData1) as Autodesk.Revit.UI.TextBox;
item1.Value = "Input something here...";
item1.ToolTip = itemData1.Name; // Can be changed to a more descriptive text.
Uri uriImage = new Uri(@"path of the image");
BitmapImage Image1 = new BitmapImage(uriImage);
item1.Image = Image1;
item1.ShowImageAsButton = true;
item1.EnterPressed += CallbackOfTextBox;

And your event:

public void CallbackOfTextBox(object sender, Autodesk.Revit.UI.Events.TextBoxEnterPressedEventArgs args)
{
	Autodesk.Revit.UI.TextBox textBox = sender as Autodesk.Revit.UI.TextBox;

	TaskDialog.Show(textBox.Value.ToString(), textBox.Value.ToString());
}

 

2019-12-07_12-39-31.png

 

Though I don't think it's a good way, and maybe there are some more ways to do but right now I can only think of this.

Hope this helps.

 

Yimin Chen
Developer Consultant
Developer Technical Services
Autodesk
Message 3 of 6

jjesusdelpino
Advocate
Advocate

Clearly this is a solution I hadn´t considered. Very original and do the point. Anyway this seems to be even harder than forms so im guesssing thats what Im gonna use. Thanks you so much for your anwser. Very complete and very didactid.

Regards.

Clearly this is a solution I hadn´t considered. Very original and do the point. Anyway this seems to be even harder than forms so im guesssing thats what Im gonna use. Thanks you so much for your anwser. Very complete and very didactid.

Regards.

Message 4 of 6
matveevri
in reply to: jjesusdelpino

matveevri
Explorer
Explorer

can i read the textbox value in another Clasees?

For example i want to input value e.g. "150" and run another command which will use this "150" value in ot own calculations, and i dont need to change value every time i run other command and dotn want to press enter.

 

I want to use it like a storage for my value, is it possible? cant access to any textbox commands from other class

0 Likes

can i read the textbox value in another Clasees?

For example i want to input value e.g. "150" and run another command which will use this "150" value in ot own calculations, and i dont need to change value every time i run other command and dotn want to press enter.

 

I want to use it like a storage for my value, is it possible? cant access to any textbox commands from other class

Message 5 of 6
AmitMetz
in reply to: jjesusdelpino

AmitMetz
Explorer
Explorer

Hi, 
you can use Microsoft.VisualBasic namespace

using Microsoft.VisualBasic;
string input = Interaction.InputBox("Prompt", "Title");

like in this example

https://stackoverflow.com/questions/97097/what-is-the-c-sharp-version-of-vb-nets-inputdialog

0 Likes

Hi, 
you can use Microsoft.VisualBasic namespace

using Microsoft.VisualBasic;
string input = Interaction.InputBox("Prompt", "Title");

like in this example

https://stackoverflow.com/questions/97097/what-is-the-c-sharp-version-of-vb-nets-inputdialog

Message 6 of 6
avpBS7DE
in reply to: yimin.chenTW

avpBS7DE
Contributor
Contributor

Hello Yimin,

Thank you, this was useful to me. Do you know how to set up the Width of that text box ? @jeremytammik I read the description of the Width property but I don't quite understand what unit sheets are, and how they would correspond to my desired units (I thought I could pick something like "max number of characters", and Font size).

avpBS7DE_0-1685537855927.png

 



Angelo

0 Likes

Hello Yimin,

Thank you, this was useful to me. Do you know how to set up the Width of that text box ? @jeremytammik I read the description of the Width property but I don't quite understand what unit sheets are, and how they would correspond to my desired units (I thought I could pick something like "max number of characters", and Font size).

avpBS7DE_0-1685537855927.png

 



Angelo

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

Post to forums  

Autodesk Design & Make Report