private static void ResetView(UIDocument uiDocument, View3D view) { using var trans = new Transaction(uiDocument.Document); if (trans.Start($"Reset view '{view.Name}'") != TransactionStatus.Started) { return; } Log.Information("Removing current selection ..."); uiDocument.Selection.SetElementIds(new List <ElementId>()); view.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); view.DisableTemporaryViewMode(TemporaryViewMode.RevealHiddenElements); view.IsSectionBoxActive = false; var currentlyHiddenElements = uiDocument.Document.GetHiddenElementsOfView(view).ToList(); if (currentlyHiddenElements.Any()) { Log.Information("Unhide {n} currently hidden elements ...", currentlyHiddenElements.Count); view.UnhideElements(currentlyHiddenElements); } trans.Commit(); }
private void IsolateElement(bool execute, Document doc) { try { UIDocument uidoc = new UIDocument(doc); Element element = m_doc.GetElement(new ElementId(currentElement.ElementId)); if (null != element && null != activeView) { if (activeView.IsInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate)) { using (Transaction trans = new Transaction(doc)) { trans.Start("Reset View"); try { activeView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); uidoc.RefreshActiveView(); trans.Commit(); } catch { trans.RollBack(); } } } if (execute) { using (Transaction trans = new Transaction(doc)) { trans.Start("Isolate"); try { List <ElementId> elementIds = new List <ElementId>(); elementIds.Add(element.Id); activeView.IsolateElementsTemporary(elementIds); uidoc.RefreshActiveView(); trans.Commit(); } catch { trans.RollBack(); } } } } } catch (Exception ex) { MessageBox.Show("Failed to highlight elements.\n" + ex.Message, "Highlight Elements", MessageBoxButton.OK, MessageBoxImage.Warning); } }
/// <summary> /// /// </summary> /// <param name="bcfView"></param> /// <param name="removeHighlight"></param> /// <param name="removeIsolate"></param> /// <param name="removeSectionBox"></param> private void CleanViewSettings(View3D bcfView, bool removeHighlight, bool removeIsolate, bool removeSectionBox) { using (var trans = new Transaction(ActiveDoc)) { trans.Start("Clean Views"); try { var uidoc = new UIDocument(ActiveDoc); if (removeHighlight) { //remove selection uidoc.Selection.SetElementIds(new List <ElementId>()); } if (removeIsolate) { //remove isolation if (bcfView.IsInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate)) { bcfView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); } } if (removeSectionBox) { //remove sectionbox bcfView.GetSectionBox().Enabled = false; } trans.Commit(); } catch (Exception) { trans.RollBack(); } } }
/// <summary> /// External Event Implementation /// </summary> /// <param name="app"></param> public void Execute(UIApplication app) { try { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; var uniqueView = UserSettings.GetBool("alwaysNewView"); // IS ORTHOGONAL if (v.OrthogonalCamera != null) { if (v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null) { return; } //type = "OrthogonalCamera"; var zoom = v.OrthogonalCamera.ViewToWorldScale.ToFeet(); var cameraDirection = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraDirection); var cameraUpVector = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraUpVector); var cameraViewPoint = RevitUtils.GetRevitXYZ(v.OrthogonalCamera.CameraViewPoint); var orient3D = RevitUtils.ConvertBasePoint(doc, cameraViewPoint, cameraDirection, cameraUpVector, true); View3D orthoView = null; //if active view is 3d ortho use it if (doc.ActiveView.ViewType == ViewType.ThreeD) { var activeView3D = doc.ActiveView as View3D; if (!activeView3D.IsPerspective) { orthoView = activeView3D; } } if (orthoView == null) { //try to use an existing 3D view IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any(o => o.Name == "{3D}" || o.Name == "BCFortho")) { orthoView = viewcollector3D.First(o => o.Name == "{3D}" || o.Name == "BCFortho"); } } using (var trans = new Transaction(uidoc.Document)) { if (trans.Start("Open orthogonal view") == TransactionStatus.Started) { //create a new 3d ortho view if (orthoView == null || uniqueView) { orthoView = View3D.CreateIsometric(doc, getFamilyViews(doc).First().Id); orthoView.Name = (uniqueView) ? "BCFortho" + DateTime.Now.ToString("yyyyMMddTHHmmss") : "BCFortho"; } else { //reusing an existing view, I net to reset the visibility //placed this here because if set afterwards it doesn't work orthoView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); } orthoView.SetOrientation(orient3D); trans.Commit(); } } uidoc.ActiveView = orthoView; //adjust view rectangle // **** CUSTOM VALUE FOR TEKLA **** // // double x = zoom / 2.5; // **** CUSTOM VALUE FOR TEKLA **** // double x = zoom; //if(MySettings.Get("optTekla")=="1") // x = zoom / 2.5; //set UI view position and zoom 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); } //perspective else if (v.PerspectiveCamera != null) { if (v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null) { return; } //not used since the fov cannot be changed in Revit var zoom = v.PerspectiveCamera.FieldOfView; //FOV - not used //double z1 = 18 / Math.Tan(zoom / 2 * Math.PI / 180); //double z = 18 / Math.Tan(25 / 2 * Math.PI / 180); //double factor = z1 - z; var cameraDirection = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraDirection); var cameraUpVector = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraUpVector); var cameraViewPoint = RevitUtils.GetRevitXYZ(v.PerspectiveCamera.CameraViewPoint); var orient3D = RevitUtils.ConvertBasePoint(doc, cameraViewPoint, cameraDirection, cameraUpVector, true); View3D perspView = null; //try to use an existing 3D view IEnumerable <View3D> viewcollector3D = get3DViews(doc); if (viewcollector3D.Any(o => o.Name == "BCFpersp")) { perspView = viewcollector3D.First(o => o.Name == "BCFpersp"); } using (var trans = new Transaction(uidoc.Document)) { if (trans.Start("Open perspective view") == TransactionStatus.Started) { if (null == perspView || uniqueView) { perspView = View3D.CreatePerspective(doc, getFamilyViews(doc).First().Id); perspView.Name = (uniqueView) ? "BCFpersp" + DateTime.Now.ToString("yyyyMMddTHHmmss") : "BCFpersp"; } else { //reusing an existing view, I net to reset the visibility //placed this here because if set afterwards it doesn't work perspView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); } perspView.SetOrientation(orient3D); // turn off the far clip plane 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; } //sheet else if (v.SheetCamera != null) { IEnumerable <View> viewcollectorSheet = getSheets(doc, v.SheetCamera.SheetID); if (!viewcollectorSheet.Any()) { MessageBox.Show("View " + v.SheetCamera.SheetName + " with Id=" + v.SheetCamera.SheetID + " not found."); return; } uidoc.ActiveView = viewcollectorSheet.First(); uidoc.RefreshActiveView(); 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); } //no view included else { return; } if (v.Components == null) { return; } var elementsToSelect = new List <ElementId>(); var elementsToHide = new List <ElementId>(); var elementsToShow = new List <ElementId>(); var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .ToElementIds() .Where(e => doc.GetElement(e).CanBeHidden(doc.ActiveView)); //might affect performance, but it's necessary bool canSetVisibility = (v.Components.Visibility != null && v.Components.Visibility.DefaultVisibilitySpecified && v.Components.Visibility.Exceptions.Any()) ; bool canSetSelection = (v.Components.Selection != null && v.Components.Selection.Any()); //loop elements foreach (var e in visibleElems) { var guid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, e)); if (canSetVisibility) { if (v.Components.Visibility.DefaultVisibility) { if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid)) { elementsToHide.Add(e); } } else { if (v.Components.Visibility.Exceptions.Any(x => x.IfcGuid == guid)) { elementsToShow.Add(e); } } } if (canSetSelection) { if (v.Components.Selection.Any(x => x.IfcGuid == guid)) { elementsToSelect.Add(e); } } } using (var trans = new Transaction(uidoc.Document)) { if (trans.Start("Apply BCF visibility and selection") == TransactionStatus.Started) { if (elementsToHide.Any()) { doc.ActiveView.HideElementsTemporary(elementsToHide); } //there are no items to hide, therefore hide everything and just show the visible ones else if (elementsToShow.Any()) { doc.ActiveView.IsolateElementsTemporary(elementsToShow); } if (elementsToSelect.Any()) { uidoc.Selection.SetElementIds(elementsToSelect); } } 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); } }