Ejemplo n.º 1
0
        public static SketchUpNET.Surface ToSKPGeo(this Autodesk.DesignScript.Geometry.Surface surface)
        {
            Surface srf = new Surface();

            srf.Vertices = new List <Vertex>();

            foreach (Autodesk.DesignScript.Geometry.Curve curve in surface.PerimeterCurves())
            {
                foreach (Autodesk.DesignScript.Geometry.Curve tesselated in curve.ApproximateWithArcAndLineSegments())
                {
                    srf.Vertices.Add(tesselated.StartPoint.ToSKPGeo());
                }
            }

            return(srf);
        }
Ejemplo n.º 2
0
        private static ElementFaceReference TryGetFaceReference(Autodesk.DesignScript.Geometry.Surface curveObject, string nodeTypeString = "This node")
        {
            // If a Reference has been added to this object, we can use that
            // to build the Element.
            object tagObj = curveObject.Tags.LookupTag(DefaultTag);

            if (tagObj != null)
            {
                var tagRef = (Reference)tagObj;
                return(new ElementFaceReference(tagRef));
            }

            throw new ArgumentException(nodeTypeString + " requires a ElementFaceReference extracted from a Revit Element! " +
                                        "You can use the ImportInstance.ByGeometry to " +
                                        "turn this Surface into a Revit Element, then extract a ElementFaceReference from it.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Place a Revit family instance of the given the FamilyType (also known as the FamilySymbol in the Revit API)
        /// on a surface derived from a backing Revit face as reference and a line as reference for its position.
        ///
        /// Note: The FamilyPlacementType must be CurveBased and the input surface must be created from a Revit Face
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</param>
        /// <param name="face">Surface geometry derived from a Revit face as reference element</param>
        /// <param name="line">A line on the face defining where the symbol is to be placed</param>
        /// <returns>FamilyInstance</returns>
        public static FamilyInstance ByFace(FamilyType familyType, Surface face, Autodesk.DesignScript.Geometry.Line line)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }
            if (face == null)
            {
                throw new ArgumentNullException("face");
            }
            if (line == null)
            {
                throw new ArgumentNullException("line");
            }
            var reference = ElementFaceReference.TryGetFaceReference(face);

            return(new FamilyInstance(familyType.InternalFamilySymbol, reference.InternalReference, (Autodesk.Revit.DB.Line)line.ToRevitType()));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
        /// and the rotation of the grid lines with respect to the natural UV parameterization of the face
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="uDivs"></param>
        /// <param name="vDivs"></param>
        /// <param name="gridRotation"></param>
        /// <returns></returns>
        public static DividedSurface ByFaceUVDivisionsAndRotation(Autodesk.DesignScript.Geometry.Surface surface, int uDivs, int vDivs, double gridRotation)
        {
            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (uDivs <= 0)
            {
                throw new Exception("uDivs must be a positive integer");
            }

            if (vDivs <= 0)
            {
                throw new Exception("vDivs must be a positive integer");
            }

            return(new DividedSurface(ElementFaceReference.TryGetFaceReference(surface), uDivs, vDivs, gridRotation));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
        /// and the rotation of the grid lines with respect to the natural UV parameterization of the face
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="uDivs"></param>
        /// <param name="vDivs"></param>
        /// <param name="gridRotation"></param>
        /// <returns></returns>
        public static DividedSurface ByFaceUVDivisionsAndRotation(Autodesk.DesignScript.Geometry.Surface surface, int uDivs, int vDivs, double gridRotation)
        {
            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (uDivs <= 0)
            {
                throw new Exception(string.Format(Properties.Resources.NotPositiveIntegerError, "uDivs"));
            }

            if (vDivs <= 0)
            {
                throw new Exception(string.Format(Properties.Resources.NotPositiveIntegerError, "vDivs"));
            }

            return(new DividedSurface(ElementFaceReference.TryGetFaceReference(surface), uDivs, vDivs, gridRotation));
        }
Ejemplo n.º 6
0
        public static AdaptiveComponent ByParametersOnFace(double[][] uvs, Surface surface, FamilyType familyType)
        {
            if (uvs == null)
            {
                throw new ArgumentNullException("uvs");
            }

            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }

            return(new AdaptiveComponent(uvs, ElementFaceReference.TryGetFaceReference(surface), familyType));
        }
        /// <summary>
        /// Show a colored Face Analysis Display in the Revit view.
        /// </summary>
        /// <param name="view">The view into which you want to draw the analysis results.</param>
        /// <param name="surface">The surface which you want to show color.</param>
        /// <param name="sampleLocations">The locations at which you want to create analysis values.</param>
        /// <param name="samples">The analysis values at the given locations.</param>
        /// <param name="name">An optional analysis results name to show on the results legend.</param>
        /// <param name="description">An optional analysis results description to show on the results legend.</param>
        /// <param name="unitType">An optional Unit type to provide conversions in the analysis results.</param>
        /// <returns>A FaceAnalysisDisplay object.</returns>
        public static FaceAnalysisDisplay ByViewFacePointsAndValues(
            View view, Surface surface,
            Autodesk.DesignScript.Geometry.UV[] sampleLocations, double[] samples, string name = "", string description = "", Type unitType = null)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (sampleLocations == null)
            {
                throw new ArgumentNullException("sampleUvPoints");
            }

            if (samples == null)
            {
                throw new ArgumentNullException("samples");
            }

            if (sampleLocations.Length != samples.Length)
            {
                throw new Exception(Properties.Resources.Array_Count_Mismatch);
            }

            if (string.IsNullOrEmpty(name))
            {
                name = Properties.Resources.AnalysisResultsDefaultName;
            }

            if (string.IsNullOrEmpty(description))
            {
                description = Properties.Resources.AnalysisResultsDefaultDescription;
            }

            var data = SurfaceData.BySurfacePointsAndValues(surface, sampleLocations, samples);

            return(new FaceAnalysisDisplay(view.InternalView, data, name, description, unitType));
        }
Ejemplo n.º 8
0
        public static List <Autodesk.DesignScript.Geometry.Surface> InnerLoops(this SketchUpNET.Surface v, Transform t = null)
        {
            List <Autodesk.DesignScript.Geometry.Surface> surfaces = new List <Autodesk.DesignScript.Geometry.Surface>();

            foreach (Loop loop in v.InnerEdges)
            {
                List <Autodesk.DesignScript.Geometry.Curve> curves = new List <Autodesk.DesignScript.Geometry.Curve>();
                foreach (Edge c in loop.Edges)
                {
                    curves.Add(c.ToDSGeo(t).ToNurbsCurve());
                }
                int a = 0;
                Autodesk.DesignScript.Geometry.PolyCurve pc = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(curves);
                Autodesk.DesignScript.Geometry.Surface   s  = Autodesk.DesignScript.Geometry.Surface.ByPatch(pc);
                surfaces.Add(s);
            }

            return(surfaces);
        }
Ejemplo n.º 9
0
        public static IList <GeometryObject> ToRevitType(this Autodesk.DesignScript.Geometry.Surface srf,
                                                         bool performHostUnitConversion = true)
        {
            var rp = new RenderPackage();

            if (performHostUnitConversion)
            {
                var newSrf = srf.InHostUnits();
                newSrf.Tessellate(rp);
                newSrf.Dispose();
            }
            else
            {
                srf.Tessellate(rp);
            }

            var tsb = new TessellatedShapeBuilder();

            tsb.OpenConnectedFaceSet(false);

            var v = rp.TriangleVertices;

            for (int i = 0; i < v.Count; i += 9)
            {
                var a = new XYZ(v[i], v[i + 1], v[i + 2]);
                var b = new XYZ(v[i + 3], v[i + 4], v[i + 5]);
                var c = new XYZ(v[i + 6], v[i + 7], v[i + 8]);

                var face = new TessellatedFace(new List <XYZ>()
                {
                    a, b, c
                }, MaterialsManager.Instance.DynamoMaterialId);
                tsb.AddFace(face);
            }

            tsb.CloseConnectedFaceSet();

            var result = tsb.Build(TessellatedShapeBuilderTarget.Mesh, TessellatedShapeBuilderFallback.Salvage, ElementId.InvalidElementId);

            return(result.GetGeometricalObjects());
        }
Ejemplo n.º 10
0
        public static List <Autodesk.Revit.DB.GeometryObject> SendToCurrentRevitDocument(List <object> geo)
        {
            List <Autodesk.Revit.DB.GeometryObject> outPut = new List <Autodesk.Revit.DB.GeometryObject>();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            for (int i = 0; i < geo.Count; i++)
            {
                if (geo[i] is Autodesk.DesignScript.Geometry.Surface)
                {
                    Autodesk.DesignScript.Geometry.Surface   srf = geo[i] as Autodesk.DesignScript.Geometry.Surface;
                    IList <Autodesk.Revit.DB.GeometryObject> dc  = srf.ToRevitType();



                    // "Start" the transaction
                    TransactionManager.Instance.EnsureInTransaction(DOC);

                    for (int j = 0; j < dc.Count; j++)
                    {
                        outPut.Add(dc[j]);
                    }

                    // "End" the transaction
                    TransactionManager.Instance.TransactionTaskDone();
                }
            }

            sw.Stop();

            string data = string.Format("Time taken to load {0} elements: {1} seconds ", outPut.Count.ToString(), (sw.ElapsedMilliseconds * 0.001).ToString());



            MessageBox.Show(data, "Parasite.IO Data", MessageBoxButtons.OK, MessageBoxIcon.Information);

            return(outPut);
        }
Ejemplo n.º 11
0
        public static SurfaceSupport SurfaceSupportDefine(Autodesk.DesignScript.Geometry.Surface surface, Motions motions, [DefaultArgument("MotionsPlasticLimits.Default()")] MotionsPlasticLimits motionsPlasticLimits, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localX, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector localZ, [DefaultArgument("S")] string identifier)
        {
            // convert geometry
            Geometry.Region region = Geometry.Region.FromDynamo(surface);

            // create new surface support
            SurfaceSupport obj = new SurfaceSupport(region, motions, motionsPlasticLimits, identifier);

            // set local x-axis
            if (!localX.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                obj.CoordinateSystem.SetXAroundZ(FemDesign.Geometry.FdVector3d.FromDynamo(localX));
            }

            // set local z-axis
            if (!localZ.Equals(Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0, 0, 0)))
            {
                obj.CoordinateSystem.SetZAroundX(FemDesign.Geometry.FdVector3d.FromDynamo(localZ));
            }

            return(obj);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Place a Revit family instance given the FamilyType (also known as the FamilySymbol in the Revit API)
        /// on a surface derived from a backing Revit face as reference, a reference direction and a point location where to place the family.
        ///
        /// Note: The FamilyType should be workplane based and the input surface must be created from a Revit Face. The reference direction defines the rotation of the instance on the reference, and thus cannot be perpendicular to the face.
        /// </summary>
        /// <param name="familyType">Family Type. Also called Family Symbol.</param>
        /// <param name="face">Surface geometry derived from a Revit face as reference element</param>
        /// <param name="location">Point on the face where the instance is to be placed</param>
        /// <param name="referenceDirection">A vector that defines the direction of placement of the family instance</param>
        /// <returns>FamilyInstance</returns>
        public static FamilyInstance ByFace(FamilyType familyType, Surface face, Point location,
                                            Vector referenceDirection)
        {
            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }
            if (face == null)
            {
                throw new ArgumentNullException("face");
            }
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (referenceDirection == null)
            {
                throw new ArgumentNullException("referenceDirection");
            }
            var reference = ElementFaceReference.TryGetFaceReference(face);

            return(new FamilyInstance(familyType.InternalFamilySymbol, reference.InternalReference,
                                      location.ToXyz(), referenceDirection.ToXyz()));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Try get ElementFaceReference from a Revit Face.
 /// </summary>
 /// <param name="surface">A face from Revit</param>
 /// <returns></returns>
 public static ElementFaceReference BySurface(Autodesk.DesignScript.Geometry.Surface surface)
 {
     return(TryGetFaceReference(surface));
 }
Ejemplo n.º 14
0
 private static ElementFaceReference TryGetFaceReference(Autodesk.DesignScript.Geometry.Surface curveObject, string nodeTypeString = "This node")
 {
     throw new ArgumentException(nodeTypeString + " requires a ElementFaceReference extracted from a Revit Element! " +
                                 "You can use the ImportInstance.ByGeometry to " +
                                 "turn this Surface into a Revit Element.");
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Create FdCoordinateSystem from Dynamo coordinate system on surface mid u/v-point.
 /// </summary>
 internal static FdCoordinateSystem FromDynamoSurface(Autodesk.DesignScript.Geometry.Surface obj)
 {
     Autodesk.DesignScript.Geometry.CoordinateSystem cs = obj.CoordinateSystemAtParameter(0.5, 0.5);
     return(FdCoordinateSystem.FromDynamoCoordinateSystemSurface(cs));
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Create Region from Dynamo surface.
        /// </summary>
        public static Geometry.Region FromDynamo(Autodesk.DesignScript.Geometry.Surface obj)
        {
            // get all perimeter curves
            // curves[] is ordered by the loops of the surface.
            // the assumption here is that the loop with the largest circumference (i.e. the outline) is placed first in the array
            // for fd definition it is neccessary that the outline is the first contour, the subsequent loops can have any order.
            Autodesk.DesignScript.Geometry.Curve[] curves = obj.PerimeterCurves();

            // find closed outlines
            List <Autodesk.DesignScript.Geometry.Curve>         perimeterCurves = new List <Autodesk.DesignScript.Geometry.Curve>();
            List <List <Autodesk.DesignScript.Geometry.Curve> > container       = new List <List <Autodesk.DesignScript.Geometry.Curve> >();

            Autodesk.DesignScript.Geometry.Point pA0, pA1, pB0, pB1;
            // control if new perimeter
            // this happens is pA0/pA1 != pB0/pB1
            for (int idx = 0; idx < curves.Length; idx++)
            {
                if (idx == 0)
                {
                    perimeterCurves.Add(curves[idx]);
                }

                else
                {
                    pA0 = curves[idx - 1].StartPoint;
                    pA1 = curves[idx - 1].EndPoint;
                    pB0 = curves[idx].StartPoint;
                    pB1 = curves[idx].EndPoint;

                    // using Autodesk.DesignScript.Geometry.Point.Equals causes tolerance errors
                    // instead Autodesk.DesignScript.Geometry.Point.IsAlmostEqualTo is used
                    // note that this can cause errors as it is unclear what tolerance IsAlmostEqualTo uses
                    // another alternative would be to create an extension method, Equal(Point point, double tolerance), to Autodesk.DesignScript.Geometry.Point
                    if (pA0.IsAlmostEqualTo(pB0) || pA0.IsAlmostEqualTo(pB1) || pA1.IsAlmostEqualTo(pB0) || pA1.IsAlmostEqualTo(pB1))
                    {
                        perimeterCurves.Add(curves[idx]);
                    }

                    // new perimeter
                    else
                    {
                        container.Add(new List <Autodesk.DesignScript.Geometry.Curve>(perimeterCurves));
                        perimeterCurves.Clear();
                        perimeterCurves.Add(curves[idx]);
                    }
                }
            }
            // add last perimeter to container
            container.Add(new List <Autodesk.DesignScript.Geometry.Curve>(perimeterCurves));
            perimeterCurves.Clear();

            // control if direction is consistent
            // as FromRhinoBrep.
            foreach (List <Autodesk.DesignScript.Geometry.Curve> items in container)
            {
                // if Contour consists of one curve.
                if (items.Count == 1)
                {
                    // check if curve is a Circle

                    // if curve is not a Circle, raise error.
                }

                // if Contour consists of more than one curve.
                else
                {
                    // using Autodesk.DesignScript.Geometry.Point.Equals causes tolerance errors
                    // instead Autodesk.DesignScript.Geometry.Point.IsAlmostEqualTo is used
                    // note that this can cause errors as it is unclear what tolerance IsAlmostEqualTo uses
                    // another alternative would be to create an extension method, Equal(Point point, double tolerance), to Autodesk.DesignScript.Geometry.Point
                    for (int idx = 0; idx < items.Count - 1; idx++)
                    {
                        // curve a = items[idx]
                        // curve b = items[idx + 1]
                        pA0 = items[idx].StartPoint;
                        pA1 = items[idx].EndPoint;
                        pB0 = items[idx + 1].StartPoint;
                        pB1 = items[idx + 1].EndPoint;

                        if (pA0.IsAlmostEqualTo(pB0))
                        {
                            if (idx == 0)
                            {
                                items[idx] = items[idx].Reverse();
                            }
                            else
                            {
                                throw new System.ArgumentException("pA0 == pB0 even though idx != 0. Bad outline.");
                            }
                        }

                        else if (pA0.IsAlmostEqualTo(pB1))
                        {
                            if (idx == 0)
                            {
                                items[idx]     = items[idx].Reverse();
                                items[idx + 1] = items[idx + 1].Reverse();
                            }
                            else
                            {
                                throw new System.ArgumentException("pA0 == pB1 even though idx != 0. Bad outline.");
                            }
                        }

                        else if (pA1.IsAlmostEqualTo(pB0))
                        {
                            // pass
                        }

                        else if (pA1.IsAlmostEqualTo(pB1))
                        {
                            items[idx + 1] = items[idx + 1].Reverse();
                        }

                        else
                        {
                            throw new System.ArgumentException("Can't close outline. Bad outline.");
                        }
                    }
                }
            }

            // create contours
            List <Geometry.Edge>    edges    = new List <Geometry.Edge>();
            List <Geometry.Contour> contours = new List <Geometry.Contour>();

            foreach (List <Autodesk.DesignScript.Geometry.Curve> items in container)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve curve in items)
                {
                    edges.Add(Geometry.Edge.FromDynamo(curve));
                }
                contours.Add(new Geometry.Contour(new List <Edge>(edges)));
                edges.Clear();
            }

            // get LCS
            FdCoordinateSystem cs = FdCoordinateSystem.FromDynamoSurface(obj);

            // return
            return(new Geometry.Region(contours, cs));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Create an adaptive component by uv points on a face.
        /// </summary>
        /// <param name="uvs">An array of UV pairs</param>
        /// <param name="surface">The surface on which to place the AdaptiveComponent</param>
        /// <param name="familyType"></param>
        /// <returns></returns>
        public static AdaptiveComponent ByParametersOnFace(Autodesk.DesignScript.Geometry.UV[] uvs, Surface surface, FamilyType familyType)
        {
            if (uvs == null)
            {
                throw new ArgumentNullException("uvs");
            }

            if (surface == null)
            {
                throw new ArgumentNullException("surface");
            }

            if (familyType == null)
            {
                throw new ArgumentNullException("familyType");
            }

            return(new AdaptiveComponent(uvs.Select(x => new[] { x.U, x.V }).ToArray(), ElementFaceReference.TryGetFaceReference(surface), familyType));
        }
Ejemplo n.º 18
0
        public static Footfall SelfExcitation(Autodesk.DesignScript.Geometry.Surface region, string identifier = "SE", string comment = "")
        {
            var p0 = Geometry.Region.FromDynamo(region);

            return(new Footfall(p0, identifier, comment));
        }
Ejemplo n.º 19
0
 internal static Autodesk.DesignScript.Geometry.Surface AddTag(Autodesk.DesignScript.Geometry.Surface surface, Autodesk.Revit.DB.Reference reference)
 {
     surface.Tags.AddTag(DefaultTag, reference);
     return(surface);
 }
Ejemplo n.º 20
0
 public static Diaphragm Define(Autodesk.DesignScript.Geometry.Surface surface, string identifier = "D")
 {
     return(new Diaphragm(Geometry.Region.FromDynamo(surface), identifier));
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Create a Revit DividedSurface on a face given the face and number of divisions in u and v directon
 /// </summary>
 /// <param name="elementFace"></param>
 /// <param name="uDivs"></param>
 /// <param name="vDivs"></param>
 /// <returns></returns>
 public static DividedSurface ByFaceAndUVDivisions(Autodesk.DesignScript.Geometry.Surface elementFace, int uDivs, int vDivs)
 {
     return(ByFaceUVDivisionsAndRotation(ElementFaceReference.TryGetFaceReference(elementFace), uDivs, vDivs, 0.0));
 }
Ejemplo n.º 22
0
        internal static FaceWall ByFace(WallLocationLine locationLine, WallType wallType, Autodesk.DesignScript.Geometry.Surface surface)
        {
            object reference = surface.Tags.LookupTag("RevitFaceReference");

            if (reference != null && reference.GetType() == typeof(Reference))
            {
                try
                {
                    var revitReference = reference as Reference;
                    return(new FaceWall(locationLine, wallType.InternalWallType, revitReference));
                }
                catch (Exception) { throw new Exception(Properties.Resources.InvalidFace); }
            }
            return(null);
        }