
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I'm trying to achieve the selection of element faces using a custom form. The procedure is as follows:
1.- When the user starts the script, the form pops up with different buttons to select different things.
2.- In this selection of elements and parameter, the user sets up the info that the code will use to perform certain tasks.
3.- When the user hits "OK" button, the code starts to make the operations and after some time it gets the result.
Simple as that.
The issue is this. When I start the code, the form pops up but when I press the button to select the element faces the form stays on the screen and is blocking the user to pick these objects.
This es my Command.cs:
#region Namespaces using System; using System.Collections.Generic; using System.Diagnostics; using dBox = System.Windows.Forms; using System.Windows.Forms; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; #endregion namespace BarraHorPAPA { [Transaction(TransactionMode.Manual)] public class Command : IExternalCommand { public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; frmHorPAPA f = new frmHorPAPA(uiapp); try { if (f.ShowDialog() == DialogResult.OK) { //Llama al formulario para la obtención de datos. List<ElementId> ids = f.getCaras(); List<Element> lstCaras = new List<Element>(); using (Transaction tx = new Transaction(doc)) { tx.Start("Seleccionar Caras."); foreach (ElementId eid in ids) { Element ele = doc.GetElement(eid); lstCaras.Add(ele); } tx.Commit(); TaskDialog.Show("test", lstCaras.Count.ToString()); } } } catch (Exception ex) { TaskDialog.Show(" Info ", ex.GetType().Name + " " + ex.Message); } return Result.Succeeded; } } }
and this is my form:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Structure; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; namespace BarraHorPAPA { public partial class frmHorPAPA : System.Windows.Forms.Form { List<ElementId> lstCaras; UIApplication uiapp; UIDocument uidoc; Autodesk.Revit.ApplicationServices.Application app; Document doc; // se trae UIApplication desde el Command - que posee CommandData. public frmHorPAPA(UIApplication uiApp) { InitializeComponent(); uiapp = uiApp; uidoc = uiApp.ActiveUIDocument; app = uiapp.Application; doc = uidoc.Document; } private void frmHorPAPA_Load(object sender, EventArgs e) { lstCaras = null; } private void btnCaras_Click(object sender, EventArgs e) { IList<Reference> caras = uidoc.Selection.PickObjects(ObjectType.Face, "Selecciona las caras de los limites"); List<ElementId> ids = (from Reference r in caras select r.ElementId).ToList(); foreach (ElementId eid in ids) { lstCaras.Add(eid); } } #region MÉTODOS PARA EL ENVIO DE VARIABLES AL COMMAND public List<ElementId> getCaras() { return lstCaras; } #endregion private void btnOK_Click(object sender, EventArgs e) { } } }
What would you recommend to do in this case, to achieve what I'm trying to do?
Thanks in advance!
Solved! Go to Solution.