/// <summary> /// update current Sketch3D using current UCS and settings /// </summary> private void UpdateSketch3D() { if (m_displayKind == DisplayKinds.GeometryModel) { GeometryData geomFactory; if (m_isSelectView) { geomFactory = new GeometryData(m_selected, m_currentView); m_detailLevel = ViewDetailLevel.Undefined; } else { geomFactory = new GeometryData(m_selected, m_detailLevel, m_currentView); } Graphics3DData geom3DData = geomFactory.Data3D; Graphics3DData old3DData = m_currentSketch3D.Data3D; geom3DData.CurrentUCS = old3DData.CurrentUCS; m_currentSketch3D.Data3D = geom3DData; m_currentSketch3D.Data2D = Graphics2DData.Empty; } else if (m_displayKind == DisplayKinds.AnalyticalModel) { ModelData modelFactory = new ModelData(m_selected); Graphics3DData model3DData = modelFactory.Data3D; Graphics2DData model2DData = modelFactory.Data2D; Graphics3DData old3DData = m_currentSketch3D.Data3D; model3DData.CurrentUCS = old3DData.CurrentUCS; m_currentSketch3D.Data3D = model3DData; m_currentSketch3D.Data2D = model2DData; } }
public static GeometryElement GetGeometry(this Element element, ViewDetailLevel viewDetailLevel, out Options options) { options = new Options { ComputeReferences = true, DetailLevel = viewDetailLevel }; return(GetGeometry(element, options)); }
public virtual IEnumerable <Solid> GeometrySolids(ViewDetailLevel detLev) { var opts = new Options(); opts.DetailLevel = detLev; return(this.GeometrySolids(opts)); }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static Options Options(ViewDetailLevel detailLevel, bool includeNonVisible = false, bool computeReferences = false) { Options options = new Options(); options.DetailLevel = detailLevel; options.IncludeNonVisibleObjects = includeNonVisible; options.ComputeReferences = computeReferences; return(options); }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static double FaceTriangulationFactor(this ViewDetailLevel viewDetailLevel) { switch (viewDetailLevel) { case Autodesk.Revit.DB.ViewDetailLevel.Coarse: return(0); case Autodesk.Revit.DB.ViewDetailLevel.Fine: return(1); default: return(0.5); } }
/// <summary> /// create 3D and 2D data of given GeometryElement /// </summary> /// <param name="elem"></param> /// <param name="detail"></param> /// <param name="currentView"></param> public GeometryData(Element elem, ViewDetailLevel detail, View currentView) { Options opt = Command.CommandData.Application.Application.Create.NewGeometryOptions(); opt.DetailLevel = detail; opt.ComputeReferences = false; GeometryElement geoElement = elem.get_Geometry(opt); Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ(0, 0, 0); Transform transform = Transform.CreateTranslation(xyz); AddGeoElement(geoElement, transform); m_bbox = elem.get_BoundingBox(currentView); }
public static GeometryElement GetGeometry(this Element element, ViewDetailLevel viewDetailLevel, out Options options) { options = new Options { ComputeReferences = true, DetailLevel = viewDetailLevel }; var geometry = element.get_Geometry(options); if (!(geometry?.Any() ?? false) && element is GenericForm form && !form.Combinations.IsEmpty) { geometry.Dispose(); options.IncludeNonVisibleObjects = true; return(element.get_Geometry(options)); } return(geometry); }
public static void SetViewDetailLevel(this View view, ViewDetailLevel viewDetailLevel) { if (view.ViewTemplateId != ElementId.InvalidElementId) { View viewTemplate = view.Document.GetElement(view.ViewTemplateId) as View; Parameter detailLevelParameter = viewTemplate.get_Parameter(BuiltInParameter.VIEW_DETAIL_LEVEL); if (detailLevelParameter.UserModifiable) { view.DetailLevel = viewDetailLevel; } else { BH.Engine.Reflection.Compute.RecordWarning("Could not change the view detail level because it's being controlled by the view template."); } } else { view.DetailLevel = viewDetailLevel; } }
/// <summary> /// Gets the element's valid solid list. /// </summary> /// <param name="elm"></param> /// <param name="lvl"></param> /// <returns></returns> public static List <Solid> GetSolidList(this Element elm, ViewDetailLevel lvl = default) { if (elm is null) { throw new ArgumentNullException(nameof(elm)); } if (!elm.IsValidObject) { throw new InvalidDataException(nameof(elm)); } var opt = new Options { ComputeReferences = true, DetailLevel = lvl }; var ge = elm.get_Geometry(opt); return(ge is null ? new List <Solid>() : ge.GetSolidList()); }
public static IEnumerable <GeometryObject> GetGeometryObjects(Element element, ViewDetailLevel viewDetailLevel) { List <GeometryObject> _geometry = new List <GeometryObject>(); Options _options = new Options(); _options.DetailLevel = viewDetailLevel; _options.ComputeReferences = true; _options.IncludeNonVisibleObjects = true; GeometryElement _geometryElement = element.get_Geometry(_options); if (_geometryElement == null) { return(_geometry); } foreach (GeometryObject _geometryObject in _geometryElement) { if (_geometryObject is GeometryInstance _geometryInstance) { foreach (GeometryObject _geometryInstanceObject in _geometryInstance.GetInstanceGeometry()) { _geometry.Add(_geometryInstanceObject); } } else { _geometry.Add(_geometryObject); } } return(_geometry); }
public static View ViewPlan(this Document document, Autodesk.Revit.DB.Level level, string viewName = null, CurveLoop cropBox = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse) { View result = null; ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.FloorPlan); result = Autodesk.Revit.DB.ViewPlan.Create(document, vft.Id, level.Id); Modify.SetViewDetailLevel(result, viewDetailLevel); if (cropBox != null) { try { ViewCropRegionShapeManager vcrShapeMgr = result.GetCropRegionShapeManager(); result.CropBoxVisible = true; vcrShapeMgr.SetCropShape(cropBox); } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not create the Floor Plan with the provided crop box. Check if the crop box is a valid geometry and if the view's designated template accepts it to change."); } } if (viewTemplateId != null) { try { result.ViewTemplateId = viewTemplateId; } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid ElementId."); } } if (!string.IsNullOrEmpty(viewName)) { try { #if (REVIT2018 || REVIT2019) result.ViewName = viewName; #else result.Name = viewName; #endif } catch { BH.Engine.Reflection.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead."); } } return(result); }
public static bool SetSectionsProperties(Document doc, List <ElementId> viewIds, string name, bool cropboxvis, ViewDetailLevel detail, DisplayStyle viewstyle, bool annotationHid, bool importedHid, int scale) { bool all_changed = true; List <string> names = new List <string>(); for (int i = 0; i < viewIds.Count; i++) { string nam = string.Format("{0} {1}", name, (i + 1).ToString()); names.Add(nam); } for (int i = 0; i < viewIds.Count; i++) { bool result = SetSectionProperties(doc, viewIds[i], names[i], cropboxvis, detail, viewstyle, annotationHid, importedHid, scale); if (result != true) { all_changed = false; } } return(all_changed); }
public static bool SetSectionProperties(Document doc, ElementId viewId, string name, bool cropboxvis, ViewDetailLevel detail, DisplayStyle viewstyle, bool annotationHid, bool importedHid, int scale) { //Retrieve view View view = doc.GetElement(viewId) as View; bool all_changed = true; using (Transaction trans = new Transaction(doc, "Rename view")) { trans.Start(); view.Name = name; view.CropBoxVisible = cropboxvis; try { view.DetailLevel = detail; } catch { all_changed = false; } try { view.DisplayStyle = viewstyle; } catch { all_changed = false; } try { view.AreAnnotationCategoriesHidden = annotationHid; } catch { all_changed = false; } try { view.AreImportCategoriesHidden = importedHid; } catch { all_changed = false; } try { view.Scale = scale; } catch { all_changed = false; } trans.Commit(); } return(all_changed); }
public static View ViewSection(this Document document, Autodesk.Revit.DB.BoundingBoxXYZ boundingBoxXyz, string viewName = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse) { View result = null; ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.Section); result = Autodesk.Revit.DB.ViewSection.CreateSection(document, vft.Id, boundingBoxXyz); Modify.SetViewDetailLevel(result, viewDetailLevel); if (viewTemplateId != null) { try { result.ViewTemplateId = viewTemplateId; } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid ElementId."); } } if (!string.IsNullOrEmpty(viewName)) { try { #if (REVIT2018 || REVIT2019) result.ViewName = viewName; #else result.Name = viewName; #endif } catch { BH.Engine.Reflection.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead."); } } return(result); }
public static View View3D(this Document document, string viewName = null, BoundingBoxXYZ boundingBoxXyz = null, ViewOrientation3D viewOrientation3D = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse) { //for information about a perspective boundingbox and its orientation see here: //https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2014/ENU/Revit/files/GUID-A7FA8DBC-830E-482D-9B66-147399524442-htm.html View3D result = null; ViewFamilyType vft = Query.ViewFamilyType(document, ViewFamily.ThreeDimensional); result = Autodesk.Revit.DB.View3D.CreatePerspective(document, vft.Id); Modify.SetViewDetailLevel(result, viewDetailLevel); if (!string.IsNullOrEmpty(viewName)) { try { #if (REVIT2018 || REVIT2019) result.ViewName = viewName; #else result.Name = viewName; #endif } catch { BH.Engine.Reflection.Compute.RecordWarning("There is already a view named '" + viewName + "'." + " It has been named '" + result.Name + "' instead."); } } if (viewTemplateId != null) { try { result.ViewTemplateId = viewTemplateId; } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not apply the View Template of Id " + viewTemplateId + "'." + ". Please check if it's a valid ElementId."); } } if (viewOrientation3D != null) { try { result.SetOrientation(viewOrientation3D); } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not set the view's orientation in 3D due to unexpected values, please report this error."); } } if (boundingBoxXyz != null) { try { //transform to view coordinates previously picked points BoundingBoxXYZ bb = result.get_BoundingBox(result); Transform transform = bb.Transform; bb.Max = transform.Inverse.OfPoint(boundingBoxXyz.Max); bb.Min = transform.Inverse.OfPoint(boundingBoxXyz.Min); result.CropBox = bb; //changes the view's far clip to the the eye and target line's length (x1.5 offset) result.SetParameter(BuiltInParameter.VIEWER_BOUND_OFFSET_FAR, boundingBoxXyz.Min.DistanceTo(boundingBoxXyz.Max) * 1.5); } catch (Exception) { BH.Engine.Reflection.Compute.RecordWarning("Could not set the view's bounding box due to unexpected values, please report this error."); } } return(result); }
public static View View3D(this Document document, XYZ eye, XYZ target, double horizontalFieldOfView, double viewRatio = 0.5625, string viewName = null, ElementId viewTemplateId = null, ViewDetailLevel viewDetailLevel = ViewDetailLevel.Coarse) { XYZ normal = (target - eye).Normalize(); XYZ planarEye = new XYZ(eye.X, eye.Y, 0); XYZ planarTarget = new XYZ(target.X, target.Y, 0); XYZ planarNormal = (planarTarget - planarEye).Normalize(); //get vertical and horizontal angle double verticalAngle = (XYZ.BasisZ.AngleTo(normal) - Math.PI / 2) * (-1); double horizontalAngle = XYZ.BasisX.AngleOnPlaneTo(planarNormal, XYZ.BasisZ); //create view orientation ViewOrientation3D viewOrientation3D = new ViewOrientation3D(eye, CombineHorizontalWithVerticalAngles(horizontalAngle, verticalAngle + Math.PI / 2), CombineHorizontalWithVerticalAngles(horizontalAngle, verticalAngle)); //information can be found here //https://knowledge.autodesk.com/support/revit-products/learn-explore/caas/CloudHelp/cloudhelp/2014/ENU/Revit/files/GUID-A7FA8DBC-830E-482D-9B66-147399524442-htm.html //rotate center point to the right side, representing HFOV start point double angleToRotate = Math.PI / 2; Transform t1 = Transform.CreateRotationAtPoint(XYZ.BasisZ, angleToRotate * -1, target); XYZ rotate = target.Add((horizontalFieldOfView / 2) * (planarNormal * -1)); XYZ hfovLeft = t1.OfPoint(rotate); XYZ bottomLeft = hfovLeft.Add(((viewRatio * horizontalFieldOfView) / 2) * (viewOrientation3D.UpDirection * -1)); //for the right Transform t2 = Transform.CreateRotationAtPoint(XYZ.BasisZ, angleToRotate, target); XYZ hfovRight = t2.OfPoint(rotate); XYZ topRight = hfovRight.Add(((viewRatio * horizontalFieldOfView) / 2) * viewOrientation3D.UpDirection); //lines for top and bottom Line topLine = Line.CreateBound(topRight, eye); Line bottomLine = Line.CreateBound(bottomLeft, eye); // to calculate bb max/min offset we need to perform an inverse regression estimate using y=A+B/x double a = 0.9995538525; //constant for THIS inverse regression double b = -0.08573511; //constant for THIS inverse regression //get line-based element's length double cameraLength = planarEye.DistanceTo(planarTarget); double evaluateLines = a + (b / cameraLength); //creates plane to project point at and retrieve cropbox.min BH.oM.Geometry.Plane backClippingPlane = BH.Engine.Geometry.Create.Plane(BH.Revit.Engine.Core.Convert.PointFromRevit(target), BH.Revit.Engine.Core.Convert.VectorFromRevit(viewOrientation3D.ForwardDirection)); BH.oM.Geometry.Point pointToProject = BH.Revit.Engine.Core.Convert.PointFromRevit(bottomLine.Evaluate(evaluateLines, true)); BH.oM.Geometry.Point bbBhomMin = backClippingPlane.ClosestPoint(pointToProject); XYZ bbMin = BH.Revit.Engine.Core.Convert.ToRevit(bbBhomMin); XYZ bbMax = topLine.Evaluate(evaluateLines, true); BoundingBoxXYZ boundingBox3DCone = new BoundingBoxXYZ(); boundingBox3DCone.Max = bbMax; boundingBox3DCone.Min = bbMin; return(View3D(document, viewName, boundingBox3DCone, viewOrientation3D, viewTemplateId, viewDetailLevel)); }