// zoom active view to element in linked doc // how to zoom elements in linked document using revit api? // https://forums.autodesk.com/t5/revit-api-forum/how-to-zoom-elements-in-linked-document-using-revit-api/m-p/9778123 // use LinkElementId class? void ZoomToLinkedElement( UIDocument uidoc, RevitLinkInstance link, ElementId id) { Document doc = uidoc.Document; View view = doc.ActiveView; // Determine active UIView to use UIView uiView = uidoc .GetOpenUIViews() .FirstOrDefault <UIView>(uv => uv.ViewId.Equals(view.Id)); Element e = doc.GetElement(id); LocationPoint lp = e.Location as LocationPoint; Transform transform1 = link.GetTransform(); XYZ newLocation2 = transform1.OfPoint(lp.Point); BoundingBoxXYZ bb = e.get_BoundingBox(doc.ActiveView); uiView.ZoomAndCenterRectangle( new XYZ(newLocation2.X - 4, newLocation2.Y - 4, newLocation2.Z - 4), new XYZ(newLocation2.X + 4, newLocation2.Y + 4, newLocation2.Z + 4)); }
/// <summary> /// Return UI data about current view /// </summary> /// <param name="uidoc"></param> /// <returns></returns> public static UIView GetActiveUIView(UIDocument uidoc) { UIView uiview = null; if (uidoc == null) { return(uiview); } View activeView = uidoc.Document.ActiveView; //Get all open views as uiview IList <UIView> uiviews = uidoc.GetOpenUIViews(); if (uiviews.Count == 0) { return(uiview); } //Loop through all open uiviews to get uiview of active view foreach (UIView uv in uiviews) { if (uv.ViewId.Equals(activeView.Id)) { uiview = uv; break; } } return(uiview); }
}//close method public static void OpenView(UIApplication uiapp) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; try { IList <UIView> uiviews = uidoc.GetOpenUIViews(); UIView uiview = null; View currentView = null; foreach (UIView uv in uiviews) { if (uv.ViewId.Equals(doc.ActiveView.Id)) { currentView = doc.ActiveView; uiview = uv; break; } } uiview.Close(); uidoc.ActiveView = currentView; } catch { } }
/// <inheritdoc/> internal override int Execute(string args = null) { var readonlyViews = new List <ViewType>() { ViewType.ProjectBrowser, ViewType.SystemBrowser, ViewType.Undefined, ViewType.DrawingSheet, ViewType.Internal }; var openUiViews = _uiDoc.GetOpenUIViews(); var openViews = new List <ElementId>(); foreach (var ov in openUiViews) { openViews.Add(ov.ViewId); } IList <Element> schedules = new FilteredElementCollector(_uiDoc.Document) .OfClass(typeof(ViewSchedule)) .WhereElementIsNotElementType() .Where(sch => ConfirmRemoval(sch as View)) .ToList(); if (schedules.Count > 0) { return(HelperMethods.RemoveElements(Name, _uiDoc.Document, schedules)); } return(0); bool ConfirmRemoval(View view) { if (view.GetType() == typeof(ViewSchedule)) { if (readonlyViews.Contains(view.ViewType)) { return(false); } if (view.IsTemplate) { return(false); } if (view.Name.Contains("<")) { return(false); } if (openViews.Contains(view.Id)) { return(false); } if (((ViewSchedule)view).Definition.CategoryId.IntegerValue == (int)BuiltInCategory.OST_KeynoteTags) { return(false); } return(true); } return(false); } }
//?? public static UIView ActiveUiview(this UIDocument uidoc) { var acview = uidoc.ActiveView; var uiviews = uidoc.GetOpenUIViews(); var acuiview = uiviews.Where(m => acview.Id == m.ViewId).FirstOrDefault(); return(acuiview); }
private static void CloseSchedules(UIDocument uiDoc, Element view) { var openViews = uiDoc.GetOpenUIViews(); var countOpenViews = uiDoc.GetOpenUIViews().Count; foreach (var uiView in openViews) { if (countOpenViews == 1) { break; } if (view.Id == uiView.ViewId) { uiView.Close(); } countOpenViews -= 1; } }
public static UIView ActiveUIView(this UIDocument uidoc) { var result = default(UIView); var doc = uidoc.Document; var acview = doc.ActiveView; var uiviews = uidoc.GetOpenUIViews(); result = uiviews.FirstOrDefault(m => m.ViewId == acview.Id); return(result); }
private static float GetViewBoxHeight(this UIDocument uiDocument) { var zoomCorners = uiDocument.GetOpenUIViews()[0].GetZoomCorners(); XYZ bottomLeft = zoomCorners[0]; XYZ topRight = zoomCorners[1]; var(viewBoxHeight, _) = RevitUtils.ConvertToViewBoxValues(topRight, bottomLeft, uiDocument.ActiveView.RightDirection); return(Convert.ToSingle(viewBoxHeight.ToMeters())); }
public static UIView ActiveUIView(UIDocument uiDoc, Element currentView) { if (uiDoc == null || currentView == null) { return(null); } return((from openUIView in uiDoc.GetOpenUIViews() let view = uiDoc.Document.GetElement(openUIView.ViewId) where view.Name == currentView.Name select openUIView).FirstOrDefault()); }
//checks if a view with the specified name is currently open public bool ViewIsOpen(string name) { View v = GetView(name); //make sure we have a view to work with, if we dont it doesnt exist and therefore cane not be open if (v == null) { return(false); } //get a list of all open views and check if the oen we are checking for is open IList <UIView> openViews = uiDoc.GetOpenUIViews(); foreach (UIView uiV in openViews) { if (uiV.ViewId.Equals(v.Id)) { return(true);//we found the view and it is open } } return(false); }
public static UIView ActiveUIView(UIDocument udoc, Element planView) { if (udoc != null && planView != null) { foreach (UIView view in udoc.GetOpenUIViews()) { View v = (View)udoc.Document.GetElement(view.ViewId); if (v.Name == planView.Name) { return(view); } } } return(null); }
/// <summary> /// Возвращает текущее активное окно /// </summary> /// <param name="uidoc"></param> /// <returns></returns> private UIView get_active_ui_view(UIDocument uidoc) { var activeView = uidoc.Document.ActiveView; var uiViews = uidoc.GetOpenUIViews(); // Возвращает все открытые виды UIView uiview = null; foreach (var view in uiViews) { if (view.ViewId.Equals(activeView.Id)) { uiview = view; break; } } return(uiview); }
//获取轴号信息 public CalcGridInfoResult GetGridNumberShowInfo(bool bIdling, Rect formRec, ref System.Drawing.Point formLeftTopPt, ref Size formSize) { if (m_uiDoc == null) { return(CalcGridInfoResult._Error); } if (m_uiView == null) { IList <UIView> openUIViews = m_uiDoc.GetOpenUIViews(); foreach (UIView uiview in openUIViews) { if (uiview.ViewId == m_uiDoc.ActiveView.Id) { m_uiView = uiview; break; } } } if (m_uiView == null) { return(CalcGridInfoResult._Error); } GetLinkInstances(); m_OutViewInfos.Clear(); m_DrawElems.Clear(); m_GridNumShowInfos.Clear(); CalcGridInfoResult result = GetCurrentViewOutLine(bIdling, formRec, ref formSize, ref formLeftTopPt); if (result != CalcGridInfoResult._Succeded) { return(result); } GetAllGridInfo(); GetAllMultiSegmentGridInfo(); GetAllLevelInfo(); GetAllLevelInfoInLinkDoc(); if (m_DrawElems.Count <= 0) { return(CalcGridInfoResult._Error); } GetIntersectPtAndDirection(); if (m_GridNumShowInfos.Count <= 0) { return(CalcGridInfoResult._Error); } return(CalcGridInfoResult._Succeded); }
//Convert Document hiện hành thành UIView private UIView GetActiveUiView(UIDocument uidoc) { Document doc = uidoc.Document; View view = doc.ActiveView; IList <UIView> uiviews = uidoc.GetOpenUIViews(); UIView uiview = null; foreach (UIView uv in uiviews) { if (uv.ViewId.Equals(view.Id)) { uiview = uv; break; } } return(uiview); }
private static UIView GetUIView(UIDocument uidoc) { IList <UIView> UIViews = uidoc.GetOpenUIViews(); var activeViewId = uidoc.Document.ActiveView.Id; UIView uiView = null; for (int i = 0; i < UIViews.Count(); i++) { if (UIViews[i].ViewId == activeViewId) { uiView = UIViews[i]; break; } } return(uiView); }
public void Showview(Document doc, UIDocument uidoc, ICollection <ElementId> elementIds, string viewname) { //View3D view = Get3Dview(doc); //List<XYZ> pointsmax = new List<XYZ>(); //List<XYZ> pointsmin = new List<XYZ>(); //foreach (var i in elementIds) //{ // Element element = doc.GetElement(i); // BoundingBoxXYZ boxXYZ = element.get_BoundingBox(view); // XYZ max = boxXYZ.Max; // XYZ min = boxXYZ.Min; // pointsmax.Add(max); // pointsmin.Add(min); //} //var Bpoint = new Maxpoint(pointsmax); //var Vpoint = new Minpoint(pointsmin); //XYZ Maxpoint = new XYZ(Bpoint.Xmax, Bpoint.Ymax, Bpoint.Zmax); //XYZ Minpoint = new XYZ(Vpoint.Xmin, Vpoint.Ymin, Vpoint.Zmin); //BoundingBoxXYZ viewSectionBox = new BoundingBoxXYZ(); //viewSectionBox.Max = Maxpoint; //viewSectionBox.Min = Minpoint; //using (Transaction tx = new Transaction(doc)) //{ // tx.Start("Move And Resize Section Box"); // view.SetSectionBox(viewSectionBox); // tx.Commit(); //} //uidoc.ActiveView = view; //uidoc.Selection.SetElementIds(elementIds); //uidoc.RefreshActiveView(); //uidoc.ShowElements(elementIds); SetBoundingBox(doc, elementIds); uidoc.Selection.SetElementIds(elementIds); foreach (UIView uiview in uidoc.GetOpenUIViews()) { Autodesk.Revit.DB.View view = uidoc.Document.GetElement(uiview.ViewId) as Autodesk.Revit.DB.View; bool flag = ((view != null) ? view.Name : null) == viewname; if (flag) { uiview.ZoomToFit(); break; } } }
/// <summary> /// Return currently active UIView or null. /// </summary> public static UIView GetActiveUiView( UIDocument uidoc) { Document doc = uidoc.Document; Autodesk.Revit.DB.View view = doc.ActiveView; IList <UIView> uiviews = uidoc.GetOpenUIViews(); UIView uiview = null; foreach (UIView uv in uiviews) { if (uv.ViewId.Equals(view.Id)) { uiview = uv; break; } } return(uiview); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; //List<View> views = new List<View>(); List <UIView> views = uidoc.GetOpenUIViews() as List <UIView>; if (views.Count > 1) { View view = doc.GetElement(views[1].ViewId) as View; uidoc.RequestViewChange(view); } else { ; } return(Result.Succeeded); }
private UIView FindDefaultUIView(View3D bcfView) { UIView uiview = null; try { var uidoc = new UIDocument(ActiveDoc); var uiviews = uidoc.GetOpenUIViews(); var viewFound = from view in uiviews where view.ViewId == bcfView.Id select view; if (viewFound.Any()) { uiview = viewFound.First(); } } catch (Exception) { // ignored } return(uiview); }
/// <summary> /// 居中显示模型 /// </summary> /// <param name="UIDoc"></param> /// <param name="ele"></param> public static void ElementCenterDisplay(UIDocument UIDoc, Element ele) { if (ele == null) { return; } XYZ point = new XYZ(); LocationPoint locationPoint = ele.Location as LocationPoint; if (locationPoint != null) { point = locationPoint.Point; } else { LocationCurve locationCurve = ele.Location as LocationCurve; XYZ pointStart = locationCurve.Curve.GetEndPoint(0); XYZ pointEnd = locationCurve.Curve.GetEndPoint(1); point = (pointStart + pointEnd) / 2; } XYZ viewCornor1 = new XYZ(point.X - 10, point.Y - 10, 0); XYZ viewCornor2 = new XYZ(point.X + 10, point.Y + 10, 0); Document doc = UIDoc.Document; IList <UIView> views = UIDoc.GetOpenUIViews(); UIView uiView = null; foreach (var uiview in views) { if (uiview.ViewId.Equals(doc.ActiveView.Id)) { uiView = uiview; break; } } uiView.ZoomAndCenterRectangle(viewCornor1, viewCornor2); UIDoc.ShowElements(ele); }
/// <inheritdoc/> internal override int Execute(string args = null) { var openUIViews = _uiDoc.GetOpenUIViews(); foreach (var ov in openUIViews) { openViews.Add(ov.ViewId); } IList <Element> sheets = new FilteredElementCollector(_uiDoc.Document).OfCategory(BuiltInCategory.OST_Sheets) .WhereElementIsNotElementType() .Where(sheet => ConfirmRemoval(sheet) == true) .ToList(); if (sheets.Count > 0) { return(HelperMethods.RemoveElements(Name, _uiDoc.Document, sheets)); } else { return(0); } }
private static Position GetCameraPosition(this UIDocument uiDocument, bool isPerspective) { ProjectPosition projectPosition = uiDocument.Document.ActiveProjectLocation.GetProjectPosition(XYZ.Zero); var zoomCorners = uiDocument.GetOpenUIViews()[0].GetZoomCorners(); XYZ bottomLeft = zoomCorners[0]; XYZ topRight = zoomCorners[1]; XYZ viewCenter = uiDocument.ActiveView.Origin; if (!isPerspective) { viewCenter = new XYZ((topRight.X + bottomLeft.X) / 2, (topRight.Y + bottomLeft.Y) / 2, (topRight.Z + bottomLeft.Z) / 2); } return(RevitUtils.TransformCameraPosition( new ProjectPositionWrapper(projectPosition), new Position( viewCenter.ToVector3(), uiDocument.ActiveView.ViewDirection.ToVector3(), uiDocument.ActiveView.UpDirection.ToVector3()))); }
/// <summary> /// 屏幕点转为空间三维点. /// </summary> /// <param name="view">指定转换到的视图.</param> /// <param name="point">指定屏幕上的点.</param> /// <returns></returns> public static XYZ ScreenToWorld(this View view, System.Drawing.Point point) { if (view == null) { throw new NullReferenceException(); } var uiDoc = new UIDocument(view.Document); var uiView = uiDoc.GetOpenUIViews().FirstOrDefault(m => m.ViewId == view.Id); if (uiView == null) { throw new NullReferenceException(); } var rect = uiView.GetWindowRectangle(); var corners = uiView.GetZoomCorners(); var mousePoint = new XYZ(point.X, point.Y, 0); var screenLeftlower = new XYZ(rect.Left, rect.Bottom, 0); var screenRightupper = new XYZ(rect.Right, rect.Top, 0); // 换算比例 var scale = corners[0].DistanceTo(corners[1]) / screenLeftlower.DistanceTo(screenRightupper); var xdis = (point.X - screenLeftlower.X) * scale; var ydis = (screenLeftlower.Y - point.Y) * scale; var vp = uiDoc.ActiveView.UpDirection; var vr = uiDoc.ActiveView.RightDirection; var distance = mousePoint.DistanceTo(screenLeftlower) * scale; var result = corners[0] + vr * xdis + vp * ydis; return(result); }
/// <summary> /// Generate Viewpoint /// </summary> /// <param name="elemCheck"></param> /// <returns></returns> public VisualizationInfo generateViewpoint(int elemCheck) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; VisualizationInfo v = new VisualizationInfo(); XYZ centerIMP = new XYZ(); string type = ""; double zoomValue = 1; if (uidoc.ActiveView.ViewType != ViewType.ThreeD) //is a 2D view { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; v.SheetCamera = new SheetCamera(); v.SheetCamera.SheetID = uidoc.ActiveView.Id.IntegerValue; v.SheetCamera.TopLeft = new IssueTracker.Classes.BCF2.Point(TL.X, TL.Y, TL.Z); v.SheetCamera.BottomRight = new IssueTracker.Classes.BCF2.Point(BR.X, BR.Y, BR.Z); } else { View3D view3D = (View3D)uidoc.ActiveView; if (!view3D.IsPerspective) //IS ORTHO { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; double xO = (TL.X + BR.X) / 2; double yO = (TL.Y + BR.Y) / 2; double zO = (TL.Z + BR.Z) / 2; //converto to METERS centerIMP = new XYZ(xO, yO, zO); double dist = TL.DistanceTo(BR) / 2; //custom sectet value to get solibri zoom value from Corners of Revit UiView XYZ diagVector = TL.Subtract(BR); // **** CUSTOM VALUE FOR TEKLA **** // //zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS); // **** CUSTOM VALUE FOR TEKLA **** // double customZoomValue = (MyProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS) * customZoomValue; type = "OrthogonalCamera"; } else // it is a perspective view { centerIMP = uidoc.ActiveView.Origin; type = "PerspectiveCamera"; zoomValue = 45; } ViewOrientation3D t = ConvertBasePoint(centerIMP, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); //ViewOrientation3D t = new ViewOrientation3D(centerIMP, uidoc.ActiveView.UpDirection, uidoc.ActiveView.ViewDirection); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; if (type == "OrthogonalCamera") { v.OrthogonalCamera = new OrthogonalCamera(); v.OrthogonalCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.ViewToWorldScale = zoomValue; } else { v.PerspectiveCamera = new PerspectiveCamera(); v.PerspectiveCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.FieldOfView = zoomValue; } // handle section box if enabled if (view3D.IsSectionBoxActive) { BoundingBoxXYZ sectionBox = view3D.GetSectionBox(); // Note that the section box can be rotated and transformed. // So the min/max corners coordinates relative to the model must be computed via the transform. Transform trf = sectionBox.Transform; XYZ max = sectionBox.Max; //Maximum coordinates (upper-right-front corner of the box before transform is applied). XYZ min = sectionBox.Min; //Minimum coordinates (lower-left-rear corner of the box before transform is applied). // Transform the min and max to model coordinates XYZ maxInModelCoords = trf.OfPoint(max); XYZ minInModelCoords = trf.OfPoint(min); // Convert to project unit DisplayUnitType lengthUnitType = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits; maxInModelCoords = new XYZ(UnitUtils.ConvertFromInternalUnits(maxInModelCoords.X, lengthUnitType), UnitUtils.ConvertFromInternalUnits(maxInModelCoords.Y, lengthUnitType), UnitUtils.ConvertFromInternalUnits(maxInModelCoords.Z, lengthUnitType)); minInModelCoords = new XYZ(UnitUtils.ConvertFromInternalUnits(minInModelCoords.X, lengthUnitType), UnitUtils.ConvertFromInternalUnits(minInModelCoords.Y, lengthUnitType), UnitUtils.ConvertFromInternalUnits(minInModelCoords.Z, lengthUnitType)); // Convert to shared coordinates maxInModelCoords = ARUP.IssueTracker.Revit.Classes.Utils.ConvertToFromSharedCoordinate(doc, maxInModelCoords, false); minInModelCoords = ARUP.IssueTracker.Revit.Classes.Utils.ConvertToFromSharedCoordinate(doc, minInModelCoords, false); // Add to BCF clipping planes v.ClippingPlanes = BcfAdapter.GetClippingPlanesFromBoundingBox ( maxInModelCoords.X, maxInModelCoords.Y, maxInModelCoords.Z, minInModelCoords.X, minInModelCoords.Y, minInModelCoords.Z ); } } //COMPONENTS PART FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = null; if (elemCheck == 0) { collection = collector.ToElementIds(); } else if (elemCheck == 1) { collection = uidoc.Selection.GetElementIds(); } if (null != collection && collection.Any()) { v.Components = new List <IssueTracker.Classes.BCF2.Component>(); foreach (var eId in collection) { Guid guid = ExportUtils.GetExportId(doc, eId); string ifcguid = IfcGuid.ToIfcGuid(guid).ToString(); v.Components.Add(new ARUP.IssueTracker.Classes.BCF2.Component(doc.Application.VersionName, eId.ToString(), ifcguid)); } } return(v); } catch (System.Exception ex1) { TaskDialog.Show("Error!", "exception: " + ex1); } return(null); }
private void performShowSolid() { // maybe we don't need a transaction right here? if (_selectedItems == null) { return; } try { double xMin = 9999999; double xMax = -999999999; double yMin = 99999999; double yMax = -999999999; double zMin = 99999999; double zMax = -99999999; List <Solid> solids = new List <Solid>(); List <double> values = new List <double>(); foreach (var item in _selectedItems) { BoundingBoxXYZ box = Utilities.RevitUtils.DeserializeBoundingBox(item.BoundingBoxDescription); if (box != null) { // take care of boxes that are smaller than the curve tolerance. if (Utilities.RevitUtils.IsBoxTooSmall(_uiDoc.Application.Application, box)) { box = Utilities.RevitUtils.GrowBox(_uiDoc.Application.Application, box, _uiDoc.Application.Application.ShortCurveTolerance * 2.0); } Solid s = Utilities.RevitUtils.CreateSolidFromBox(_uiDoc.Application.Application, box); if (s != null) { solids.Add(s); values.Add(1.0); } // see if the box is bigger. If so, expand it. if (box.Min.X < xMin) { xMin = box.Min.X; } if (box.Min.Y < yMin) { yMin = box.Min.Y; } if (box.Min.Z < zMin) { zMin = box.Min.Z; } if (box.Max.X > xMax) { xMax = box.Max.X; } if (box.Max.Y > yMax) { yMax = box.Max.Y; } if (box.Max.Z > zMax) { zMax = box.Max.Z; } } } Utilities.AVFUtility.ShowSolids(_uiDoc.Document, solids, values); UIView v = _uiDoc.GetOpenUIViews().FirstOrDefault(); if (v != null) { BoundingBoxXYZ bigBox = new BoundingBoxXYZ() { Min = new XYZ(xMin, yMin, zMin), Max = new XYZ(xMax, yMax, zMax) }; v.ZoomAndCenterRectangle(bigBox.Min, bigBox.Max); } } catch (Exception ex) { // swallow. MessageBox.Show("Error: " + ex); } }
internal static int PurgeAllViews(UIDocument uiDoc, Type viewClassToPurge, int viewTypeToPurge, string actionTitle, bool keepReferenced = false) { var openUiViews = uiDoc.GetOpenUIViews(); var openViews = new List <ElementId>(); foreach (var ov in openUiViews) { openViews.Add(ov.ViewId); } var readonlyViews = new List <ViewType>() { ViewType.ProjectBrowser, ViewType.SystemBrowser, ViewType.Undefined, ViewType.DrawingSheet, ViewType.Internal }; bool IsReferenced(View view) { var viewRefs = new FilteredElementCollector(uiDoc.Document) .OfCategory(BuiltInCategory.OST_ReferenceViewer) .WhereElementIsNotElementType() .ToElements(); var viewRefsIds = new List <ElementId>(); foreach (var viewRef in viewRefs) { var refParam = viewRef.get_Parameter(BuiltInParameter.REFERENCE_VIEWER_TARGET_VIEW); viewRefsIds.Add(refParam.AsElementId()); } var refSheet = view.get_Parameter(BuiltInParameter.VIEW_REFERENCING_SHEET); var refViewport = view.get_Parameter(BuiltInParameter.VIEW_REFERENCING_DETAIL); if ((!(refSheet is null) && !(refViewport is null) && refSheet.AsString() != string.Empty && refViewport.AsString() != string.Empty) || viewRefsIds.Contains(view.Id)) { return(true); } return(false); } bool ConfirmRemoval(View view) { if (view.GetType().IsSubclassOf(viewClassToPurge) || view.GetType() == viewClassToPurge) { if (viewTypeToPurge != 0 && (int)view.ViewType != viewTypeToPurge) { return(false); } if (readonlyViews.Contains(view.ViewType)) { return(false); } if (view.IsTemplate) { return(false); } if (view.ViewType == ViewType.ThreeD && view.Name == "{3D}") { return(false); } if (view.Name.Contains("<")) { return(false); } if (openViews.Contains(view.Id)) { return(false); } if (keepReferenced && IsReferenced(view)) { return(false); } return(true); } return(false); } IList <Element> views = new FilteredElementCollector(uiDoc.Document) .OfClass(viewClassToPurge) .WhereElementIsNotElementType() .Where(v => ConfirmRemoval(v as View)) .ToList(); return(RemoveElements(actionTitle, uiDoc.Document, views)); }
public static void Place(UIApplication uiapp, TextLeaderPosition _textLeader, double _textWidth, double _leaderLength) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; IList <UIView> uiviews = uidoc.GetOpenUIViews(); UIView uiview = null; foreach (UIView uv in uiviews) { if (uv.ViewId.Equals(doc.ActiveView.Id)) { uiview = uv; break; } } IList <XYZ> corners = uiview.GetZoomCorners(); XYZ p = corners[0]; XYZ q = corners[1]; XYZ v = q - p; XYZ center = p + 0.5 * v; try { using (Transaction tran = new Transaction(doc, "Text note created")) { if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)) { //uses PresentationCore string textNoteContent = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString(); //double width = 3.0 / 12.0; // feet on paper TextNoteOptions options = new TextNoteOptions(); options.HorizontalAlignment = HorizontalTextAlignment.Left; options.TypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); double noteWidth = _textWidth / 12; tran.Start(); TextNote note = TextNote.Create(doc, doc.ActiveView.Id, center, textNoteContent, options); note.Width = noteWidth; if (_textLeader == TextLeaderPosition.Both) { note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_L); Leader lead = note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R); note.LeaderLeftAttachment = LeaderAtachement.TopLine; note.LeaderRightAttachment = LeaderAtachement.TopLine; note.Width = noteWidth; lead.End = new XYZ(center.X + _leaderLength, center.Y - 0.8, center.Z); } else if (_textLeader == TextLeaderPosition.Left) { note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_L); note.LeaderLeftAttachment = LeaderAtachement.TopLine; note.Width = noteWidth; } else if (_textLeader == TextLeaderPosition.Right) { Leader lead = note.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R); note.LeaderRightAttachment = LeaderAtachement.TopLine; note.Width = noteWidth; //lead.Elbow = new XYZ(center.X, center.Y, center.Z); lead.End = new XYZ(center.X + _leaderLength, center.Y - 0.8, center.Z); } tran.Commit(); } else { TaskDialog.Show("Warning", "Clipboard is empty. Try to copy something."); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } }
//<summary> //Generate a VisualizationInfo of the current view //</summary> //<returns></returns> public static VisualizationInfo GenerateViewpoint(UIDocument uidoc) { try { var doc = uidoc.Document; var v = new VisualizationInfo(); //Corners of the active UI view var topLeft = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; var bottomRight = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; //It's a 2D view //not supported by BCF, but I store it under a custom //fields using 2D coordinates and sheet id if (uidoc.ActiveView.ViewType != ViewType.ThreeD) { v.SheetCamera = new SheetCamera { SheetID = uidoc.ActiveView.Id.IntegerValue, TopLeft = new Point { X = topLeft.X, Y = topLeft.Y, Z = topLeft.Z }, BottomRight = new Point { X = bottomRight.X, Y = bottomRight.Y, Z = bottomRight.Z } }; } //It's a 3d view else { var viewCenter = new XYZ(); var view3D = (View3D)uidoc.ActiveView; double zoomValue = 1; // it is a orthogonal view if (!view3D.IsPerspective) { double x = (topLeft.X + bottomRight.X) / 2; double y = (topLeft.Y + bottomRight.Y) / 2; double z = (topLeft.Z + bottomRight.Z) / 2; //center of the UI view viewCenter = new XYZ(x, y, z); //vector going from BR to TL XYZ diagVector = topLeft.Subtract(bottomRight); //length of the vector double dist = topLeft.DistanceTo(bottomRight) / 2; //ViewToWorldScale value zoomValue = dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)).ToMeters(); // **** CUSTOM VALUE FOR TEKLA **** // // calculated experimentally, not sure why but it works //if (UserSettings.Get("optTekla") == "1") // zoomValue = zoomValue * 2.5; // **** CUSTOM VALUE FOR TEKLA **** // ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; v.OrthogonalCamera = new OrthogonalCamera { CameraViewPoint = { X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }, CameraUpVector = { X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }, CameraDirection = { X = vi.X.ToMeters() * -1, Y = vi.Y.ToMeters() * -1, Z = vi.Z.ToMeters() * -1 }, ViewToWorldScale = zoomValue }; } // it is a perspective view else { viewCenter = uidoc.ActiveView.Origin; //revit default value zoomValue = 45; ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; v.PerspectiveCamera = new PerspectiveCamera { CameraViewPoint = { X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }, CameraUpVector = { X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }, CameraDirection = { X = vi.X.ToMeters() * -1, Y = vi.Y.ToMeters() * -1, Z = vi.Z.ToMeters() * -1 }, FieldOfView = zoomValue }; } } //COMPONENTS PART string versionName = doc.Application.VersionName; v.Components = new List<Component>(); var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .ToElementIds(); var hiddenElems = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .Where(x => x.IsHidden(doc.ActiveView) || !doc.ActiveView.IsElementVisibleInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate, x.Id)).ToList();//would need to check how much this is affecting performance var selectedElems = uidoc.Selection.GetElementIds(); //include only hidden elements and selected in the BCF if (visibleElems.Count() > hiddenElems.Count()) { foreach (var elem in hiddenElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem.Id)), Visible = false, Selected = false, AuthoringToolId = elem.Id.IntegerValue.ToString() }); } foreach (var elem in selectedElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)), Visible = true, Selected = true, AuthoringToolId = elem.IntegerValue.ToString() }); } } //include only visible elements //all the others are hidden else { foreach (var elem in visibleElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)), Visible = true, Selected = selectedElems.Contains(elem), AuthoringToolId = elem.IntegerValue.ToString() }); } } return v; } catch (System.Exception ex1) { TaskDialog.Show("Error generating viewpoint", "exception: " + ex1); } return null; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; Document doc = commandData.Application.ActiveUIDocument.Document; UIDocument uidoc = commandData.Application.ActiveUIDocument; ElementId sheetId = null; if (doc.ActiveView is ViewSheet) { message = "Active view can not be a sheet!"; return(Result.Failed); } List <ElementId> sheedIds = new List <ElementId>(); foreach (UIView uiview in uidoc.GetOpenUIViews()) { if (doc.GetElement(uiview.ViewId) is ViewSheet) { sheedIds.Add(uiview.ViewId); } } if (sheedIds.Count == 0) { message = "No sheets are open, or a viewport is activated."; return(Result.Failed); } int selectedSheet = 0; if (sheedIds.Count > 1) { List <string> sheetNames = new List <string>(); foreach (ElementId id in sheedIds) { Element e = doc.GetElement(id); sheetNames.Add(e.Name); } WindowSelectSheet dialog = new WindowSelectSheet(sheetNames); dialog.ShowDialog(); if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { selectedSheet = dialog.comboSheet.SelectedIndex; } else { return(Result.Cancelled); } } sheetId = sheedIds[selectedSheet]; if (Viewport.CanAddViewToSheet(doc, sheetId, doc.ActiveView.Id)) { using (Transaction t1 = new Transaction(doc, "Add active view to opened sheet")) { t1.Start(); Viewport.Create(doc, sheetId, doc.ActiveView.Id, new XYZ(0, 0, 0)); t1.Commit(); } } else { message = "Active view can not be added to sheet. Maybe it is on a sheet already?"; return(Result.Failed); } uidoc.RequestViewChange(doc.GetElement(sheetId) as View); return(Result.Succeeded); }
/// <summary> /// Generate Viewpoint /// </summary> /// <param name="elemCheck"></param> /// <returns></returns> private VisualizationInfo generateViewpoint(int elemCheck) { try { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; VisualizationInfo v = new VisualizationInfo(); XYZ centerIMP = new XYZ(); string type = ""; double zoomValue = 1; if (uidoc.ActiveView.ViewType != ViewType.ThreeD) //is a 2D view { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; v.SheetCamera = new SheetCamera(); v.SheetCamera.SheetID = uidoc.ActiveView.Id.IntegerValue; v.SheetCamera.TopLeft = new IssueTracker.Data.Point(TL.X, TL.Y, TL.Z); v.SheetCamera.BottomRight = new IssueTracker.Data.Point(BR.X, BR.Y, BR.Z); } else { View3D view3D = (View3D)uidoc.ActiveView; if (!view3D.IsPerspective) //IS ORTHO { XYZ TL = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; XYZ BR = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; double xO = (TL.X + BR.X) / 2; double yO = (TL.Y + BR.Y) / 2; double zO = (TL.Z + BR.Z) / 2; //converto to METERS centerIMP = new XYZ(xO, yO, zO); double dist = TL.DistanceTo(BR) / 2; //custom value to get solibri zoom value from Corners of Revit UiView XYZ diagVector = TL.Subtract(BR); double customZoomValue = (ProjectSettings.Get("useDefaultZoom", doc.PathName) == "1") ? 1 : 2.5; zoomValue = UnitUtils.ConvertFromInternalUnits(dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)), DisplayUnitType.DUT_METERS) * customZoomValue; type = "OrthogonalCamera"; } else // it is a perspective view { centerIMP = uidoc.ActiveView.Origin; type = "PerspectiveCamera"; zoomValue = 45; } ViewOrientation3D t = ConvertBasePoint(centerIMP, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; if (type == "OrthogonalCamera") { v.OrthogonalCamera = new OrthogonalCamera(); v.OrthogonalCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.OrthogonalCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.OrthogonalCamera.ViewToWorldScale = zoomValue; } else { v.PerspectiveCamera = new PerspectiveCamera(); v.PerspectiveCamera.CameraViewPoint.X = UnitUtils.ConvertFromInternalUnits(c.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Y = UnitUtils.ConvertFromInternalUnits(c.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraViewPoint.Z = UnitUtils.ConvertFromInternalUnits(c.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.X = UnitUtils.ConvertFromInternalUnits(up.X, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Y = UnitUtils.ConvertFromInternalUnits(up.Y, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraUpVector.Z = UnitUtils.ConvertFromInternalUnits(up.Z, DisplayUnitType.DUT_METERS); v.PerspectiveCamera.CameraDirection.X = UnitUtils.ConvertFromInternalUnits(vi.X, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Y = UnitUtils.ConvertFromInternalUnits(vi.Y, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.CameraDirection.Z = UnitUtils.ConvertFromInternalUnits(vi.Z, DisplayUnitType.DUT_METERS) * -1; v.PerspectiveCamera.FieldOfView = zoomValue; } } //COMPONENTS PART FilteredElementCollector collector = new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType(); System.Collections.Generic.ICollection <ElementId> collection = null; if (elemCheck == 0) { collection = collector.ToElementIds(); } else if (elemCheck == 1) { collection = uidoc.Selection.GetElementIds(); } if (null != collection && collection.Any()) { v.Components = new IssueTracker.Data.Component[collection.Count]; for (var i = 0; i < collection.Count; i++) { Guid guid = ExportUtils.GetExportId(doc, collection.ElementAt(i)); string ifcguid = IfcGuid.ToIfcGuid(guid).ToString(); ; v.Components[i] = new Case.IssueTracker.Data.Component(doc.Application.VersionName, collection.ElementAt(i).ToString(), ifcguid); } } return(v); } catch (System.Exception ex1) { TaskDialog.Show("Error!", "exception: " + ex1); } return(null); }
//<summary> //Generate a VisualizationInfo of the current view //</summary> //<returns></returns> public static VisualizationInfo GenerateViewpoint(UIDocument uidoc) { try { var doc = uidoc.Document; var v = new VisualizationInfo(); //Corners of the active UI view var topLeft = uidoc.GetOpenUIViews()[0].GetZoomCorners()[0]; var bottomRight = uidoc.GetOpenUIViews()[0].GetZoomCorners()[1]; //It's a 2D view //not supported by BCF, but I store it under a custom //fields using 2D coordinates and sheet id if (uidoc.ActiveView.ViewType != ViewType.ThreeD) { v.SheetCamera = new SheetCamera { SheetID = uidoc.ActiveView.Id.IntegerValue, TopLeft = new Point { X = topLeft.X, Y = topLeft.Y, Z = topLeft.Z }, BottomRight = new Point { X = bottomRight.X, Y = bottomRight.Y, Z = bottomRight.Z } }; } //It's a 3d view else { var viewCenter = new XYZ(); var view3D = (View3D)uidoc.ActiveView; double zoomValue = 1; // it is a orthogonal view if (!view3D.IsPerspective) { double x = (topLeft.X + bottomRight.X) / 2; double y = (topLeft.Y + bottomRight.Y) / 2; double z = (topLeft.Z + bottomRight.Z) / 2; //center of the UI view viewCenter = new XYZ(x, y, z); //vector going from BR to TL XYZ diagVector = topLeft.Subtract(bottomRight); //length of the vector double dist = topLeft.DistanceTo(bottomRight) / 2; //ViewToWorldScale value zoomValue = dist * Math.Sin(diagVector.AngleTo(view3D.RightDirection)).ToMeters(); // **** CUSTOM VALUE FOR TEKLA **** // // calculated experimentally, not sure why but it works //if (UserSettings.Get("optTekla") == "1") // zoomValue = zoomValue * 2.5; // **** CUSTOM VALUE FOR TEKLA **** // ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; v.OrthogonalCamera = new OrthogonalCamera { CameraViewPoint = { X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }, CameraUpVector = { X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }, CameraDirection = { X = vi.X.ToMeters() * -1, Y = vi.Y.ToMeters() * -1, Z = vi.Z.ToMeters() * -1 }, ViewToWorldScale = zoomValue }; } // it is a perspective view else { viewCenter = uidoc.ActiveView.Origin; //revit default value zoomValue = 45; ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection, uidoc.ActiveView.UpDirection, false); XYZ c = t.EyePosition; XYZ vi = t.ForwardDirection; XYZ up = t.UpDirection; v.PerspectiveCamera = new PerspectiveCamera { CameraViewPoint = { X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }, CameraUpVector = { X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }, CameraDirection = { X = vi.X.ToMeters() * -1, Y = vi.Y.ToMeters() * -1, Z = vi.Z.ToMeters() * -1 }, FieldOfView = zoomValue }; } } //COMPONENTS PART string versionName = doc.Application.VersionName; v.Components = new List <Component>(); var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .ToElementIds(); var hiddenElems = new FilteredElementCollector(doc) .WhereElementIsNotElementType() .WhereElementIsViewIndependent() .Where(x => x.IsHidden(doc.ActiveView) || !doc.ActiveView.IsElementVisibleInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate, x.Id)).ToList();//would need to check how much this is affecting performance var selectedElems = uidoc.Selection.GetElementIds(); //include only hidden elements and selected in the BCF if (visibleElems.Count() > hiddenElems.Count()) { foreach (var elem in hiddenElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem.Id)), Visible = false, Selected = false, AuthoringToolId = elem.Id.IntegerValue.ToString() }); } foreach (var elem in selectedElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)), Visible = true, Selected = true, AuthoringToolId = elem.IntegerValue.ToString() }); } } //include only visible elements //all the others are hidden else { foreach (var elem in visibleElems) { v.Components.Add(new Component { OriginatingSystem = versionName, IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)), Visible = true, Selected = selectedElems.Contains(elem), AuthoringToolId = elem.IntegerValue.ToString() }); } } return(v); } catch (System.Exception ex1) { TaskDialog.Show("Error generating viewpoint", "exception: " + ex1); } return(null); }