private void AddModelLineInfosToDataTable(DimensionEditingForm def) { def.DataTable.Rows.Clear(); // Get all the model lines created by our plugin in the doc IList <CurveElement> lines = (from line in new FilteredElementCollector(_doc) .OfClass(typeof(CurveElement)) .OfCategory(BuiltInCategory.OST_Lines) .Cast <CurveElement>() where (line as ModelLine) != null && line.GetEntitySchemaGuids().Count != 0 select line) .ToList(); // Add infos to eht data table for each model line IList <object[]> linesParams = new List <object[]>(); foreach (CurveElement line in lines) { ModelLine modelLine = line as ModelLine; Schema lineSchema = Schema.Lookup(Utils.Guids.MODELLINE_SCHEMA_GUID); Entity lineSchemaEnt = modelLine.GetEntity(lineSchema); // Get line Id int lineId = modelLine.Id.IntegerValue; // Get associated level of the line string lineLevel = modelLine.SketchPlane.Name; // Get line length double lineLength = Math.Round( UnitUtils.Convert(modelLine.GeometryCurve.Length, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_METERS), 2); // Get beam type string beamType = lineSchemaEnt.Get <string>(lineSchema.GetField("BeamType")); // Get beam section height double beamHeight = lineSchemaEnt.Get <double>( lineSchema.GetField("SectionHeight"), DisplayUnitType.DUT_CENTIMETERS); // Get beam section width double beamWidth = lineSchemaEnt.Get <double>( lineSchema.GetField("SectionWidth"), DisplayUnitType.DUT_CENTIMETERS); // Add infos to the datatable def.DataTable.Rows.Add( lineId, lineLevel, lineLength, beamType, beamHeight, beamWidth); } ; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { if (null == _hWndRevit) { Process[] processes = Process.GetProcessesByName("Revit"); if (0 < processes.Length && processes.Any(p => p == Process.GetCurrentProcess())) { IntPtr h = Process.GetCurrentProcess().MainWindowHandle; _hWndRevit = new WindowHandle(h); } } _uiapp = commandData.Application; _uidoc = _uiapp.ActiveUIDocument; _doc = _uidoc.Document; SaveDimensionEvent handler = new SaveDimensionEvent(); _exEvent = ExternalEvent.Create(handler); _def = new DimensionEditingForm(_doc, _exEvent, handler); _def.Show(_hWndRevit); AddModelLineInfosToDataTable(_def); _def.DataGridView.CellDoubleClick += new DataGridViewCellEventHandler(dataGrid_DoubleClick); _uiapp.Application.DocumentChanged += new EventHandler <DocumentChangedEventArgs>(CtrlApp_DocumentChanged); foreach (Autodesk.Windows.RibbonTab tab in Autodesk.Windows.ComponentManager.Ribbon.Tabs) { if (tab.Id == "Modify") { tab.PropertyChanged += PanelEvent; break; } } _def.FormClosed += new FormClosedEventHandler(formClosed); return(Result.Succeeded); }