TextBoxData user input to set parameter values

TextBoxData user input to set parameter values

AdvancedBIMSystems
Enthusiast Enthusiast
1,596 Views
2 Replies
Message 1 of 3

TextBoxData user input to set parameter values

AdvancedBIMSystems
Enthusiast
Enthusiast

I'm after a code example or links on how a TextBoxData value entered from a ribbon panel text box can be used to set a parameter value in a class. 

 

Text box setup on ribbon panel works as follows :

 

TextBoxData modifyData = new TextBoxData("ModifyBox");
TextBox modify = modifyPanel.AddItem(modifyData) as TextBox;

 

modify.PromptText = "Enter a value in mm";
modify.ToolTip = "Test text box";
modify.EnterPressed += new EventHandler<TextBoxEnterPressedEventArgs>(ProcessText);

 

void ProcessText(object sender, TextBoxEnterPressedEventArgs args)
{
     TextBox textBox = sender as TextBox;
     string strText = textBox.Value as string;
     double doorwidth = Convert.ToDouble(strText);
}

 

Get & set "doorwidth" parameter in separate class as follows :

 

ElementId doorId = doorObj.ElementId;
Element door = doc.GetElement(doorId);


Parameter p01 = door.LookupParameter("Door Width");


using (Transaction tx = new Transaction(doc, "Set door width"))
{
    tx.Start();


    p01.Set(doorwidth);

 

    tx.Commit();
}

 

Thanks

0 Likes
Accepted solutions (1)
1,597 Views
2 Replies
Replies (2)
Message 2 of 3

boostyourbim
Advocate
Advocate

What happens when you run your code? Is there an error? One possibility is that you should use an External Event, call the Raise() method in ProcessText, and put the transaction and Parameter.Set in the External Event's Execute method. If you want to pass the value when you raise the event, see https://forums.autodesk.com/t5/revit-api-forum/externalevent-raise-should-accept-parameters/td-p/550...

0 Likes
Message 3 of 3

AdvancedBIMSystems
Enthusiast
Enthusiast
Accepted solution

Thanks for taking the time to answer my question, much appreciated.

 

I ended up finding the solution here : https://forums.autodesk.com/t5/revit-api-forum/how-to-get-modeless-form-textbox-value/td-p/6008361 

 

Cheers

0 Likes