
Not applicable
05-23-2018
07:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, I've been messing around with the following code the past few hours, and I cant seem to get it to work. What I'm trying to achieve is to use a button on a windows form to select an object with the mouse in revit (to later store by id in a JSON file)
The problem I'm getting is that when it hits the selection.pickobject(...) command, the program just hangs and does not let you click in Revit. I think it has to do with Revit API being single thread, but I'm not sure.
Any ideas would be greatly appreciated!
This is the code within the Windows Form.
public partial class AddToJson : System.Windows.Forms.Form { ExternalCommandData commandData; UIDocument uidoc; Selection selection; public AddToJson(string optionName, ExternalCommandData cData) { commandData = cData; InitializeComponent(); comboBox1.Text = optionName; label6.Text = optionName; populateForm(); refreshData(); } private void button1_Click(object sender, EventArgs e) { //this.Hide(); foreach (System.Windows.Forms.Form f in Application.OpenForms) { f.Hide(); } UIApplication app = commandData.Application; uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; selection = uidoc.Selection; Reference ref1 = selection.PickObject(ObjectType.Element, "Pick element"); ElementId elemid = ref1.ElementId; this.Show(); }
Solved! Go to Solution.