public void ShowElements(List <MonitorMessage> selectedMessages) { try { UIDocument uidoc = m_app.ActiveUIDocument; List <ElementId> selectedIds = new List <ElementId>(); #if RELEASE2013 || RELEASE2014 SelElementSet selElements = SelElementSet.Create(); foreach (MonitorMessage message in selectedMessages) { selElements.Add(message.ElementObj); selectedIds.Add(message.ElementObj.Id); } uidoc.Selection.Elements = selElements; uidoc.ShowElements(selectedIds); #elif RELEASE2015 || RELEASE2016 || RELEASE2017 foreach (MonitorMessage message in selectedMessages) { selectedIds.Add(message.ElementObj.Id); } uidoc.Selection.SetElementIds(selectedIds); uidoc.ShowElements(selectedIds); #endif } catch (Exception ex) { MessageBox.Show("Failed to show elements.\n" + ex.Message, "Show Elements", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void menuViewElement_Click(object sender, EventArgs e) { using (Transaction trans = new Transaction(doc)) { try { trans.Start("Show Elements"); UIDocument uidoc = m_app.ActiveUIDocument; List <ElementId> elementIds = new List <ElementId>(); #if RELEASE2013 || RELEASE2014 SelElementSet newSelection = SelElementSet.Create(); foreach (DataGridViewRow row in dataGridViewRoom.SelectedRows) { if (null != row.Tag) { RoomProperties rp = row.Tag as RoomProperties; ElementId elementId = new ElementId(rp.ID); Element element = doc.GetElement(elementId); if (null != element) { newSelection.Add(element); elementIds.Add(elementId); } } } uidoc.ShowElements(elementIds); uidoc.Selection.Elements = newSelection; #elif RELEASE2015 || RELEASE2016 Selection selection = uidoc.Selection; foreach (DataGridViewRow row in dataGridViewRoom.SelectedRows) { if (null != row.Tag) { RoomProperties rp = row.Tag as RoomProperties; ElementId elementId = new ElementId(rp.ID); Element element = doc.GetElement(elementId); if (null != element) { elementIds.Add(elementId); } } } uidoc.ShowElements(elementIds); selection.SetElementIds(elementIds); #endif trans.Commit(); } catch (Exception ex) { MessageBox.Show("Failed to view elements.\n" + ex.Message, "Form_RoomMass: menuViewElement_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning); trans.RollBack(); } } }
//execute or cancel private void HighlightElement(bool execute, Document doc) { try { UIDocument uidoc = new UIDocument(doc); using (Transaction trans = new Transaction(doc)) { trans.Start("Highlight"); try { Element element = m_doc.GetElement(new ElementId(currentElement.ElementId)); if (null != element) { if (execute) { #if RELEASE2013 || RELEASE2014 SelElementSet selElements = SelElementSet.Create(); selElements.Add(element); uidoc.Selection.Elements = selElements; uidoc.ShowElements(element); #elif RELEASE2015 || RELEASE2016 List <ElementId> selectedIds = new List <ElementId>(); selectedIds.Add(element.Id); uidoc.Selection.SetElementIds(selectedIds); uidoc.ShowElements(element.Id); #endif } else { #if RELEASE2013 || RELEASE2014 SelElementSet selElementSet = SelElementSet.Create(); uidoc.Selection.Elements = selElementSet; #elif RELEASE2015 || RELEASE2016 uidoc.Selection.SetElementIds(new List <ElementId>()); #endif } uidoc.RefreshActiveView(); } trans.Commit(); } catch (Exception ex) { MessageBox.Show(currentElement.ElementName + ": Failed to highlight elements.\n" + ex.Message, "Highlight Element", MessageBoxButton.OK, MessageBoxImage.Warning); trans.RollBack(); } } } catch (Exception ex) { MessageBox.Show("Failed to highlight elements.\n" + ex.Message, "Highlight Elements", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public override void selectElements(List <string> elementIds) { SelElementSet elementsToBeSelected = SelElementSet.Create(); elementIds.ForEach(eId => { Element e = doc.GetElement(new ElementId(int.Parse(eId))); if (e != null) { elementsToBeSelected.Add(e); } }); uidoc.Selection.Elements = elementsToBeSelected; uidoc.RefreshActiveView(); }
private void showElementToolStripMenuItem_Click(object sender, EventArgs e) { try { UIDocument uidoc = m_app.ActiveUIDocument; Document m_doc = uidoc.Document; List <ElementId> elementIds = new List <ElementId>(); #if RELEASE2013 || RELEASE2014 SelElementSet newSelection = SelElementSet.Create(); foreach (DataGridViewRow row in dataGridViewElement.SelectedRows) { if (null != row.Tag) { ElementProperties ep = row.Tag as ElementProperties; ElementId elementId = new ElementId(ep.ElementId); elementIds.Add(elementId); newSelection.Add(ep.ElementObj); } } uidoc.ShowElements(elementIds); uidoc.Selection.Elements = newSelection; #elif RELEASE2015 || RELEASE2016 Selection selection = uidoc.Selection; foreach (DataGridViewRow row in dataGridViewElement.SelectedRows) { if (null != row.Tag) { ElementProperties ep = row.Tag as ElementProperties; ElementId elementId = new ElementId(ep.ElementId); elementIds.Add(elementId); } } uidoc.ShowElements(elementIds); selection.SetElementIds(elementIds); #endif } catch (Exception ex) { MessageBox.Show("Failed to show elements.\n" + ex.Message, "Form_OverlapMass:buttonDetermine_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning); LogFileManager.AppendLog("showElementToolStripMenuItem_Click", ex.Message); } }
private void showElementToolStripMenuItem_Click(object sender, EventArgs e) { try { UIDocument uidoc = m_app.ActiveUIDocument; Document m_doc = uidoc.Document; List <ElementId> elementIds = new List <ElementId>(); #if RELEASE2013 || RELEASE2014 SelElementSet newSelection = SelElementSet.Create(); foreach (DataGridViewRow row in dataGridViewElement.SelectedRows) { if (null != row.Tag) { ElementProperties ep = row.Tag as ElementProperties; ElementId elementId = new ElementId(ep.ElementId); elementIds.Add(elementId); newSelection.Add(ep.ElementObj); } } uidoc.ShowElements(elementIds); uidoc.Selection.Elements = newSelection; #else Selection selection = uidoc.Selection; foreach (DataGridViewRow row in dataGridViewElement.SelectedRows) { if (null != row.Tag) { ElementProperties ep = row.Tag as ElementProperties; ElementId elementId = new ElementId(ep.ElementId); elementIds.Add(elementId); } } uidoc.ShowElements(elementIds); selection.SetElementIds(elementIds); #endif } catch (Exception ex) { Log.AppendLog(LogMessageType.EXCEPTION, ex.Message); } }
public void selectElements(List <Component> components) { #if REVIT2014 SelElementSet elementsToBeSelected = SelElementSet.Create(); components.ForEach(component => { Element e = doc.GetElement(new ElementId(int.Parse(component.AuthoringToolId))); if (e != null) { elementsToBeSelected.Add(e); } }); uidoc.Selection.Elements = elementsToBeSelected; uidoc.RefreshActiveView(); #else List <ElementId> elementsToBeSelected = new List <ElementId>(); components.ForEach(component => elementsToBeSelected.Add(new ElementId(int.Parse(component.AuthoringToolId)))); uidoc.Selection.SetElementIds(elementsToBeSelected); #endif }
/// <summary> /// External Event Implementation /// </summary> /// <param name="app"></param> public void Execute(UIApplication app) { try { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; SelElementSet m_elementsToHide = SelElementSet.Create(); List <ElementId> elementids = new List <ElementId>(); // IS ORTHOGONAL if (v.OrthogonalCamera != null) { if (v.OrthogonalCamera.ViewToWorldScale == null || v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null) { return; } //type = "OrthogonalCamera"; var zoom = UnitUtils.ConvertToInternalUnits(v.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS); var CameraDirection = Utils.GetXYZ(v.OrthogonalCamera.CameraDirection.X, v.OrthogonalCamera.CameraDirection.Y, v.OrthogonalCamera.CameraDirection.Z); var CameraUpVector = Utils.GetXYZ(v.OrthogonalCamera.CameraUpVector.X, v.OrthogonalCamera.CameraUpVector.Y, v.OrthogonalCamera.CameraUpVector.Z); var CameraViewPoint = Utils.GetXYZ(v.OrthogonalCamera.CameraViewPoint.X, v.OrthogonalCamera.CameraViewPoint.Y, v.OrthogonalCamera.CameraViewPoint.Z); var orient3d = Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D orthoView = null; //if active view is 3d ortho use it if (doc.ActiveView.ViewType == ViewType.ThreeD) { View3D ActiveView3D = doc.ActiveView as View3D; if (!ActiveView3D.IsPerspective) { orthoView = ActiveView3D; } } if (orthoView == null) { IEnumerable <View3D> viewcollector3D = get3DViews(doc); //try to use default 3D view if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").Any()) { orthoView = viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").First(); } } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open orthogonal view") == TransactionStatus.Started) { //create a new 3d ortho view if (orthoView == null) { orthoView = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id); orthoView.Name = "BCFortho"; } orthoView.SetOrientation(orient3d); trans.Commit(); } } uidoc.ActiveView = orthoView; //adjust view rectangle // **** CUSTOM VALUE FOR TEKLA **** // // double x = touple.Item2 // **** CUSTOM VALUE FOR TEKLA **** // double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; double x = zoom / customZoomValue; XYZ m_xyzTl = uidoc.ActiveView.Origin.Add(uidoc.ActiveView.UpDirection.Multiply(x)).Subtract(uidoc.ActiveView.RightDirection.Multiply(x)); XYZ m_xyzBr = uidoc.ActiveView.Origin.Subtract(uidoc.ActiveView.UpDirection.Multiply(x)).Add(uidoc.ActiveView.RightDirection.Multiply(x)); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else if (v.PerspectiveCamera != null) { if (v.PerspectiveCamera.FieldOfView == null || v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null) { return; } var zoom = v.PerspectiveCamera.FieldOfView; double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //focale 1 double z = 18 / Math.Tan(25 / 2 * Math.PI / 180); //focale, da controllare il 18, vedi PDF double factor = z1 - z; var CameraDirection = Utils.GetXYZ(v.PerspectiveCamera.CameraDirection.X, v.PerspectiveCamera.CameraDirection.Y, v.PerspectiveCamera.CameraDirection.Z); var CameraUpVector = Utils.GetXYZ(v.PerspectiveCamera.CameraUpVector.X, v.PerspectiveCamera.CameraUpVector.Y, v.PerspectiveCamera.CameraUpVector.Z); XYZ oldO = Utils.GetXYZ(v.PerspectiveCamera.CameraViewPoint.X, v.PerspectiveCamera.CameraViewPoint.Y, v.PerspectiveCamera.CameraViewPoint.Z); var CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor))); var orient3d = Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D perspView = null; IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "BCFpersp").Any()) { perspView = viewcollector3D.Where(o => o.Name == "BCFpersp").First(); } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open perspective view") == TransactionStatus.Started) { if (null == perspView) { perspView = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id); perspView.Name = "BCFpersp"; } perspView.SetOrientation(orient3d); // turn off the far clip plane with standard parameter API if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(0); } perspView.CropBoxActive = true; perspView.CropBoxVisible = true; trans.Commit(); } } uidoc.ActiveView = perspView; } else if (v.SheetCamera != null)//sheet { //using (Transaction trans = new Transaction(uidoc.Document)) //{ // if (trans.Start("Open sheet view") == TransactionStatus.Started) // { IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID); if (!viewcollectorSheet.Any()) { MessageBox.Show("No Sheet with Id=" + v.SheetCamera.SheetID + " found."); return; } uidoc.ActiveView = viewcollectorSheet.First(); uidoc.RefreshActiveView(); // trans.Commit(); // } //} XYZ m_xyzTl = new XYZ(v.SheetCamera.TopLeft.X, v.SheetCamera.TopLeft.Y, v.SheetCamera.TopLeft.Z); XYZ m_xyzBr = new XYZ(v.SheetCamera.BottomRight.X, v.SheetCamera.BottomRight.Y, v.SheetCamera.BottomRight.Z); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else { return; } //select/hide elements if (v.Components != null && v.Components.Any()) { FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = collector.ToElementIds(); foreach (var e in v.Components) { var bcfguid = IfcGuid.FromIfcGUID(e.IfcGuid); var ids = collection.Where(o => bcfguid == ExportUtils.GetExportId(doc, o)); if (ids.Any()) { m_elementsToHide.Add(doc.GetElement(ids.First())); elementids.Add(ids.First()); } } if (null != m_elementsToHide && !m_elementsToHide.IsEmpty) { //do transaction only if there is something to hide/select using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Apply visibility/selection") == TransactionStatus.Started) { if (MySettings.Get("selattachedelems") == "0") { uidoc.ActiveView.IsolateElementsTemporary(elementids); } else { uidoc.Selection.Elements = m_elementsToHide; } } trans.Commit(); } } } uidoc.RefreshActiveView(); } catch (Exception ex) { TaskDialog.Show("Error!", "exception: " + ex); } }
/// <summary> /// External Event Implementation /// </summary> /// <param name="app"></param> public void Execute(UIApplication app) { try { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; SelElementSet m_elementsToHide = SelElementSet.Create(); List <ElementId> elementsToBeIsolated = new List <ElementId>(); List <ElementId> elementsToBeHidden = new List <ElementId>(); List <ElementId> elementsToBeSelected = new List <ElementId>(); // IS ORTHOGONAL if (v.OrthogonalCamera != null) { if (v.OrthogonalCamera.ViewToWorldScale == null || v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null) { return; } //type = "OrthogonalCamera"; var zoom = UnitUtils.ConvertToInternalUnits(v.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS); var CameraDirection = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.OrthogonalCamera.CameraDirection.X, v.OrthogonalCamera.CameraDirection.Y, v.OrthogonalCamera.CameraDirection.Z); var CameraUpVector = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.OrthogonalCamera.CameraUpVector.X, v.OrthogonalCamera.CameraUpVector.Y, v.OrthogonalCamera.CameraUpVector.Z); var CameraViewPoint = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.OrthogonalCamera.CameraViewPoint.X, v.OrthogonalCamera.CameraViewPoint.Y, v.OrthogonalCamera.CameraViewPoint.Z); var orient3d = ARUP.IssueTracker.Revit.Classes.Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D orthoView = null; //if active view is 3d ortho use it if (doc.ActiveView.ViewType == ViewType.ThreeD) { View3D ActiveView3D = doc.ActiveView as View3D; if (!ActiveView3D.IsPerspective) { orthoView = ActiveView3D; } } if (orthoView == null) { IEnumerable <View3D> viewcollector3D = get3DViews(doc); //try to use default 3D view if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").Any()) { orthoView = viewcollector3D.Where(o => o.Name == "{3D}" || o.Name == "BCFortho").First(); } } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open orthogonal view") == TransactionStatus.Started) { //create a new 3d ortho view if (orthoView == null) { orthoView = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id); orthoView.Name = "BCFortho"; } orthoView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); orthoView.SetOrientation(orient3d); trans.Commit(); } } uidoc.ActiveView = orthoView; //adjust view rectangle // **** CUSTOM VALUE FOR TEKLA **** // // double x = touple.Item2 // **** CUSTOM VALUE FOR TEKLA **** // double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; double x = zoom / customZoomValue; XYZ m_xyzTl = uidoc.ActiveView.Origin.Add(uidoc.ActiveView.UpDirection.Multiply(x)).Subtract(uidoc.ActiveView.RightDirection.Multiply(x)); XYZ m_xyzBr = uidoc.ActiveView.Origin.Subtract(uidoc.ActiveView.UpDirection.Multiply(x)).Add(uidoc.ActiveView.RightDirection.Multiply(x)); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else if (v.PerspectiveCamera != null) { if (v.PerspectiveCamera.FieldOfView == null || v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null) { return; } var zoom = v.PerspectiveCamera.FieldOfView; double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //focale 1 double z = 18 / Math.Tan(25 / 2 * Math.PI / 180); //focale, da controllare il 18, vedi PDF double factor = z1 - z; var CameraDirection = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.PerspectiveCamera.CameraDirection.X, v.PerspectiveCamera.CameraDirection.Y, v.PerspectiveCamera.CameraDirection.Z); var CameraUpVector = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.PerspectiveCamera.CameraUpVector.X, v.PerspectiveCamera.CameraUpVector.Y, v.PerspectiveCamera.CameraUpVector.Z); XYZ oldO = ARUP.IssueTracker.Revit.Classes.Utils.GetXYZ(v.PerspectiveCamera.CameraViewPoint.X, v.PerspectiveCamera.CameraViewPoint.Y, v.PerspectiveCamera.CameraViewPoint.Z); var CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor))); var orient3d = ARUP.IssueTracker.Revit.Classes.Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D perspView = null; IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == "BCFpersp").Any()) { perspView = viewcollector3D.Where(o => o.Name == "BCFpersp").First(); } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open perspective view") == TransactionStatus.Started) { if (null == perspView) { perspView = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id); perspView.Name = "BCFpersp"; } perspView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); perspView.SetOrientation(orient3d); // turn on the far clip plane with standard parameter API if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(1); } // reset far clip offset if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).HasValue) { Parameter m_farClipOffset = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR); m_farClipOffset.SetValueString("35"); } // turn off the far clip plane with standard parameter API if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(0); } perspView.CropBoxActive = true; perspView.CropBoxVisible = true; trans.Commit(); } } uidoc.ActiveView = perspView; } else if (v.SheetCamera != null)//sheet { //using (Transaction trans = new Transaction(uidoc.Document)) //{ // if (trans.Start("Open sheet view") == TransactionStatus.Started) // { IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID); if (!viewcollectorSheet.Any()) { MessageBox.Show("No Sheet with Id=" + v.SheetCamera.SheetID + " found."); return; } uidoc.ActiveView = viewcollectorSheet.First(); uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); uidoc.RefreshActiveView(); // trans.Commit(); // } //} XYZ m_xyzTl = new XYZ(v.SheetCamera.TopLeft.X, v.SheetCamera.TopLeft.Y, v.SheetCamera.TopLeft.Z); XYZ m_xyzBr = new XYZ(v.SheetCamera.BottomRight.X, v.SheetCamera.BottomRight.Y, v.SheetCamera.BottomRight.Z); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else { return; } //apply BCF clipping planes to Revit section box View3D view3D = doc.ActiveView as View3D; if (view3D != null) { if (v.ClippingPlanes != null) { if (v.ClippingPlanes.Count() > 0) { var result = getBoundingBoxFromClippingPlanes(doc, v.ClippingPlanes); if (result != null) { BoundingBoxXYZ computedBox = result.Item1; Transform rotate = result.Item2; using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Apply Section Box") == TransactionStatus.Started) { view3D.IsSectionBoxActive = true; view3D.SetSectionBox(computedBox); if (rotate != null) { // Transform the View3D's section box with the rotation transform computedBox.Transform = computedBox.Transform.Multiply(rotate); // Set the section box back to the view (requires an open transaction) view3D.SetSectionBox(computedBox); } } trans.Commit(); } } } } } //select/hide elements if (v.Components != null && v.Components.Any()) { if (v.Components.Count > 100) { var result = MessageBox.Show("Too many elements attached. It may take for a while to isolate/select them. Do you want to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.No) { uidoc.RefreshActiveView(); return; } } FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = collector.ToElementIds(); foreach (var e in v.Components) { var bcfguid = IfcGuid.FromIfcGUID(e.IfcGuid); int authoringToolId = string.IsNullOrWhiteSpace(e.AuthoringToolId) ? -1 : int.Parse(e.AuthoringToolId); var ids = collection.Where(o => bcfguid == ExportUtils.GetExportId(doc, o) | authoringToolId == Convert.ToInt32(doc.GetElement(o).UniqueId.Substring(37), 16)); if (ids.Any()) { // handle visibility if (e.Visible) { elementsToBeIsolated.Add(ids.First()); } else { elementsToBeHidden.Add(ids.First()); } // handle selection if (e.Selected) { elementsToBeSelected.Add(ids.First()); } } } if (elementsToBeHidden.Count > 0) { using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Hide Elements") == TransactionStatus.Started) { uidoc.ActiveView.HideElementsTemporary(elementsToBeHidden); } trans.Commit(); } } else if (elementsToBeIsolated.Count > 0) { using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Isolate Elements") == TransactionStatus.Started) { uidoc.ActiveView.IsolateElementsTemporary(elementsToBeIsolated); } trans.Commit(); } } if (elementsToBeSelected.Count > 0) { using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Select Elements") == TransactionStatus.Started) { SelElementSet selectedElements = SelElementSet.Create(); elementsToBeSelected.ForEach(id => { selectedElements.Add(doc.GetElement(id)); }); uidoc.Selection.Elements = selectedElements; } trans.Commit(); } } } uidoc.RefreshActiveView(); } catch (Exception ex) { TaskDialog.Show("Error!", "exception: " + ex); } }
/// <summary> /// External Event Implementation /// </summary> /// <param name="app"></param> public void Execute(UIApplication app) { try { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; //Selection m_elementsToHide = uidoc.Selection; //SelElementSet.Create(); BlockingCollection <ElementId> elementsToBeIsolated = new BlockingCollection <ElementId>(); BlockingCollection <ElementId> elementsToBeHidden = new BlockingCollection <ElementId>(); BlockingCollection <ElementId> elementsToBeSelected = new BlockingCollection <ElementId>(); // IS ORTHOGONAL if (v.OrthogonalCamera != null) { if (v.OrthogonalCamera.ViewToWorldScale == null || v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null) { return; } //type = "OrthogonalCamera"; var zoom = UnitUtils.ConvertToInternalUnits(v.OrthogonalCamera.ViewToWorldScale, DisplayUnitType.DUT_METERS); var CameraDirection = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.OrthogonalCamera.CameraDirection.X, v.OrthogonalCamera.CameraDirection.Y, v.OrthogonalCamera.CameraDirection.Z); var CameraUpVector = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.OrthogonalCamera.CameraUpVector.X, v.OrthogonalCamera.CameraUpVector.Y, v.OrthogonalCamera.CameraUpVector.Z); var CameraViewPoint = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.OrthogonalCamera.CameraViewPoint.X, v.OrthogonalCamera.CameraViewPoint.Y, v.OrthogonalCamera.CameraViewPoint.Z); var orient3d = ARUP.IssueTracker.Revit.Classes.Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D orthoView = null; //if active view is 3d ortho use it if (doc.ActiveView.ViewType == ViewType.ThreeD) { View3D ActiveView3D = doc.ActiveView as View3D; if (!ActiveView3D.IsPerspective) { orthoView = ActiveView3D; } } string userDefault3dViewName = "{3D - " + app.Application.Username + "}"; string default3dViewName = "{3D}"; string userBCForthoViewName = string.Format("BCFortho_{0}", app.Application.Username); if (orthoView == null) { IEnumerable <View3D> viewcollector3D = get3DViews(doc); //find a orthographic 3D view if (viewcollector3D.Any()) { if (viewcollector3D.Where(o => o.Name == userDefault3dViewName).Any()) // 1) try to find user specific 3D view in workshared environment { orthoView = viewcollector3D.Where(o => o.Name == userDefault3dViewName).First(); } else if (viewcollector3D.Where(o => o.Name == default3dViewName).Any()) // 2) try to find the default 3D view if 1) not found { orthoView = viewcollector3D.Where(o => o.Name == default3dViewName).First(); } else if (viewcollector3D.Where(o => o.Name == userBCForthoViewName).Any()) // 3) try to find BCFortho 3D view generated by AIT previously if 2) is not found { orthoView = viewcollector3D.Where(o => o.Name == userBCForthoViewName).First(); } } } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open orthogonal view") == TransactionStatus.Started) { //create a new user-specific 3d ortho view if (orthoView == null) { orthoView = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id); orthoView.Name = userBCForthoViewName; } orthoView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); orthoView.SetOrientation(orient3d); trans.Commit(); } } uidoc.ActiveView = orthoView; //adjust view rectangle // **** CUSTOM VALUE FOR TEKLA **** // // double x = touple.Item2 // **** CUSTOM VALUE FOR TEKLA **** // double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; double x = zoom / customZoomValue; XYZ m_xyzTl = uidoc.ActiveView.Origin.Add(uidoc.ActiveView.UpDirection.Multiply(x)).Subtract(uidoc.ActiveView.RightDirection.Multiply(x)); XYZ m_xyzBr = uidoc.ActiveView.Origin.Subtract(uidoc.ActiveView.UpDirection.Multiply(x)).Add(uidoc.ActiveView.RightDirection.Multiply(x)); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else if (v.PerspectiveCamera != null) { if (v.PerspectiveCamera.FieldOfView == null || v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null) { return; } var zoom = v.PerspectiveCamera.FieldOfView; double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //focale 1 double z = 18 / Math.Tan(25 / 2 * Math.PI / 180); //focale, da controllare il 18, vedi PDF double factor = z1 - z; var CameraDirection = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.PerspectiveCamera.CameraDirection.X, v.PerspectiveCamera.CameraDirection.Y, v.PerspectiveCamera.CameraDirection.Z); var CameraUpVector = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.PerspectiveCamera.CameraUpVector.X, v.PerspectiveCamera.CameraUpVector.Y, v.PerspectiveCamera.CameraUpVector.Z); XYZ oldO = ARUP.IssueTracker.Revit.Classes.Utils.GetInternalXYZ(v.PerspectiveCamera.CameraViewPoint.X, v.PerspectiveCamera.CameraViewPoint.Y, v.PerspectiveCamera.CameraViewPoint.Z); var CameraViewPoint = (oldO.Subtract(CameraDirection.Divide(factor))); var orient3d = ARUP.IssueTracker.Revit.Classes.Utils.ConvertBasePoint(doc, CameraViewPoint, CameraDirection, CameraUpVector, true); View3D perspView = null; IEnumerable <View3D> viewcollector3D = get3DViews(doc); string userPersp3dViewName = string.Format("BCFperps_{0}", app.Application.Username); // find a perspective view if (viewcollector3D.Any() && viewcollector3D.Where(o => o.Name == userPersp3dViewName).Any()) { perspView = viewcollector3D.Where(o => o.Name == userPersp3dViewName).First(); } using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Open perspective view") == TransactionStatus.Started) { if (null == perspView) { perspView = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id); perspView.Name = userPersp3dViewName; } perspView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); perspView.SetOrientation(orient3d); // turn on the far clip plane with standard parameter API if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(1); } // reset far clip offset if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR).HasValue) { Parameter m_farClipOffset = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR); m_farClipOffset.SetValueString("35"); } // turn off the far clip plane with standard parameter API if (perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { Parameter m_farClip = perspView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(0); } perspView.CropBoxActive = true; perspView.CropBoxVisible = true; trans.Commit(); } } uidoc.ActiveView = perspView; } else if (v.SheetCamera != null)//sheet { //using (Transaction trans = new Transaction(uidoc.Document)) //{ // if (trans.Start("Open sheet view") == TransactionStatus.Started) // { IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID); if (!viewcollectorSheet.Any()) { MessageBox.Show("No Sheet with Id=" + v.SheetCamera.SheetID + " found."); return; } uidoc.ActiveView = viewcollectorSheet.First(); uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); uidoc.RefreshActiveView(); // trans.Commit(); // } //} XYZ m_xyzTl = new XYZ(v.SheetCamera.TopLeft.X, v.SheetCamera.TopLeft.Y, v.SheetCamera.TopLeft.Z); XYZ m_xyzBr = new XYZ(v.SheetCamera.BottomRight.X, v.SheetCamera.BottomRight.Y, v.SheetCamera.BottomRight.Z); uidoc.GetOpenUIViews().First().ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); } else { return; } //apply BCF clipping planes to Revit section box View3D view3D = doc.ActiveView as View3D; if (view3D != null) { // resume section box state using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Resume Section Box") == TransactionStatus.Started) { view3D.IsSectionBoxActive = false; } trans.Commit(); } if (v.ClippingPlanes != null) { if (v.ClippingPlanes.Count() > 0) { var result = getBoundingBoxFromClippingPlanes(doc, v.ClippingPlanes); if (result != null) { BoundingBoxXYZ computedBox = result.Item1; Transform rotate = result.Item2; using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Apply Section Box") == TransactionStatus.Started) { view3D.IsSectionBoxActive = true; view3D.SetSectionBox(computedBox); if (rotate != null) { // Transform the View3D's section box with the rotation transform computedBox.Transform = computedBox.Transform.Multiply(rotate); // Set the section box back to the view (requires an open transaction) view3D.SetSectionBox(computedBox); } } trans.Commit(); } } } } } // resume visibility and selection using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Resume Visibility/Selection") == TransactionStatus.Started) { #if REVIT2014 uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); uidoc.Selection.Elements.Clear(); #elif REVIT2015 uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); uidoc.Selection.SetElementIds(new List <ElementId>()); #else uidoc.ActiveView.TemporaryViewModes.DeactivateAllModes(); uidoc.Selection.SetElementIds(new List <ElementId>()); #endif } trans.Commit(); } //select/hide elements if (v.Components != null && v.Components.Any()) { //if (v.Components.Count > 100) //{ // var result = MessageBox.Show("Too many elements attached. It may take for a while to isolate/select them. Do you want to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); // if (result == MessageBoxResult.No) // { // uidoc.RefreshActiveView(); // return; // } //} revitWindow.initializeProgressWin(v.Components.Count); FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id); var allElementIds = collector.ToElementIds(); Dictionary <Guid, ElementId> exportIdElementIdDic = new Dictionary <Guid, ElementId>(); Dictionary <int, ElementId> uniqueIdElementIdDic = new Dictionary <int, ElementId>(); foreach (ElementId eId in allElementIds) { Guid guid = ExportUtils.GetExportId(doc, eId); int elementIdInteger = Convert.ToInt32(doc.GetElement(eId).UniqueId.Substring(37), 16); if (!exportIdElementIdDic.ContainsKey(guid)) { exportIdElementIdDic.Add(guid, eId); } if (!uniqueIdElementIdDic.ContainsKey(elementIdInteger)) { uniqueIdElementIdDic.Add(elementIdInteger, eId); } } //System.Threading.Tasks.Parallel.For(0, v.Components.Count, i => { for (int i = 0; i < v.Components.Count; i++) { double percentage = ((double)i / (double)v.Components.Count) * 100; revitWindow.updateProgressWin((int)percentage, i, v.Components.Count); ARUP.IssueTracker.Classes.BCF2.Component e = v.Components[i]; ElementId currentElementId = null; // find by ElementId first if OriginatingSystem is Revit if (e.OriginatingSystem != null) { if (e.OriginatingSystem.Contains("Revit") && !string.IsNullOrEmpty(e.AuthoringToolId)) { int elementId = -1; int.TryParse(e.AuthoringToolId, out elementId); if (elementId != -1) { Element ele = doc.GetElement(new ElementId(elementId)); if (ele != null) { currentElementId = ele.Id; } } } } // find by IfcGuid if ElementId not found if (currentElementId == null) { var bcfguid = IfcGuid.FromIfcGUID(e.IfcGuid); if (exportIdElementIdDic.ContainsKey(bcfguid)) { currentElementId = exportIdElementIdDic[bcfguid]; } } // find by UniqueId if IfcGuid not found if (currentElementId == null) { int authoringToolId = -1; int.TryParse(e.AuthoringToolId, out authoringToolId); if (uniqueIdElementIdDic.ContainsKey(authoringToolId)) { currentElementId = uniqueIdElementIdDic[authoringToolId]; } } if (currentElementId != null) { // handle visibility if (e.Visible) { elementsToBeIsolated.Add(currentElementId); } else { elementsToBeHidden.Add(currentElementId); } // handle selection if (e.Selected) { elementsToBeSelected.Add(currentElementId); } } } ; if (elementsToBeHidden.Count > 0) { using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Hide Elements") == TransactionStatus.Started) { uidoc.ActiveView.HideElementsTemporary(elementsToBeHidden.ToList()); } trans.Commit(); } } else if (elementsToBeIsolated.Count > 0) { using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Isolate Elements") == TransactionStatus.Started) { uidoc.ActiveView.IsolateElementsTemporary(elementsToBeIsolated.ToList()); } trans.Commit(); } } if (elementsToBeSelected.Count > 0) { using (Transaction trans = new Transaction(uidoc.Document)) { if (trans.Start("Select Elements") == TransactionStatus.Started) { #if REVIT2014 SelElementSet selectedElements = SelElementSet.Create(); elementsToBeSelected.ToList().ForEach(id => { selectedElements.Add(doc.GetElement(id)); }); uidoc.Selection.Elements = selectedElements; #else uidoc.Selection.SetElementIds(elementsToBeSelected.ToList()); #endif } trans.Commit(); } } revitWindow.disposeProgressWin(); } uidoc.RefreshActiveView(); } catch (Exception ex) { TaskDialog.Show("Error!", "exception: " + ex); } }
private void buttonShow_Click(object sender, EventArgs e) { try { if (listViewComponents.SelectedItems.Count > 0) { //Would you like to create a 3dview? if (!view3dDictionary.ContainsKey(selectedView)) { DialogResult dr = MessageBox.Show("Would you like to create a 3DView including all components for the selected issues?\n View Name:" + selectedView, "Create a 3DView", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { if (Create3DView()) { MessageBox.Show("[" + selectedView + "] was successfully created in 3DView.\n Please open this view to find the model elements.", "Created 3DView", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } UIDocument uidoc = m_app.ActiveUIDocument; List <ElementId> elementIds = new List <ElementId>(); #if RELEASE2015 Selection selection = uidoc.Selection; foreach (ListViewItem item in listViewComponents.SelectedItems) { if (null != item.Tag) { Element element = item.Tag as Element; if (null != element) { ElementId elementId = element.Id; elementIds.Add(elementId); } } } if (elementIds.Count > 0) { //uidoc.ActiveView.IsolateElementsTemporary(elementIds); uidoc.ShowElements(elementIds);//+ make selection selection.SetElementIds(elementIds);; } #else SelElementSet newSelection = SelElementSet.Create(); foreach (ListViewItem item in listViewComponents.SelectedItems) { if (null != item.Tag) { Element element = item.Tag as Element; if (null != element) { ElementId elementId = element.Id; elementIds.Add(elementId); newSelection.Add(element); } } } if (elementIds.Count > 0) { //uidoc.ActiveView.IsolateElementsTemporary(elementIds); uidoc.ShowElements(elementIds);//+ make selection uidoc.Selection.Elements = newSelection; } #endif } else { MessageBox.Show("Please select at least one component item to show elements in Revit UI.", "Select an Item.", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Failed to show Revit elements.\n" + ex.Message, "CommandForm:buttonShow_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// found the element which using the GUID /// that was assigned to the shared parameter in the shared parameters file. /// </summary> /// <param name="UniqueIdValue"></param> public void FindElement(string UniqueIdValue) { SelElementSet seleElements = m_revit.ActiveUIDocument.Selection.Elements; // all the elements of current document IEnumerator i = seleElements.GetEnumerator(); // if the selections include beams and slabs, // find out the element using the select value for display i.Reset(); bool moreElements = i.MoveNext(); while (moreElements) { // Get beams and slabs from selections Element component = i.Current as Autodesk.Revit.DB.Element; if (null == component) { moreElements = i.MoveNext(); continue; } if (null == component.Category) { moreElements = i.MoveNext(); continue; } if (("Structural Framing" != component.Category.Name) && ("Floors" != component.Category.Name)) { moreElements = i.MoveNext(); continue; } // Get "Unique ID" parameter ParameterSet attributes = component.Parameters; foreach (object o in attributes) { Parameter attribute = o as Parameter; if ("Unique ID" == attribute.Definition.Name) { if (null == attribute.AsString()) { break; } // compare if the parameter's value is the same as the selected value. // Clear the SelElementSet and add the found element into it. // So this element will highlight in Revit UI if (UniqueIdValue == attribute.AsString()) { seleElements.Clear(); seleElements.Add(component); return; } break; } } moreElements = i.MoveNext(); } }