public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { // Get application and document objects UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; UIDocument uidoc = uiApp.ActiveUIDocument; try { if (!doc.IsWorkshared) { TaskDialog.Show("Workset 3D View", "Project doesn't have any Worksets."); } else { ViewFamilyType vft = new FilteredElementCollector(doc) .OfClass(typeof(ViewFamilyType)) .Cast <ViewFamilyType>() .FirstOrDefault(q => q.ViewFamily == ViewFamily.ThreeDimensional); using (Transaction t = new Transaction(doc, "Workset View Creation")) { t.Start(); int i = 0; // Loop through all User Worksets only foreach (Workset wst in new FilteredWorksetCollector(doc) .WherePasses(new WorksetKindFilter(WorksetKind.UserWorkset))) { // Create a 3D View View3D view = View3D.CreateIsometric(doc, vft.Id); // Set the name of the view to match workset view.Name = "WORKSET - " + wst.Name; // Isolate elements in the view using a filter to find elements only in this workset view.IsolateElementsTemporary(new FilteredElementCollector(doc) .WherePasses(new ElementWorksetFilter(wst.Id)) .Select(q => q.Id) .ToList()); i++; } t.Commit(); TaskDialog.Show("Workset 3D View", i.ToString() + " Views Created Successfully!"); } } return(Result.Succeeded); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
private void ApplyViewOrientationAndVisibility(UIDocument uiDocument, View3D view, Camera camera) { using var trans = new Transaction(uiDocument.Document); if (trans.Start($"Apply view orientation and visibility in '{view.Name}'") != TransactionStatus.Started) { return; } StatusBarService.SetStatusText("Loading view point data ..."); Log.Information("Calculating view orientation from camera position ..."); ProjectPosition projectPosition = uiDocument.Document.ActiveProjectLocation.GetProjectPosition(XYZ.Zero); var viewOrientation3D = RevitUtils.TransformCameraPosition( new ProjectPositionWrapper(projectPosition), camera.Position.ToInternalUnits(), true) .ToViewOrientation3D(); if (camera.Type == CameraType.Perspective) { Log.Information("Setting active far viewer bound to zero ..."); Parameter farClip = view.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); if (farClip.HasValue) { farClip.Set(0); } } Log.Information("Applying new view orientation ..."); view.SetOrientation(viewOrientation3D); Log.Information("Applying element visibility ..."); var currentlyVisibleElements = uiDocument.Document.GetVisibleElementsOfView(view); var map = uiDocument.Document.GetIfcGuidElementIdMap(currentlyVisibleElements); var exceptionElements = GetViewpointVisibilityExceptions(map); var selectedElements = GetViewpointSelection(map); if (exceptionElements.Any()) { if (_bcfViewpoint.GetVisibilityDefault()) { view.HideElementsTemporary(exceptionElements); selectedElements = selectedElements.Where(id => !exceptionElements.Contains(id)).ToList(); } else { view.IsolateElementsTemporary(exceptionElements); selectedElements = selectedElements.Where(id => exceptionElements.Contains(id)).ToList(); } } view.ConvertTemporaryHideIsolateToPermanent(); if (selectedElements.Any()) { Log.Information("Select {n} elements ...", selectedElements.Count); uiDocument.Selection.SetElementIds(selectedElements); } trans.Commit(); }
/// <summary> /// 隔离元素集合 /// </summary> /// <param name="doc"></param> /// <param name="eles"></param> public static void IsolateElements(Document doc, IList <ElementId> eles) { View3D view3d = doc.ActiveView as View3D; if (eles != null && eles.Count != 0) { view3d.IsolateElementsTemporary(eles); } }
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); } }