/// <summary> /// Orthogonal View by Perspective Camera. /// </summary> /// <param name="bcfView"></param> /// <param name="camera"></param> /// <returns></returns> private bool SetOrthogonalView(View3D bcfView, PerspectiveCamera camera) { var result = false; try { var direction = RevitUtils.GetRevitXYZ(camera.CameraDirection); var upVector = RevitUtils.GetRevitXYZ(camera.CameraUpVector); var viewPoint = RevitUtils.GetRevitXYZ(camera.CameraViewPoint); var orientation = RevitUtils.ConvertBasePoint(ActiveDoc, viewPoint, direction, upVector, true); using (var trans = new Transaction(ActiveDoc)) { trans.Start("Set Orientation"); try { bcfView.SetOrientation(orientation); trans.Commit(); } catch (Exception) { trans.RollBack(); } } SetViewPointBoundingBox(bcfView); result = true; } catch (Exception) { // ignored } return(result); }
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> /// Creates a CableTray by two Points. /// </summary> /// <param name="cableTrayType">Type of the cable tray.</param> /// <param name="start">The start Point in WCS.</param> /// <param name="end">The end Point in WCS.</param> /// <returns></returns> public static CableTray ByPoints(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end) { Utils.Log(string.Format("CableTray.ByPoints started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var oType = cableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; var totalTransform = RevitUtils.DocumentTotalTransform(); var nstart = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = nstart.ToXyz(); var nend = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = nend.ToXyz(); TransactionManager.Instance.TransactionTaskDone(); if (nstart != null) { nstart.Dispose(); } if (nend != null) { nend.Dispose(); } Utils.Log(string.Format("CableTray.ByPoints completed.", "")); return(new CableTray(oType, s, e)); }
/// <summary> /// Creates a Conduit by a curve. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="curve">The curve.</param> /// <returns></returns> public static Conduit ByCurve(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve) { Utils.Log(string.Format("Conduit.ByCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } Utils.Log(string.Format("Conduit.ByCurve completed.", "")); return(new Conduit(oType, s, e)); }
/// <summary> /// Creates a Conduit by a curve. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="curve">The curve.</param> /// <param name="featureline">The featureline.</param> /// <returns></returns> public static Conduit ByCurveFeatureline(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve, Featureline featureline) { Utils.Log(string.Format("Conduit.ByCurveFeatureline started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var pipe = Conduit.ByCurve(conduitType, curve); // new Conduit(oType, s, e); var start = curve.StartPoint; var end = curve.EndPoint; var startSOE = featureline.GetStationOffsetElevationByPoint(start); var endSOE = featureline.GetStationOffsetElevationByPoint(end); double startStation = (double)startSOE["Station"]; double startOffset = (double)startSOE["Offset"]; double startElevation = (double)startSOE["Elevation"]; double endStation = (double)endSOE["Station"]; double endOffset = (double)endSOE["Offset"]; double endElevation = (double)endSOE["Elevation"]; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.RegionIndex.Name, featureline.BaselineRegionIndex); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionRelative.Name, startStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionNormalized.Name, (startStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(curve.StartPoint.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(curve.StartPoint.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(curve.StartPoint.Z, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round(startStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round(startOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round(startElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round(endStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round(endOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round(endElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionRelative.Name, endStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionNormalized.Name, (endStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } Utils.Log(string.Format("Conduit.ByCurveFeatureline completed.", "")); return(pipe); }
/// <summary> /// Creates a pipe by curve. /// </summary> /// <param name="pipeType">Type of the pipe.</param> /// <param name="pipingSystemType">Type of the piping system.</param> /// <param name="curve">The curve.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Pipe ByCurve(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, Autodesk.DesignScript.Geometry.Curve curve, Revit.Elements.Level level) { Utils.Log(string.Format("Pipe.ByCurve started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var totalTransform = RevitUtils.DocumentTotalTransform(); var start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); var end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } Utils.Log(string.Format("Pipe.ByCurve completed.", "")); return(new Pipe(oType, oSystemType, s, e, l)); }
/// <summary> /// Creates a PipePlaceholder by two points. /// </summary> /// <param name="pipeType">Type of the pipe.</param> /// <param name="systemType">Type of the system.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="level">The level.</param> /// <returns></returns> public static PipePlaceHolder ByPoints(Revit.Elements.Element pipeType, Revit.Elements.Element systemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level) { Utils.Log(string.Format("PipePlaceHolder.ByPoints started...", "")); var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = systemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var totalTransform = RevitUtils.DocumentTotalTransform(); var nstart = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = nstart.ToXyz(); var nend = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = nend.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; if (nstart != null) { nstart.Dispose(); } if (nend != null) { nend.Dispose(); } Utils.Log(string.Format("PipePlaceHolder.ByPoints completed.", "")); return(new PipePlaceHolder(oType, oSystemType, s, e, l)); }
/// <summary> /// Initializes a new instance of the <see cref="ShapePoint"/> class. /// </summary> /// <param name="point">The point.</param> /// <param name="featureline">The featureline.</param> /// <param name="id">The initial ID of the ShapePoint.</param> internal ShapePoint(Point point, Featureline featureline, int id = 0) { this.UniqueId = Guid.NewGuid().ToString(); this._id = id; this.Corridor = featureline.Baseline.CorridorName; this.BaselineIndex = featureline.Baseline.Index; this.RegionIndex = featureline.BaselineRegionIndex; this.Side = featureline.Side; this.Code = featureline.Code; var soe = featureline.GetStationOffsetElevationByPoint(point); this.Station = (double)soe["Station"]; this.Offset = (double)soe["Offset"]; this.Elevation = (double)soe["Elevation"]; this.RegionRelative = this.Station - featureline.Start; // 1.1.0 this.RegionNormalized = this.RegionRelative / (featureline.End - featureline.Start); // 1.1.0 this.Point = point; this.Featureline = featureline; this.RevitPoint = point.Transform(RevitUtils.DocumentTotalTransform()) as Point; }
//Raise methos when click apply button private void ApplyExecuted(object param) { _handler.ViewModel = this; AppCommand.Handler.Request.Make(ColorHandler.RequestId.SetColor); AppCommand.ExEvent.Raise(); RevitUtils.SetFocusToRevit(); }
/// <summary> /// Creates a pipe by two points. /// </summary> /// <param name="ductType">Type of the duct.</param> /// <param name="mechanicalSystemType">Type of the mechanical system.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Duct ByPoints(Revit.Elements.Element ductType, Revit.Elements.Element mechanicalSystemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level) { Utils.Log(string.Format("Duct.ByPoints started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = ductType.InternalElement as Autodesk.Revit.DB.Mechanical.DuctType; var oSystemType = mechanicalSystemType.InternalElement as Autodesk.Revit.DB.Mechanical.MechanicalSystemType; start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; totalTransform.Dispose(); Utils.Log(string.Format("Duct.ByPoints completed.", "")); return(new Duct(oType, oSystemType, s, e, l)); }
public ApplicationPlaceholderObject DirectShapeToNative(DirectShape speckleDs) { var docObj = GetExistingElementByApplicationId(speckleDs.applicationId); //just create new one if (docObj != null) { Doc.Delete(docObj.Id); } var converted = new List <GeometryObject>(); speckleDs.baseGeometries.ToList().ForEach(b => { switch (b) { case Brep brep: try { var solid = BrepToNative(brep); converted.Add(solid); } catch (Exception e) { var mesh = MeshToNative(brep.displayValue); converted.AddRange(mesh); } break; case Mesh mesh: var rMesh = MeshToNative(mesh); converted.AddRange(rMesh); break; default: ConversionErrors.Add(new Error("Incompatible geometry type", $"Type ${b.GetType()} is not supported in DirectShape conversions.")); break; } }); BuiltInCategory cat; var bic = RevitUtils.GetBuiltInCategory(speckleDs.category); BuiltInCategory.TryParse(bic, out cat); var catId = Doc.Settings.Categories.get_Item(cat).Id; var revitDs = DB.DirectShape.CreateElement(Doc, catId); revitDs.ApplicationId = speckleDs.applicationId; revitDs.ApplicationDataId = Guid.NewGuid().ToString(); revitDs.SetShape(converted); revitDs.Name = speckleDs.name; SetInstanceParameters(revitDs, speckleDs); return(new ApplicationPlaceholderObject { applicationId = speckleDs.applicationId, ApplicationGeneratedId = revitDs.UniqueId, NativeObject = revitDs }); }
/// <summary> /// Creates a pipe by curve. /// </summary> /// <param name="ductType">Type of the duct.</param> /// <param name="mechanicalSystemType">Type of the mechanical system.</param> /// <param name="level">The level.</param> /// <param name="curve">The curve.</param> /// <param name="featureline">The featureline.</param> /// <returns></returns> public static Duct ByCurveFeatureline(Revit.Elements.Element ductType, Revit.Elements.Element mechanicalSystemType, Revit.Elements.Level level, Autodesk.DesignScript.Geometry.Curve curve, Featureline featureline) { Utils.Log(string.Format("Duct.ByCurveFeatureline started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = ductType.InternalElement as Autodesk.Revit.DB.Mechanical.DuctType; var oSystemType = mechanicalSystemType.InternalElement as Autodesk.Revit.DB.Mechanical.MechanicalSystemType; var start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); var end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; var pipe = new Duct(oType, oSystemType, s, e, l); var startSOE = featureline.GetStationOffsetElevationByPoint(curve.StartPoint); var endSOE = featureline.GetStationOffsetElevationByPoint(curve.EndPoint); double startStation = (double)startSOE["Station"]; double startOffset = (double)startSOE["Offset"]; double startElevation = (double)startSOE["Elevation"]; double endStation = (double)endSOE["Station"]; double endOffset = (double)endSOE["Offset"]; double endElevation = (double)endSOE["Elevation"];; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.RegionIndex.Name, featureline.BaselineRegionIndex); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionRelative.Name, startStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionNormalized.Name, (startStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(curve.StartPoint.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(curve.StartPoint.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(curve.StartPoint.Z, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round(startStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round(startOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round(startElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round(endStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round(endOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round(endElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionRelative.Name, endStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionNormalized.Name, (endStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 totalTransform.Dispose(); Utils.Log(string.Format("Duct.ByCurveFeatureline completed.", "")); return(pipe); }
/// <summary> /// Creates a set of CableTrays following a PolyCurve specifying a maximum length. /// </summary> /// <param name="CableTrayType">The CableTray type.</param> /// <param name="polyCurve">The PolyCurve to follow.</param> /// <param name="maxLength">The maximum length of the CableTrays following the PolyCurve.</param> /// <returns></returns> private CableTray[] ByPolyCurve(Revit.Elements.Element CableTrayType, PolyCurve polyCurve, double maxLength) { Utils.Log(string.Format("CableTray.ByPolyCurve started...", "")); var oType = CableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; double length = polyCurve.Length; double subdivisions = Math.Ceiling(length / maxLength); double increment = 1 / subdivisions; IList <double> parameters = new List <double>(); double parameter = 0; IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); while (parameter <= 1) { points.Add(polyCurve.PointAtParameter(parameter)); parameter = parameter + increment; } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); IList <ElementId> ids = new List <ElementId>(); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var totalTransform = RevitUtils.DocumentTotalTransform(); for (int i = 0; i < points.Count - 1; ++i) { Autodesk.DesignScript.Geometry.Point start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = points[i + 1].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); Autodesk.Revit.DB.Electrical.CableTray p = Autodesk.Revit.DB.Electrical.CableTray.Create(DocumentManager.Instance.CurrentDBDocument, oType.Id, s, e, ElementId.InvalidElementId); ids.Add(p.Id); } for (int i = 0; i < GetCableTrayByIds(ids).Length - 1; ++i) { CableTray ct1 = GetCableTrayByIds(ids)[i]; CableTray ct2 = GetCableTrayByIds(ids)[i + 1]; Fitting.Elbow(ct1, ct2); } TransactionManager.Instance.TransactionTaskDone(); Utils.Log(string.Format("CableTray.ByPolyCurve completed.", "")); return(GetCableTrayByIds(ids)); }
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())); }
private PerspectiveCamera GetPerspectiveCamera(View3D view, string viewpoint_Guid) { var camera = new PerspectiveCamera(); try { var viewCenter = view.Origin; double zoomValue = 45; var orientation = RevitUtils.ConvertBasePoint(ActiveDoc, viewCenter, view.ViewDirection, view.UpDirection, false); var c = orientation.EyePosition; var vi = orientation.ForwardDirection; var up = orientation.UpDirection; camera.Guid = Guid.NewGuid().ToString(); camera.ViewPointGuid = viewpoint_Guid; var viewPoint = new Schemas.Point { Guid = Guid.NewGuid().ToString(), X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }; camera.CameraViewPoint = viewPoint; var upVector = new Direction { Guid = Guid.NewGuid().ToString(), X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }; camera.CameraUpVector = upVector; var direction = new Direction { Guid = Guid.NewGuid().ToString(), X = -(vi.X.ToMeters()), Y = -(vi.Y.ToMeters()), Z = -(vi.Z.ToMeters()) }; camera.CameraDirection = direction; camera.FieldOfView = zoomValue; } catch (Exception) { // ignored } return(camera); }
private DirectShape DirectShapeToSpeckle(DB.DirectShape revitAc) { var cat = ((BuiltInCategory)revitAc.Category.Id.IntegerValue).ToString(); var category = RevitUtils.GetCategory(cat); var element = revitAc.get_Geometry(new Options()); var geometries = element.ToList().Select <GeometryObject, Base>(obj => { return(obj switch { DB.Mesh mesh => MeshToSpeckle(mesh), Solid solid => BrepToSpeckle(solid), _ => null }); });
private bool SetPerspectiveView(View3D bcfView, PerspectiveCamera camera) { var result = false; try { var zoom = camera.FieldOfView; var direction = RevitUtils.GetRevitXYZ(camera.CameraDirection); var upVector = RevitUtils.GetRevitXYZ(camera.CameraUpVector); var viewPoint = RevitUtils.GetRevitXYZ(camera.CameraViewPoint); var orientation = RevitUtils.ConvertBasePoint(ActiveDoc, viewPoint, direction, upVector, true); using (var trans = new Transaction(ActiveDoc)) { trans.Start("Set Orientation"); try { if (bcfView.CanResetCameraTarget()) { bcfView.ResetCameraTarget(); } bcfView.SetOrientation(orientation); if (bcfView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR).HasValue) { var m_farClip = bcfView.get_Parameter(BuiltInParameter.VIEWER_BOUND_ACTIVE_FAR); m_farClip.Set(0); } bcfView.CropBoxActive = true; bcfView.CropBoxVisible = true; trans.Commit(); } catch (Exception) { trans.RollBack(); } } result = true; } catch (Exception) { // ignored } return(result); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; Application app = commandData.Application.Application; // internal agreement: abuse KeyValuePair to pass plugin operation state and objects KeyValuePair <Result, SpaceSyntax> kvSpaceSyntax = FileOpenService.PromtUserForSpaceSyntaxXml(); if (kvSpaceSyntax.Key != Result.Succeeded) { return(kvSpaceSyntax.Key); } SpaceSyntax spaceSyntax = kvSpaceSyntax.Value; KeyValuePair <Result, Level> kvSelectedLevel = new KeyValuePair <Result, Level>(Result.Failed, null); if (!string.IsNullOrEmpty(spaceSyntax.ScenarioName)) { kvSelectedLevel = RevitUtils.AttemptToGetLevelByScenarioName(doc, spaceSyntax.ScenarioName); } if (kvSelectedLevel.Key != Result.Succeeded) { kvSelectedLevel = UserLevelSelectService.LetUserPickLevelFromDialog(doc); } if (kvSelectedLevel.Key != Result.Succeeded) { return(kvSelectedLevel.Key); } Level level = kvSelectedLevel.Value; KeyValuePair <Result, PlanarFace> kvTopFace = RevitUtils.GetTopFaceFromLevel(app, level); if (kvSelectedLevel.Key != Result.Succeeded) { return(kvSelectedLevel.Key); } PlanarFace topFace = kvTopFace.Value; Result result = RevitVisualizationService.CreateSpaceSyntaxAnalysisResult(doc, spaceSyntax, topFace); return(result); }
/// <summary> /// Sets a callback that applies a zoom to the current view. /// </summary> /// <param name="app">The current UI application.</param> /// <param name="viewId">The view ID for the view to be zoomed.</param> /// <param name="zoom">The zoom in decimal precision.</param> public static void SetPendingZoomChangedCallback(UIApplication app, ElementId viewId, decimal zoom) { void Callback(object sender, IdlingEventArgs args) { StatusBarService.SetStatusText("Zooming to scale '" + zoom + "' ..."); UIView currentView = app.ActiveUIDocument.GetOpenUIViews().First(); if (currentView.ViewId != viewId) { return; } UIDocument uiDoc = app.ActiveUIDocument; View activeView = uiDoc.ActiveView; var zoomCorners = currentView.GetZoomCorners(); XYZ bottomLeft = zoomCorners[0]; XYZ topRight = zoomCorners[1]; var(currentHeight, currentWidth) = RevitUtils.ConvertToViewBoxValues(topRight, bottomLeft, activeView.RightDirection); var zoomedViewBoxHeight = Convert.ToDouble(zoom).ToInternalRevitUnit(); var zoomedViewBoxWidth = zoomedViewBoxHeight * currentWidth / currentHeight; XYZ newTopRight = activeView.Origin .Add(activeView.UpDirection.Multiply(zoomedViewBoxHeight / 2)) .Add(activeView.RightDirection.Multiply(zoomedViewBoxWidth / 2)); XYZ newBottomLeft = activeView.Origin .Subtract(activeView.UpDirection.Multiply(zoomedViewBoxHeight / 2)) .Subtract(activeView.RightDirection.Multiply(zoomedViewBoxWidth / 2)); Log.Information("Zoom to {topRight} | {bottomLeft} ...", newTopRight.ToString(), newBottomLeft.ToString()); currentView.ZoomAndCenterRectangle(newTopRight, newBottomLeft); StatusBarService.ResetStatusBarText(); Log.Information("Finished applying zoom for orthogonal view."); app.Idling -= Callback; } Log.Information("Append zoom callback for orthogonal view to idle state of Revit application ..."); app.Idling += Callback; }
/// <summary> /// CableTray by curve. /// </summary> /// <param name="cableTrayType">Type of the cable tray.</param> /// <param name="curve">The curve.</param> /// <returns>It Uses the start and end Points of the curve to create the CableTray</returns> private static CableTray CableTrayByCurve(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Curve curve) { Utils.Log(string.Format("CableTray.CableTrayByCurve started...", "")); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var oType = cableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; var totalTransform = RevitUtils.DocumentTotalTransform(); Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); TransactionManager.Instance.TransactionTaskDone(); Utils.Log(string.Format("CableTray.CableTrayByCurve completed.", "")); return(new CableTray(oType, s, e)); }
/// <summary> /// Creates a Conduit by two points. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="start">The start point.</param> /// <param name="end">The end point.</param> /// <returns></returns> public static Conduit ByPoints(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end) { Utils.Log(string.Format("Conduit.ByPoints started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); totalTransform.Dispose(); Utils.Log(string.Format("Conduit.ByPoints completed.", "")); return(new Conduit(oType, s, e)); }
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()))); }
private bool SetOrthogonalView(View3D bcfView, OrthogonalCamera camera) { var result = false; try { var zoom = camera.ViewToWorldScale.ToFeet(); var direction = RevitUtils.GetRevitXYZ(camera.CameraDirection); var upVector = RevitUtils.GetRevitXYZ(camera.CameraUpVector); var viewPoint = RevitUtils.GetRevitXYZ(camera.CameraViewPoint); var orientation = RevitUtils.ConvertBasePoint(ActiveDoc, viewPoint, direction, upVector, true); using (var trans = new Transaction(ActiveDoc)) { trans.Start("Set Orientation"); try { bcfView.SetOrientation(orientation); trans.Commit(); } catch (Exception ex) { trans.RollBack(); var message = ex.Message; } } var m_xyzTl = bcfView.Origin.Add(bcfView.UpDirection.Multiply(zoom)).Subtract(bcfView.RightDirection.Multiply(zoom)); var m_xyzBr = bcfView.Origin.Subtract(bcfView.UpDirection.Multiply(zoom)).Add(bcfView.RightDirection.Multiply(zoom)); BCFUIView.ZoomAndCenterRectangle(m_xyzTl, m_xyzBr); result = true; } catch (Exception ex) { var message = ex.Message; } return(result); }
/// <summary> /// Calculates the new ShapePoint location on the new Featureline using the Station, Offset and Elevation parameters. /// </summary> /// <param name="featureline">The featureline used to update the ShapePoint</param> /// <returns></returns> public ShapePoint UpdateByFeatureline(Featureline featureline) { Utils.Log(string.Format("ShapePoint.UpdateByFeatureline started...", "")); var p = featureline.PointByStationOffsetElevation(this.Station, this.Offset, this.Elevation, false); this.Point = p; this.RevitPoint = this.Point.Transform(RevitUtils.DocumentTotalTransform()) as Point; this.Featureline = featureline; this.BaselineIndex = featureline.Baseline.Index; // 1.1.0 this.RegionIndex = featureline.BaselineRegionIndex; // 1.1.0 this.RegionRelative = this.Station - featureline.Start; // 1.1.0 this.RegionNormalized = this.RegionRelative / (featureline.End - featureline.Start); // 1.1.0 this.Code = featureline.Code; // 1.1.0 this.Corridor = featureline.Baseline.CorridorName; // 1.1.0 this.Side = featureline.Side; // 1.1.0 Utils.Log(string.Format("ShapePoint.UpdateByFeatureline completed.", "")); return(this); }
public void TransformCameraPosition_ReturnsExpectedPosition( ProjectPositionWrapper projectBase, Position initialCamera, Position expectedCamera, bool reverse) { // Arrange / Act Position cameraPosition = RevitUtils.TransformCameraPosition(projectBase, initialCamera, reverse); // Assert Assert.Equal(expectedCamera.Center.X, cameraPosition.Center.X, 10); Assert.Equal(expectedCamera.Center.Y, cameraPosition.Center.Y, 10); Assert.Equal(expectedCamera.Center.Z, cameraPosition.Center.Z, 10); Assert.Equal(expectedCamera.Forward.X, cameraPosition.Forward.X, 10); Assert.Equal(expectedCamera.Forward.Y, cameraPosition.Forward.Y, 10); Assert.Equal(expectedCamera.Forward.Z, cameraPosition.Forward.Z, 10); Assert.Equal(expectedCamera.Up.X, cameraPosition.Up.X, 10); Assert.Equal(expectedCamera.Up.Y, cameraPosition.Up.Y, 10); Assert.Equal(expectedCamera.Up.Z, cameraPosition.Up.Z, 10); }
/// <summary> /// Creates a pipe by two points. /// </summary> /// <param name="pipeType">Type of the pipe.</param> /// <param name="pipingSystemType">Type of the piping system.</param> /// <param name="start">The start point.</param> /// <param name="end">The end point.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Pipe ByPoints(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level) { Utils.Log(string.Format("Pipe.ByPoints started...", "")); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var totalTransform = RevitUtils.DocumentTotalTransform(); start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; totalTransform.Dispose(); Utils.Log(string.Format("Pipe.ByPoints completed.", "")); return(new Pipe(oType, oSystemType, s, e, l)); }
//<summary> //Generate a VisualizationInfo of the current view //</summary> //<returns></returns> private VisualizationInfo GenerateViewpoint() { try { var uidoc = uiapp.ActiveUIDocument; 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); //lenght 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 sperimentally, 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 visigle 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 static Dictionary <string, object> ByPolyCurve(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, PolyCurve polyCurve, Revit.Elements.Level level, double maxLength, Featureline featureline) { Utils.Log(string.Format("Pipe.ByPolyCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); var totalTransformInverse = totalTransform.Inverse(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var l = level.InternalElement as Autodesk.Revit.DB.Level; double length = polyCurve.Length; int subdivisions = Convert.ToInt32(Math.Ceiling(length / maxLength)); IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); points.Add(polyCurve.StartPoint); foreach (Autodesk.DesignScript.Geometry.Point p in polyCurve.PointsAtEqualChordLength(subdivisions)) { points.Add(p); } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); IList <ElementId> ids = new List <ElementId>(); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); Autodesk.DesignScript.Geometry.Point start = null; Autodesk.DesignScript.Geometry.Point end = null; Autodesk.DesignScript.Geometry.Point sp = null; Autodesk.DesignScript.Geometry.Point ep = null; Autodesk.DesignScript.Geometry.Curve curve = null; for (int i = 0; i < points.Count - 1; ++i) { start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = points[i + 1].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); Autodesk.Revit.DB.Plumbing.Pipe p = Autodesk.Revit.DB.Plumbing.Pipe.CreatePlaceholder(DocumentManager.Instance.CurrentDBDocument, oSystemType.Id, oType.Id, l.Id, s, e); ids.Add(p.Id); } var pipeIds = Autodesk.Revit.DB.Plumbing.PlumbingUtils.ConvertPipePlaceholders(DocumentManager.Instance.CurrentDBDocument, ids); TransactionManager.Instance.TransactionTaskDone(); DocumentManager.Instance.CurrentDBDocument.Regenerate(); Pipe[] pipes = GetPipesByIds(pipeIds); foreach (Pipe pipe in pipes) { curve = pipe.Location.Transform(totalTransformInverse) as Autodesk.DesignScript.Geometry.Curve; sp = curve.StartPoint; ep = curve.EndPoint; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(sp.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(sp.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(sp.Z, 3)); var soe = featureline.GetStationOffsetElevationByPoint(sp); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round((double)soe["Elevation"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); soe = featureline.GetStationOffsetElevationByPoint(ep); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round((double)soe["Elevation"], 3)); } IList <Fitting> fittings = new List <Fitting>(); for (int i = 0; i < pipes.Length - 1; ++i) { Fitting fitting = null; try { fitting = Fitting.Elbow(pipes[i], pipes[i + 1]); } catch { } fittings.Add(fitting); } if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } if (sp != null) { sp.Dispose(); } if (ep != null) { ep.Dispose(); } if (curve != null) { curve.Dispose(); } foreach (var item in points) { if (item != null) { item.Dispose(); } } points.Clear(); Utils.Log(string.Format("Pipe.ByPolyCurve completed.", "")); return(new Dictionary <string, object>() { { "Pipes", pipes }, { "Fittings", fittings } }); }
/// <summary> /// Creates the connection with the running session of Civil 3D. /// </summary> public CivilApplication() { Utils.InitializeLog(); Utils.Log(string.Format("CivilApplication.CivilApplication started...", "")); this.mApp = this.GetApplication(); IList <CivilDocument> documents = new List <CivilDocument>(); foreach (var doc in this.mApp.Documents) { documents.Add(new CivilDocument(doc as AeccRoadwayDocument)); } this.Documents = documents; this.ActiveDocument = mApp.ActiveDocument; var revitDoc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument; RevitServices.Transactions.TransactionManager.Instance.EnsureInTransaction(revitDoc); Autodesk.Revit.DB.Units units = new Autodesk.Revit.DB.Units(Autodesk.Revit.DB.UnitSystem.Metric); var du = this.Documents.First()._document.Settings.DrawingSettings.UnitZoneSettings.DrawingUnits; Utils.Log(string.Format("CivilApplication.Units started...", "")); // 1.1.0 Change Revit Document untis to match the Civil 3D Units if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitMeters) { units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_METERS)); } else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitDecimeters) { units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_DECIMETERS)); } else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitCentimeters) { units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_CENTIMETERS)); } else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitMillimeters) { units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_MILLIMETERS)); } else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitFeet) { units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_DECIMAL_FEET)); } else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitInches) { units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_DECIMAL_INCHES)); } else { throw new Exception("UNITS ERROR\nThe Civil 3D units of the Active Document are not supported in Revit.\nChange the Civil 3D Units to continue"); } revitDoc.SetUnits(units); RevitServices.Transactions.TransactionManager.Instance.TransactionTaskDone(); Utils.Log(string.Format("CivilApplication.Units completed.", "")); SessionVariables.LandXMLPath = System.IO.Path.GetTempPath(); SessionVariables.IsLandXMLExported = false; SessionVariables.CivilApplication = this; SessionVariables.ParametersCreated = false; SessionVariables.DocumentTotalTransform = null; RevitUtils.DocumentTotalTransform(); }
/// <summary> /// /// </summary> /// <param name="view"></param> /// <param name="viewpoint_Guid"></param> /// <returns></returns> private OrthogonalCamera GetOrthogonalCamera(View3D view, string viewpoint_Guid) { var camera = new OrthogonalCamera(); try { var uiView = FindDefaultUIView(view); if (null == uiView) { return(camera); } var topLeft = uiView.GetZoomCorners()[0]; var bottomRight = uiView.GetZoomCorners()[1]; var x = (topLeft.X + bottomRight.X) / 2; var y = (topLeft.Y + bottomRight.Y) / 2; var z = (topLeft.Z + bottomRight.Z) / 2; var viewCenter = new XYZ(x, y, z); var diagVector = topLeft.Subtract(bottomRight); var dist = topLeft.DistanceTo(bottomRight) / 2; var zoomValue = dist * Math.Sin(diagVector.AngleTo(view.RightDirection)).ToMeters(); var orientation = RevitUtils.ConvertBasePoint(ActiveDoc, viewCenter, view.ViewDirection, view.UpDirection, false); var c = orientation.EyePosition; var vi = orientation.ForwardDirection; var up = orientation.UpDirection; camera.Guid = Guid.NewGuid().ToString(); camera.ViewPointGuid = viewpoint_Guid; var viewPoint = new Schemas.Point { Guid = Guid.NewGuid().ToString(), X = c.X.ToMeters(), Y = c.Y.ToMeters(), Z = c.Z.ToMeters() }; camera.CameraViewPoint = viewPoint; var upVector = new Direction { Guid = Guid.NewGuid().ToString(), X = up.X.ToMeters(), Y = up.Y.ToMeters(), Z = up.Z.ToMeters() }; camera.CameraUpVector = upVector; var direction = new Direction { Guid = Guid.NewGuid().ToString(), X = -(vi.X.ToMeters()), Y = -(vi.Y.ToMeters()), Z = -(vi.Z.ToMeters()) }; camera.CameraDirection = direction; camera.ViewToWorldScale = zoomValue; } catch (Exception) { // ignored } return(camera); }