Esempio n. 1
0
        public static Rhino.Geometry.Point3d getRefPoint()
        {
            Guid docBoxID = new Guid(utils.properties.tryGetDocBox());

            Rhino.DocObjects.ObjRef docBox = new Rhino.DocObjects.ObjRef(docBoxID);

            Rhino.Geometry.Curve docBoxCurve = docBox.Curve();

            List <double> xVals = new List <double>();
            List <double> yVals = new List <double>();

            int spanCount = docBoxCurve.SpanCount;

            for (int i = 0; i < spanCount; i++)
            {
                double activeParameter             = docBoxCurve.SpanDomain(i).Min;
                Rhino.Geometry.Point3d activePoint = docBoxCurve.PointAt(activeParameter);

                double activeX = activePoint.X;
                xVals.Add(activeX);

                double activeY = activePoint.Y;
                yVals.Add(activeY);
            }

            xVals.Sort();
            yVals.Sort();

            Rhino.Geometry.Point3d docBoxRefPoint = new Rhino.Geometry.Point3d(xVals[0], yVals[spanCount - 1], 0);

            return(docBoxRefPoint);
        }
        void ReconstructModelLineByCurve
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Curve curve,
            Autodesk.Revit.DB.SketchPlane sketchPlane
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            var plane = sketchPlane.GetPlane().ToRhino().ChangeUnits(scaleFactor);

            if
            (
                ((curve = curve.ChangeUnits(scaleFactor)) is null) ||
                ((curve = Rhino.Geometry.Curve.ProjectToPlane(curve, plane)) == null)
            )
            {
                ThrowArgumentException(nameof(curve), "Failed to project curve in the sketchPlane.");
            }

            var centerLine = curve.ToHost();

            if (curve.IsClosed == centerLine.IsBound)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to keep curve closed.");
            }

            if (element is ModelCurve modelCurve && centerLine.IsSameKindAs(modelCurve.GeometryCurve))
            {
                modelCurve.SetSketchPlaneAndCurve(sketchPlane, centerLine);
            }
Esempio n. 3
0
        public static List <ICurve> HourPath(SpaceTime spaceTime)
        {
            List <ICurve> paths = new List <ICurve>();

            for (int h = 0; h <= 23; ++h)
            {
                List <Point3d> sunPositions = new List <Point3d>();
                for (int m = 1; m <= 12; ++m)
                {
                    spaceTime.Day   = 21;
                    spaceTime.Month = m;
                    spaceTime.Hour  = h;
                    Sun ss = SolarPA(spaceTime);

                    Point   sunPosition   = Geometry.Create.Point(ss.SolarVector());
                    Point3d sunPosition3d = Rhinoceros.Convert.ToRhino(sunPosition);
                    sunPositions.Add(sunPosition3d);
                }
                sunPositions.Add(sunPositions[0]);
                Rhino.Geometry.CurveKnotStyle nnotStyle = Rhino.Geometry.CurveKnotStyle.UniformPeriodic;
                Curve  crv  = Curve.CreateInterpolatedCurve(sunPositions, 3, nnotStyle);
                ICurve crvB = Rhinoceros.Convert.ToBHoM(crv);
                paths.Add(crvB);
            }
            return(paths);
        }
Esempio n. 4
0
    public static Rhino.Commands.Result TweenCurve(Rhino.RhinoDoc doc)
    {
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select two curves");
        go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve;
        go.GetMultiple(2, 2);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        Rhino.Geometry.Curve curve0 = go.Object(0).Curve();
        Rhino.Geometry.Curve curve1 = go.Object(1).Curve();
        if (null != curve0 && null != curve1)
        {
            Rhino.Geometry.Curve[] curves = Rhino.Geometry.Curve.CreateTweenCurves(curve0, curve1, 1);
            if (null != curves)
            {
                for (int i = 0; i < curves.Length; i++)
                {
                    doc.Objects.AddCurve(curves[i]);
                }

                doc.Views.Redraw();
                return(Rhino.Commands.Result.Success);
            }
        }

        return(Rhino.Commands.Result.Failure);
    }
Esempio n. 5
0
    void ReconstructGridByCurve
    (
      Document doc,
      ref Autodesk.Revit.DB.Element element,

      Rhino.Geometry.Curve curve,
      Optional<Autodesk.Revit.DB.GridType> type,
      Optional<string> name
    )
    {
      SolveOptionalType(ref type, doc, ElementTypeGroup.GridType, nameof(type));

      var parametersMask = name.IsMissing ?
        new BuiltInParameter[]
        {
          BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM,
          BuiltInParameter.ELEM_FAMILY_PARAM,
          BuiltInParameter.ELEM_TYPE_PARAM
        } :
        new BuiltInParameter[]
        {
          BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM,
          BuiltInParameter.ELEM_FAMILY_PARAM,
          BuiltInParameter.ELEM_TYPE_PARAM,
          BuiltInParameter.DATUM_TEXT
        };

      if (curve.TryGetLine(out var line, Revit.VertexTolerance * Revit.ModelUnits))
      {
        ReplaceElement(ref element, Grid.Create(doc, line.ToLine()), parametersMask);
        ChangeElementTypeId(ref element, type.Value.Id);
      }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="curve"></param>
        /// <returns></returns>
        public static double CurveLength(Rhino.Geometry.Curve curve)
        {
            MyPlugInSdk.SdkTest(true);
            IntPtr pCurve = Rhino.Runtime.Interop.NativeGeometryConstPointer(curve);

            return(UnsafeNativeMethods.Expose_CurveLength(pCurve));
        }
Esempio n. 7
0
 /// <summary>
 /// Copies a Rhino_DotNet curve to a RhinoCommon curve class.
 /// </summary>
 /// <param name="source">
 /// RMA.OpenNURBS.IOnCurve or RMA.OpenNURBS.OnCurve.
 /// </param>
 /// <returns>
 /// RhinoCommon object on success. This will be an independent copy.
 /// </returns>
 public static Rhino.Geometry.Curve FromOnCurve(object source)
 {
     Rhino.Geometry.GeometryBase g = CopyHelper(source, "RMA.OpenNURBS.OnCurve");
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnArcCurve");
     }
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnLineCurve");
     }
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnNurbsCurve");
     }
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnPolylineCurve");
     }
     if (null == g)
     {
         g = CopyHelper(source, "RMA.OpenNURBS.OnPolyCurve");
     }
     Rhino.Geometry.Curve rc = g as Rhino.Geometry.Curve;
     return(rc);
 }
Esempio n. 8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve axis = null;
            DA.GetData("Axis", ref axis);

            FamilySymbol familySymbol = null;

            if (!DA.GetData("Type", ref familySymbol) && Params.Input[1].Sources.Count == 0)
            {
                familySymbol = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultFamilyTypeId(new ElementId(BuiltInCategory.OST_StructuralFraming))) as FamilySymbol;
            }

            if (familySymbol == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' There is no default structural framing family loaded.", Params.Input[1].Name));
                DA.AbortComponentSolution();
                return;
            }

            if (!familySymbol.IsActive)
            {
                familySymbol.Activate();
            }

            Autodesk.Revit.DB.Level level = null;
            DA.GetData("Level", ref level);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, familySymbol, level));
        }
    public static Rhino.Commands.Result ArcLengthPoint(Rhino.RhinoDoc doc)
    {
        Rhino.DocObjects.ObjRef objref;
        Rhino.Commands.Result   rc = Rhino.Input.RhinoGet.GetOneObject("Select curve",
                                                                       true, Rhino.DocObjects.ObjectType.Curve, out objref);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }
        Rhino.Geometry.Curve crv = objref.Curve();
        if (crv == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        double crv_length = crv.GetLength();
        double length     = 0;

        rc = Rhino.Input.RhinoGet.GetNumber("Length from start", true, ref length, 0, crv_length);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        Rhino.Geometry.Point3d pt = crv.PointAtLength(length);
        if (pt.IsValid)
        {
            doc.Objects.AddPoint(pt);
            doc.Views.Redraw();
        }
        return(Rhino.Commands.Result.Success);
    }
        void ReconstructDirectShapeByCurve
        (
            DB.Document doc,
            ref DB.DirectShape element,

            Rhino.Geometry.Curve curve
        )
        {
            if (!ThrowIfNotValid(nameof(curve), curve))
            {
                return;
            }

            if (element is DB.DirectShape ds)
            {
            }
            else
            {
                ds = DB.DirectShape.CreateElement(doc, new DB.ElementId(DB.BuiltInCategory.OST_GenericModel));
            }

            using (var ctx = GeometryEncoder.Context.Push(ds))
            {
                ctx.RuntimeMessage = (severity, message, invalidGeometry) =>
                                     AddGeometryConversionError((GH_RuntimeMessageLevel)severity, message, invalidGeometry);

                ds.SetShape(curve.ToShape().OfType <DB.GeometryObject>().ToList());
            }

            ReplaceElement(ref element, ds);
        }
Esempio n. 11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve axis = null;
            DA.GetData("Axis", ref axis);

            FamilySymbol familySymbol = null;

            if (!DA.GetData("FamilyType", ref familySymbol) && Params.Input[1].Sources.Count == 0)
            {
                familySymbol = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultFamilyTypeId(new ElementId(BuiltInCategory.OST_StructuralFraming))) as FamilySymbol;
            }

            if (!familySymbol.IsActive)
            {
                familySymbol.Activate();
            }

            Autodesk.Revit.DB.Level level = null;
            DA.GetData("Level", ref level);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, familySymbol, level));
        }
Esempio n. 12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve boundary = null;
            DA.GetData("Boundary", ref boundary);

            Autodesk.Revit.DB.FloorType floorType = null;
            if (!DA.GetData("Type", ref floorType) && Params.Input[1].Sources.Count == 0)
            {
                floorType = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultElementTypeId(ElementTypeGroup.FloorType)) as FloorType;
            }

            Autodesk.Revit.DB.Level level = null;
            DA.GetData("Level", ref level);
            if (level == null && boundary != null)
            {
                var boundaryBBox = boundary.GetBoundingBox(true);
                level = Revit.ActiveDBDocument.FindLevelByElevation(boundaryBBox.Min.Z / Revit.ModelUnits);
            }

            bool structural = true;

            DA.GetData("Structural", ref structural);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, boundary, floorType, level, structural));
        }
Esempio n. 13
0
        void ReconstructModelLineByCurve
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Curve curve,
            Autodesk.Revit.DB.SketchPlane sketchPlane
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            var plane = sketchPlane.GetPlane().ToRhino().Scale(scaleFactor);

            if
            (
                !(scaleFactor != 1.0 ? curve.Scale(scaleFactor) : true) ||
                ((curve = Rhino.Geometry.Curve.ProjectToPlane(curve, plane)) != null)
            )
            {
                ThrowArgumentException(nameof(curve), "Failed to project curve in the sketchPlane.");
            }

            var curves = curve.ToHost().ToArray();

            Debug.Assert(curves.Length == 1);
            var centerLine = curves[0];

            if (element is ModelCurve modelCurve && centerLine.IsSameKindAs(modelCurve.GeometryCurve))
            {
                modelCurve.SetSketchPlaneAndCurve(sketchPlane, centerLine);
            }
Esempio n. 14
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve axis = null;
            DA.GetData("Curve", ref axis);

            GridType gridType = null;

            if (!DA.GetData("Type", ref gridType) && Params.Input[1].Sources.Count == 0)
            {
                gridType = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultElementTypeId(ElementTypeGroup.GridType)) as GridType;
            }

            if (gridType == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' There is no default level type loaded.", Params.Input[1].Name));
                DA.AbortComponentSolution();
                return;
            }

            string name = null;

            DA.GetData("Name", ref name);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, gridType));
        }
Esempio n. 15
0
        void ReconstructModelLineByCurve
        (
            DB.Document doc,
            ref DB.Element element,

            Rhino.Geometry.Curve curve,
            DB.SketchPlane sketchPlane
        )
        {
            var plane = sketchPlane.GetPlane().ToPlane();

            if
            (
                ((curve = Rhino.Geometry.Curve.ProjectToPlane(curve, plane)) == null)
            )
            {
                ThrowArgumentException(nameof(curve), "Failed to project curve in the sketchPlane.");
            }

            var centerLine = curve.ToCurve();

            if (curve.IsClosed == centerLine.IsBound)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unable to keep curve closed.");
            }

            if (element is DB.ModelCurve modelCurve && centerLine.IsSameKindAs(modelCurve.GeometryCurve))
            {
                modelCurve.SetSketchPlaneAndCurve(sketchPlane, centerLine);
            }
Esempio n. 16
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve axis = null;
            DA.GetData("Axis", ref axis);

            WallType wallType = null;

            if (!DA.GetData("Type", ref wallType) && Params.Input[1].Sources.Count == 0)
            {
                wallType = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultElementTypeId(ElementTypeGroup.WallType)) as WallType;
            }

            Autodesk.Revit.DB.Level level = null;
            DA.GetData("Level", ref level);
            if (level == null && axis != null)
            {
                level = Revit.ActiveDBDocument.FindLevelByElevation(axis.PointAtStart.Z / Revit.ModelUnits);
            }

            bool structural = true;

            DA.GetData("Structural", ref structural);

            double height = 0.0;

            if (!DA.GetData("Height", ref height))
            {
                height = LiteralLengthValue(3.0);
            }

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, wallType, level, structural, height));
        }
Esempio n. 17
0
        void ReconstructDirectShapeByCurve
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Curve curve
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            ThrowIfNotValid(nameof(curve), curve);

            if (element is DirectShape ds)
            {
            }
            else
            {
                ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel));
            }

            var shape = curve.
                        ToHostMultiple(scaleFactor).
                        SelectMany(x => x.ToDirectShapeGeometry());

            ds.SetShape(shape.ToList());

            ReplaceElement(ref element, ds);
        }
Esempio n. 18
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Curve curve,
            Autodesk.Revit.DB.SketchPlane plane
        )
        {
            var elements = PreviousElements(doc, Iteration).ToList();

            try
            {
                if (curve == null)
                {
                    throw new Exception(string.Format("Parameter '{0}' is null.", Params.Input[0].Name));
                }

                if (plane == null)
                {
                    throw new Exception(string.Format("Parameter '{0}' is null.", Params.Input[1].Name));
                }

                var scaleFactor = 1.0 / Revit.ModelUnits;
                if (scaleFactor != 1.0)
                {
                    curve.Scale(scaleFactor);
                }

                curve = Rhino.Geometry.Curve.ProjectToPlane(curve, plane.GetPlane().ToRhino());

                var newElements = new List <Element>();
                {
                    int index = 0;
                    foreach (var c in curve.ToHost() ?? Enumerable.Empty <Autodesk.Revit.DB.Curve>())
                    {
                        var element = index < elements.Count ? elements[index] : null;
                        index++;

                        if (element?.Pinned ?? true)
                        {
                            if (element is ModelCurve modelCurve && modelCurve.GeometryCurve.IsBound == c.IsBound)
                            {
                                modelCurve.SetSketchPlaneAndCurve(plane, c);
                            }
                            else if (doc.IsFamilyDocument)
                            {
                                element = CopyParametersFrom(doc.FamilyCreate.NewModelCurve(c, plane), element);
                            }
                            else
                            {
                                element = CopyParametersFrom(doc.Create.NewModelCurve(c, plane), element);
                            }
                        }

                        newElements.Add(element);
                    }
                }

                ReplaceElements(doc, DA, Iteration, newElements);
            }
Esempio n. 19
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve axis = null;
            DA.GetData("Axis", ref axis);

            WallType wallType = null;

            if (!DA.GetData("FamilyType", ref wallType) && Params.Input[1].Sources.Count == 0)
            {
                wallType = Revit.ActiveDBDocument.GetElement(Revit.ActiveDBDocument.GetDefaultElementTypeId(ElementTypeGroup.WallType)) as WallType;
            }

            Autodesk.Revit.DB.Level level = null;
            DA.GetData("Level", ref level);
            if (level == null && axis != null)
            {
                using (var collector = new FilteredElementCollector(Revit.ActiveDBDocument))
                {
                    foreach (var levelN in collector.OfClass(typeof(Level)).ToElements().Cast <Level>().OrderBy(c => c.Elevation))
                    {
                        if (level == null)
                        {
                            level = levelN;
                        }
                        else if (axis.PointAtStart.Z >= levelN.Elevation)
                        {
                            level = levelN;
                        }
                    }
                }
            }

            bool structural = true;

            DA.GetData("Structural", ref structural);

            double height = 0.0;

            if (!DA.GetData("Height", ref height))
            {
                switch (Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem)
                {
                case Rhino.UnitSystem.None:
                case Rhino.UnitSystem.Inches:
                case Rhino.UnitSystem.Feet:
                    height = 10.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Feet, Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem);
                    break;

                default:
                    height = 3.0 * Rhino.RhinoMath.UnitScale(Rhino.UnitSystem.Meters, Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem);
                    break;
                }
            }

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, wallType, level, structural, height));
        }
Esempio n. 20
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Curve curve,
            Autodesk.Revit.DB.FamilySymbol familySymbol,
            Autodesk.Revit.DB.Level level
        )
        {
            var element = PreviousElement(doc, Iteration);

            if (!element?.Pinned ?? false)
            {
                ReplaceElement(doc, DA, Iteration, element);
            }
            else
            {
                try
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        curve?.Scale(scaleFactor);
                    }

                    if
                    (
                        curve == null ||
                        curve.IsShort(Revit.ShortCurveTolerance) ||
                        curve.IsClosed ||
                        !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                        curve.GetNextDiscontinuity(Rhino.Geometry.Continuity.C1_continuous, curve.Domain.Min, curve.Domain.Max, out double discontinuity)
                    )
                    {
                        throw new Exception(string.Format("Parameter '{0}' must be a C1 continuous planar non closed curve.", Params.Input[0].Name));
                    }

                    var axisList = curve.ToHost().ToList();
                    Debug.Assert(axisList.Count == 1);

                    if (element is FamilyInstance && familySymbol.Id != element.GetTypeId())
                    {
                        var newElmentId = element.ChangeTypeId(familySymbol.Id);
                        if (newElmentId != ElementId.InvalidElementId)
                        {
                            element = doc.GetElement(newElmentId);
                        }
                    }

                    if (element is FamilyInstance familyInstance && element.Location is LocationCurve locationCurve)
                    {
                        locationCurve.Curve = axisList[0];
                    }
                    else
                    {
                        element = CopyParametersFrom(doc.Create.NewFamilyInstance(axisList[0], familySymbol, level, Autodesk.Revit.DB.Structure.StructuralType.Beam), element);
                    }

                    ReplaceElement(doc, DA, Iteration, element);
                }
Esempio n. 21
0
        public bool SolveOptionalLevels(DB.Document doc, Rhino.Geometry.Curve curve, ref Optional <DB.Level> baseLevel, ref Optional <DB.Level> topLevel)
        {
            bool result = true;

            result &= SolveOptionalLevel(doc, Math.Min(curve.PointAtStart.Z, curve.PointAtEnd.Z), ref baseLevel);
            result &= SolveOptionalLevel(doc, Math.Max(curve.PointAtStart.Z, curve.PointAtEnd.Z), ref baseLevel);

            return(result);
        }
Esempio n. 22
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Curve boundary,
            Autodesk.Revit.DB.RoofType roofType,
            Autodesk.Revit.DB.Level level
        )
        {
            var element = PreviousElement(doc, Iteration);

            if (!element?.Pinned ?? false)
            {
                ReplaceElement(doc, DA, Iteration, element);
            }
            else
            {
                try
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        boundary?.Scale(scaleFactor);
                    }

                    if
                    (
                        boundary == null ||
                        boundary.IsShort(Revit.ShortCurveTolerance) ||
                        !boundary.IsClosed ||
                        !boundary.TryGetPlane(out var boundaryPlane, Revit.VertexTolerance) ||
                        boundaryPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
                    )
                    {
                        throw new Exception(string.Format("Parameter '{0}' must be an horizontal planar closed curve.", Params.Input[0].Name));
                    }

                    var curveArray = boundary.ToHost().ToCurveArray();
                    var footPintToModelCurvesMapping = new ModelCurveArray();
                    element = CopyParametersFrom(doc.Create.NewFootPrintRoof(curveArray, level, roofType, out footPintToModelCurvesMapping), element);

                    if (element != null)
                    {
                        var boundaryBBox = boundary.GetBoundingBox(true);
                        element.get_Parameter(BuiltInParameter.ROOF_BASE_LEVEL_PARAM).Set(level.Id);
                        element.get_Parameter(BuiltInParameter.ROOF_LEVEL_OFFSET_PARAM).Set(boundaryBBox.Min.Z - level.Elevation);
                    }

                    ReplaceElement(doc, DA, Iteration, element);
                }
                catch (Exception e)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                    ReplaceElement(doc, DA, Iteration, null);
                }
            }
        }
Esempio n. 23
0
        public Guid DrawObjectWithSpecificLayer(Rhino.Geometry.Curve curve, NamedLayer layername)
        {
            Rhino.RhinoDoc.ActiveDoc.Layers.SetCurrentLayerIndex(layerIndexes[(int)layername], false);

            var result = Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(curve);

            Rhino.RhinoDoc.ActiveDoc.Layers.SetCurrentLayerIndex(0, false);

            return(result);
        }
Esempio n. 24
0
        void ReconstructFloorByOutline
        (
            Document doc,
            ref Autodesk.Revit.DB.Element element,

            Rhino.Geometry.Curve boundary,
            Optional <Autodesk.Revit.DB.FloorType> type,
            Optional <Autodesk.Revit.DB.Level> level,
            [Optional] bool structural
        )
        {
            var scaleFactor = 1.0 / Revit.ModelUnits;

            if
            (
                scaleFactor != 1.0 ? !boundary.Scale(scaleFactor) : true &&
                boundary.IsShort(Revit.ShortCurveTolerance) ||
                !boundary.IsClosed ||
                !boundary.TryGetPlane(out var boundaryPlane, Revit.VertexTolerance) ||
                boundaryPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
            )
            {
                ThrowArgumentException(nameof(boundary), "Boundary must be an horizontal planar closed curve.");
            }

            SolveOptionalType(ref type, doc, ElementTypeGroup.FloorType, nameof(type));

            SolveOptionalLevel(ref level, doc, boundary, nameof(level));

            var curveArray = boundary.ToHost().ToCurveArray();

            var parametersMask = new BuiltInParameter[]
            {
                BuiltInParameter.ELEM_FAMILY_AND_TYPE_PARAM,
                BuiltInParameter.ELEM_FAMILY_PARAM,
                BuiltInParameter.ELEM_TYPE_PARAM,
                BuiltInParameter.LEVEL_PARAM,
                BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL
            };

            if (type.Value.IsFoundationSlab)
            {
                ReplaceElement(ref element, doc.Create.NewFoundationSlab(curveArray, type.Value, level.Value, structural, XYZ.BasisZ), parametersMask);
            }
            else
            {
                ReplaceElement(ref element, doc.Create.NewFloor(curveArray, type.Value, level.Value, structural, XYZ.BasisZ), parametersMask);
            }

            if (element != null)
            {
                var boundaryBBox = boundary.GetBoundingBox(true);
                element.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(boundaryBBox.Min.Z - level.Value.Elevation);
            }
        }
Esempio n. 25
0
        //Update illustrator doc bound if docbox changes in rhino.
        public static void docBoxChanges(Rhino.DocObjects.RhinoObject docBox)
        {
            //Parse rectangle from incoming RhinoObject.
            Guid incomingGuid = docBox.Id;

            Rhino.Geometry.Curve newCurve = null;

            Rhino.DocObjects.ObjRef oRef = new Rhino.DocObjects.ObjRef(incomingGuid);

            newCurve = oRef.Curve();

            Rhino.Geometry.BoundingBox newDimsBox = newCurve.GetBoundingBox(false);

            Rhino.Geometry.Point3d newMinPoint = newDimsBox.Min;
            Rhino.Geometry.Point3d newMaxPoint = newDimsBox.Max;

            double newWidth  = newMaxPoint.X - newMinPoint.X;
            double newHeight = newMaxPoint.Y - newMinPoint.Y;

            int conversion = utils.units.conversion();

            //Compare previous size, or record if first run.
            string D01_Path = utils.file_structure.getPathFor("D01");
            string jsxPath  = utils.file_structure.getJavascriptPath();

            if (System.IO.File.Exists(D01_Path) == false)
            {
                string newData = newWidth.ToString() + "|" + newHeight.ToString();
                System.IO.File.WriteAllText(D01_Path, newData);
            }
            else if (System.IO.File.Exists(D01_Path) == true)
            {
                //If file exists, verify bounds changed. (Otherwise, box moved.)
                string[] oldData   = System.IO.File.ReadAllText(D01_Path).Split('|');
                double   oldWidth  = Convert.ToDouble(oldData[0]);
                double   oldHeight = Convert.ToDouble(oldData[1]);

                //utils.debug.ping(0, "Width change: " + newWidth.ToString() + " - " + oldWidth.ToString());

                if (oldWidth == newWidth && oldHeight == newHeight)
                {
                    //outbound.push.fullReset();
                }
                else
                {
                    string newData = newWidth.ToString() + "|" + newHeight.ToString();
                    System.IO.File.WriteAllText(D01_Path, newData);

                    echo.interop echo = new echo.interop();
                    echo.docBounds(newWidth, newHeight, conversion, jsxPath);

                    //outbound.push.fullReset();
                }
            }
        }
        /// <summary>
        /// Intersects a curve and an infinite line.
        /// </summary>
        /// <param name="curve">Curve to intersect.</param>
        /// <param name="line">Infinite line to intesect.</param>
        /// <param name="tolerance">If the distance from a point on curve to line
        /// is &lt;= tolerance, then the point will be part of an intersection
        /// event. If the tolerance &lt;= 0.0, then 0.001 is used.</param>
        /// <param name="overlapTolerance">If t1 and t2 are parameters of curve's
        /// intersection events and the distance from curve(t) to line is &lt;=
        /// overlapTolerance for every t1 &lt;= t &lt;= t2, then the event will
        /// be returened as an overlap event. If overlapTolerance &lt;= 0.0,
        /// then tolerance * 2.0 is used.</param>
        /// <returns>A collection of intersection events.</returns>
        public static Rhino.Geometry.Intersect.CurveIntersections IntersectCurveLine(
            Rhino.Geometry.Curve curve,
            Rhino.Geometry.Line line,
            double tolerance,
            double overlapTolerance
            )
        {
            if (!curve.IsValid || !line.IsValid || line.Length < Rhino.RhinoMath.SqrtEpsilon)
            {
                return(null);
            }

            // Extend the line through the curve's bounding box
            var bbox = curve.GetBoundingBox(false);

            if (!bbox.IsValid)
            {
                return(null);
            }

            var dir = line.Direction;

            dir.Unitize();

            var points = bbox.GetCorners();
            var plane  = new Rhino.Geometry.Plane(line.From, dir);

            double max_dist;
            var    min_dist = max_dist = plane.DistanceTo(points[0]);

            for (var i = 1; i < points.Length; i++)
            {
                var dist = plane.DistanceTo(points[i]);
                if (dist < min_dist)
                {
                    min_dist = dist;
                }
                if (dist > max_dist)
                {
                    max_dist = dist;
                }
            }

            // +- 1.0 makes the line a little bigger than the bounding box
            line.From = line.From + dir * (min_dist - 1.0);
            line.To   = line.From + dir * (max_dist + 1.0);

            // Calculate curve-curve intersection
            var line_curve = new Rhino.Geometry.LineCurve(line);

            return(Rhino.Geometry.Intersect.Intersection.CurveCurve(curve, line_curve, tolerance, overlapTolerance));
        }
Esempio n. 27
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve curve = null;
            if (!DA.GetData("Curve", ref curve))
            {
                return;
            }

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, (Rhino.Geometry.Curve)curve?.DuplicateShallow()));
        }
Esempio n. 28
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Rhino.Geometry.Curve axis = null;
            DA.GetData("Curve", ref axis);

            Autodesk.Revit.DB.SketchPlane plane = null;
            DA.GetData("SketchPlane", ref plane);

            DA.DisableGapLogic();
            int Iteration = DA.Iteration;

            Revit.EnqueueAction((doc) => CommitInstance(doc, DA, Iteration, axis, plane));
        }
Esempio n. 29
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Curve boundary,
            Autodesk.Revit.DB.FloorType floorType,
            Autodesk.Revit.DB.Level level,
            bool structural
        )
        {
            var element = PreviousElement(doc, Iteration);

            try
            {
                if (element?.Pinned ?? true)
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        boundary?.Scale(scaleFactor);
                    }

                    if
                    (
                        boundary == null ||
                        boundary.IsShort(Revit.ShortCurveTolerance) ||
                        !boundary.IsClosed ||
                        !boundary.TryGetPlane(out var boundaryPlane, Revit.VertexTolerance) ||
                        boundaryPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
                    )
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' must be an horizontal planar closed curve.", Params.Input[0].Name));
                    }
                    else
                    {
                        var curveArray = new CurveArray();
                        foreach (var curve in boundary.ToHost())
                        {
                            curveArray.Append(curve);
                        }

                        if (floorType.IsFoundationSlab)
                        {
                            element = doc.Create.NewFoundationSlab(curveArray, floorType, level, structural, XYZ.BasisZ);
                        }
                        else
                        {
                            element = doc.Create.NewFloor(curveArray, floorType, level, structural, XYZ.BasisZ);
                        }
                    }
                }
            }
Esempio n. 30
0
        void CommitInstance
        (
            Document doc, IGH_DataAccess DA, int Iteration,
            Rhino.Geometry.Curve curve,
            Autodesk.Revit.DB.WallType wallType,
            Autodesk.Revit.DB.Level level,
            bool structural,
            double height
        )
        {
            var element = PreviousElement(doc, Iteration);

            try
            {
                if (element?.Pinned ?? true)
                {
                    var scaleFactor = 1.0 / Revit.ModelUnits;
                    if (scaleFactor != 1.0)
                    {
                        height *= scaleFactor;
                        curve?.Scale(scaleFactor);
                    }

                    if
                    (
                        curve == null ||
                        curve.IsShort(Revit.ShortCurveTolerance) ||
                        !(curve.IsArc(Revit.VertexTolerance) || curve.IsLinear(Revit.VertexTolerance)) ||
                        !curve.TryGetPlane(out var axisPlane, Revit.VertexTolerance) ||
                        axisPlane.ZAxis.IsParallelTo(Rhino.Geometry.Vector3d.ZAxis) == 0
                    )
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' must be a horizontal line or arc curve.", Params.Input[0].Name));
                    }
                    else if (level == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' no suitable level is been found.", Params.Input[3].Name));
                    }
                    else if (height < Revit.VertexTolerance)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("Parameter '{0}' is too small.", Params.Input[5].Name));
                    }
                    else
                    {
                        var axisList = curve.ToHost().ToList();
                        Debug.Assert(axisList.Count == 1);

                        element = Autodesk.Revit.DB.Wall.Create(doc, axisList[0], wallType.Id, level.Id, height, axisPlane.Origin.Z - level.Elevation, false, structural);
                    }
                }
            }