/// <summary> /// Gets the selected element. /// </summary> /// <param name="provider">The provider.</param> /// <returns></returns> public static ModelElement GetSelectedElement(IServiceProvider provider) { ModelingDocView docView = DesignerHelper.GetModelingDocView(provider); if (docView != null) { if (docView.SelectionCount == 1) { foreach (object component in docView.GetSelectedComponents()) { ShapeElement selectionShape = component as ShapeElement; ModelElement selectionElement = component as ModelElement; if (selectionShape != null) { return(selectionShape.ModelElement); } else if (selectionElement != null) { return(selectionElement); } } } } return(null); }
/// <summary> /// Gets the selected elements. /// </summary> /// <param name="provider">The provider.</param> /// <returns></returns> public static IList <object> GetSelectedElements(IServiceProvider provider) { ModelingDocView docView = DesignerHelper.GetModelingDocView(provider); if (docView != null) { if (docView.SelectionCount > 0) { IList <object> elements = new List <object>(docView.SelectionCount); foreach (object component in docView.GetSelectedComponents()) { ShapeElement selectedShape = component as ShapeElement; ModelElement selectedElement = component as ModelElement; if (selectedShape != null) { elements.Add(selectedShape.ModelElement); } else if (selectedElement != null) { elements.Add(selectedElement); } } return(elements); } } return(null); }