Ejemplo n.º 1
0
 internal Dyn.Geometry EnsureUnit(Dyn.Geometry geo, bool disposeInput = false)
 {
     Dyn.Geometry scgeo = null;
     Dyn.Plane    xy    = Dyn.Plane.XY();
     if (targetUnit == baseUnit)
     {
         scgeo = geo.Scale(xy, 1, 1, 1);
     }
     else
     {
         if (baseUnit == "Meters" && targetUnit == "Feet")
         {
             double factor = 3.280841666667;
             scgeo = geo.Scale(xy, factor, factor, factor);
         }
         else if (baseUnit == "Feet" && targetUnit == "Meters")
         {
             double factor = 0.304800164592;
             scgeo = geo.Scale(xy, factor, factor, factor);
         }
         else
         {
         }
     }
     if (disposeInput)
     {
         geo.Dispose();
     }
     xy.Dispose();
     return(scgeo);
 }
Ejemplo n.º 2
0
        internal OctreeNode ClosestNodeRecursive(OctreeNode ot, Autodesk.DesignScript.Geometry.Geometry geom)
        {
            if (ot.isLeaf())
            {
                return(ot);
            }
            double     minDist     = -10;
            OctreeNode closestNode = null;

            foreach (OctreeNode child in ot.children)
            {
                if (!ot.isValid())
                {
                    continue;
                }
                double childDist = child.DistanceTo(geom);
                if (minDist < 0 || childDist < minDist)
                {
                    minDist     = childDist;
                    closestNode = child;
                }
            }

            return(ClosestNodeRecursive(closestNode, geom));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a Revit DirectShape given some geometry, a name for the shape, a Category, and Material.
        /// The geometry will be tessellated before being placed in the Revit model
        /// The category of a DirectShape cannot be changed after creation, so
        /// a new DirectShape will be generated if the category input is changed.
        /// </summary>
        /// <param name="geometry">A Solid or Surface that will be tessellated and placed in the Revit model as a DirectShape</param>
        /// <param name="name">A string name for the DirectShape</param>
        /// <param name="category">Must be a top level Built-in Category</param>
        /// <param name="material">A Material to apply to the faces of the DirectShape</param>
        /// <returns>A DirectShape Element</returns>
        public static DirectShape ByGeometry(Autodesk.DesignScript.Geometry.Geometry geometry,
                                             Category category,
                                             [DefaultArgumentAttribute(" DirectShape.DynamoPreviewMaterial")] Material material,
                                             string name = DEFAULT_NAME)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }

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

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

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

            if (geometry is Autodesk.DesignScript.Geometry.Solid || geometry is Autodesk.DesignScript.Geometry.Surface)
            {
                return(new DirectShape(geometry, name, category, material));
            }

            throw new ArgumentException(Revit.Properties.Resources.DirectShapeInvalidArgument);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Import a collection of Geometry (Solid, Curve, Surface, etc) into Revit as an ImportInstance.
        /// </summary>
        /// <param name="geometry">A single piece of geometry</param>
        /// <returns></returns>
        public static ImportInstance ByGeometry(Autodesk.DesignScript.Geometry.Geometry geometry)
        {
            List <Autodesk.DesignScript.Geometry.Geometry> geometries =
                new List <Autodesk.DesignScript.Geometry.Geometry>();

            geometries.Add(geometry);
            return(ByGeometries(geometries.ToArray()));
        }
Ejemplo n.º 5
0
 private static Autodesk.DesignScript.Geometry.Geometry Transform(Autodesk.DesignScript.Geometry.Geometry geom, CoordinateSystem coordinateSystem)
 {
     if (coordinateSystem == null)
     {
         return(geom);
     }
     return(geom.Transform(coordinateSystem));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Import a collection of Geometry (Solid, Curve, Surface, etc) into Revit views as an ImportInstance.
        /// </summary>
        /// <param name="geometry">A single piece of geometry</param>
        /// <param name="view">The view into which the ImportInstance will be imported.</param>
        /// <returns></returns>
        public static ImportInstance ByGeometryAndView(Autodesk.DesignScript.Geometry.Geometry geometry, Revit.Elements.Views.View view)
        {
            List <Autodesk.DesignScript.Geometry.Geometry> geometries =
                new List <Autodesk.DesignScript.Geometry.Geometry>();

            geometries.Add(geometry);
            return(ByGeometriesAndView(geometries.ToArray(), view));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This method contains workarounds for increasing the robustness of input geometry
        /// </summary>
        /// <param name="geometry"></param>
        /// <param name="translation"></param>
        private static void Robustify(ref Autodesk.DesignScript.Geometry.Geometry geometry,
                                      ref Autodesk.DesignScript.Geometry.Vector translation)
        {
            // translate centroid of the solid to the origin
            // export, then move back
            if (geometry is Autodesk.DesignScript.Geometry.Solid)
            {
                var solid = geometry as Autodesk.DesignScript.Geometry.Solid;

                translation = solid.Centroid().AsVector();
                var tranGeo = solid.Translate(translation.Reverse());

                geometry = tranGeo;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Import a collection of Geometry (Solid, Curve, Surface, etc) into Revit as an ImportInstance.
        /// </summary>
        /// <param name="geometry">A single piece of geometry</param>
        /// <returns></returns>
        public static ImportInstance ByGeometry(Autodesk.DesignScript.Geometry.Geometry geometry)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }

            // Create a temp file name to export to
            var fn = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".sat";

            var translation = Vector.ByCoordinates(0, 0, 0);

            Robustify(ref geometry, ref translation);

            var exported_fn = geometry.ExportToSAT(fn);

            return(new ImportInstance(exported_fn, translation.ToXyz()));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Import a collection of Geometry (Solid, Curve, Surface, etc) into Revit as an ImportInstance.
        /// </summary>
        /// <param name="geometry">A single piece of geometry</param>
        /// <returns></returns>
        public static ImportInstance ByGeometry(Autodesk.DesignScript.Geometry.Geometry geometry)
        {
            if (geometry == null)
            {
                throw new ArgumentNullException("geometry");
            }

            // transform geometry from dynamo unit system (m) to revit (ft)
            geometry = geometry.InHostUnits();

            var translation = Vector.ByCoordinates(0, 0, 0);

            Robustify(ref geometry, ref translation);

            // Export to temporary file
            var fn          = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".sat";
            var exported_fn = geometry.ExportToSAT(fn);

            return(new ImportInstance(exported_fn, translation.ToXyz()));
        }
Ejemplo n.º 10
0
        public void Tessellate(IRenderPackage package, TessellationParameters parameters)
        {
            package.RequiresPerVertexColoration = true;
            Point center = SphereNode.Center(this);

            Autodesk.DesignScript.Geometry.Geometry geometry = Sphere.ByCenterPointRadius(center, this.radius);
            byte[] color = new byte[] { 0, 200, 200, 50 };
            // As you add more data to the render package, you need
            // to keep track of the index where this coloration will
            // start from.

            geometry.Tessellate(package, parameters);

            if (package.MeshVertexCount > 0)
            {
                package.ApplyMeshVertexColors(CreateColorByteArrayOfSize(package.MeshVertexCount, color[0], color[1], color[2], color[3]));
            }
            center.Dispose();
            geometry.Dispose();
        }
Ejemplo n.º 11
0
 private static Autodesk.DesignScript.Geometry.Geometry Tag(Autodesk.DesignScript.Geometry.Geometry geo,
                                                            Autodesk.Revit.DB.Reference reference)
 {
     return(geo);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Create a TranformableExample class which stores a Geometry object and a Transform.
        /// </summary>
        /// <param name="geometry"> a geometry object</param>
        /// <returns></returns>
        public static TransformableExample ByGeometry(Autodesk.DesignScript.Geometry.Geometry geometry)
        {
            var newTransformableThing = new TransformableExample(geometry);

            return(newTransformableThing);
        }
Ejemplo n.º 13
0
 public OctreeNode ClosestNode(Autodesk.DesignScript.Geometry.Geometry geometry)
 {
     return(ClosestNodeRecursive(this._root, geometry));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Create PDF Geometry from Dynamo Geometry
 /// </summary>
 /// <param name="geometry"></param>
 /// <param name="settings"></param>
 public PDFGeometry(Dyn.Geometry geometry, PrintSettings settings)
 {
     this.Geometry = geometry;
     this.Settings = settings;
 }