예제 #1
0
파일: Element.cs 프로젝트: ssnkamali/Dynamo
 /// <summary>
 /// Recursively traverse the GeometryElement obtained from this Element, collecting the Curves
 /// </summary>
 /// <param name="geomElem"></param>
 /// <param name="faces"></param>
 private void GetFaces(IEnumerable <Autodesk.Revit.DB.GeometryObject> geomElement, ref FaceArray faces)
 {
     foreach (Autodesk.Revit.DB.GeometryObject geob in geomElement)
     {
         if (geob is GeometryInstance)
         {
             GetFaces((geob as GeometryInstance).GetInstanceGeometry(), ref faces);
         }
         else if (geob is Autodesk.Revit.DB.Solid)
         {
             var mySolid = geob as Autodesk.Revit.DB.Solid;
             if (mySolid != null)
             {
                 foreach (var f in mySolid.Faces.Cast <Autodesk.Revit.DB.Face>().ToList())
                 {
                     faces.Append(f);
                 }
             }
         }
         else if (geob is Autodesk.Revit.DB.GeometryElement)
         {
             GetFaces(geob as GeometryElement, ref faces);
         }
     }
 }
        private FaceArray GetFaces(ICollection <Element> elements)
        {
            FaceArray faceArray = new FaceArray();
            Options   options   = new Options();

            options.ComputeReferences = true;
            foreach (Element element in elements)
            {
                GeometryElement geomElem = element.get_Geometry(options);
                if (geomElem != null)
                {
                    foreach (GeometryObject geomObj in geomElem)
                    {
                        Solid solid = geomObj as Solid;
                        if (solid != null)
                        {
                            foreach (Face f in solid.Faces)
                            {
                                faceArray.Append(f);
                            }
                        }
                        GeometryInstance inst = geomObj as GeometryInstance;
                        if (inst != null) // in-place family walls
                        {
                            foreach (Object o in inst.SymbolGeometry)
                            {
                                Solid s = o as Solid;
                                if (s != null)
                                {
                                    foreach (Face f in s.Faces)
                                    {
                                        faceArray.Append(f);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(faceArray);
        }
        private static FaceArray GetFaces(Element element)
        {
            var faceArray = new FaceArray();
            var options   = new Options();

            options.ComputeReferences = true;
            var geomElem = element.get_Geometry(options);

            if (geomElem != null)
            {
                foreach (GeometryObject geomObj in geomElem.Objects)
                {
                    var solid = geomObj as Solid;
                    if (solid != null)
                    {
                        foreach (Face f in solid.Faces)
                        {
                            faceArray.Append(f);
                        }
                    }
                    var inst = geomObj as GeometryInstance;
                    if (inst != null) // in-place family walls
                    {
                        foreach (Object o in inst.SymbolGeometry.Objects)
                        {
                            var s = o as Solid;
                            if (s != null)
                            {
                                foreach (Face f in s.Faces)
                                {
                                    faceArray.Append(f);
                                }
                            }
                        }
                    }
                }
            }
            return(faceArray);
        }
예제 #4
0
        /// <summary>
        ///     Converts the Face list to the FaceArray.
        /// </summary>
        /// <param name="faces"></param>
        /// <returns></returns>
        public static FaceArray ToFaceArray <T>(params T[] faces) where T : Face
        {
            if (faces is null)
            {
                throw new ArgumentNullException(nameof(faces));
            }

            var results = new FaceArray();

            foreach (var face in faces)
            {
                results.Append(face);
            }

            return(results);
        }
예제 #5
0
        /// <summary>
        ///     Converts the Face list to the FaceArray.
        /// </summary>
        /// <param name="faces"></param>
        /// <returns></returns>
        public static FaceArray ToFaceArray(this IEnumerable <Face> faces)
        {
            if (faces == null)
            {
                throw new ArgumentNullException(nameof(faces));
            }

            var results = new FaceArray();

            foreach (var face in faces)
            {
                results.Append(face);
            }

            return(results);
        }
예제 #6
0
 private static FaceArray GetFaces(Element element)
 {
     var faceArray = new FaceArray();
     var options = new Options();
     options.ComputeReferences = true;
     var geomElem = element.get_Geometry(options);
     if (geomElem != null)
     {
         foreach (GeometryObject geomObj in geomElem.Objects)
         {
             var solid = geomObj as Solid;
             if (solid != null)
             {
                 foreach (Face f in solid.Faces)
                 {
                     faceArray.Append(f);
                 }
             }
             var inst = geomObj as GeometryInstance;
             if (inst != null) // in-place family walls
             {
                 foreach (Object o in inst.SymbolGeometry.Objects)
                 {
                     var s = o as Solid;
                     if (s != null)
                     {
                         foreach (Face f in s.Faces)
                         {
                             faceArray.Append(f);
                         }
                     }
                 }
             }
         }
     }
     return faceArray;
 }
        //Create family for each building
        //http://thebuildingcoder.typepad.com/blog/2011/06/creating-and-inserting-an-extrusion-family.html
        private bool CreateFamilyFile(ProcessPolygon polygon, double height, string familyFileName, XYZ translation)
        {
            bool     success = true;
            Document FamDoc  = null;

            Autodesk.Revit.DB.Form form = null;
            using (Transaction CreateFamily = new Transaction(_doc))
            {
                CreateFamily.Start("Create a new Family");
                FamDoc = _doc.Application.NewFamilyDocument(this.FamilyTemplateAddress);
                CreateFamily.Commit();
            }
            ReferenceArray refAr = polygon.Get_ReferenceArray(FamDoc, translation);

            using (Transaction CreateExtrusion = new Transaction(FamDoc))
            {
                FailureHandlingOptions failOpt = CreateExtrusion.GetFailureHandlingOptions();
                failOpt.SetFailuresPreprocessor(new WarningSwallower());
                CreateExtrusion.SetFailureHandlingOptions(failOpt);
                CreateExtrusion.Start("Create Extrusion");
                /*Mohammad took this out of try */
                try
                {
                    form = FamDoc.FamilyCreate.NewExtrusionForm(true, refAr, height * XYZ.BasisZ);
                }
                catch (Exception)
                {
                    this.FailedAttemptsToCreateBuildings++;
                    success = false;
                }
                CreateExtrusion.Commit();
            }

            //Added by Mohammad
            using (Transaction AddParamTrans = new Transaction(FamDoc))
            {
                AddParamTrans.Start("Add Parameter");
                Autodesk.Revit.ApplicationServices.Application app = FamDoc.Application;
                View3D view3d = createView3d();

                Dimension windowInsetDimension = null;
                FaceArray faces = new FaceArray();
                if (form.IsSolid)
                {
                    Options options = new Options();
                    options.ComputeReferences = true;
                    //options.View = new Autodesk.Revit.DB.View();
                    //GeometryObjectArray geoArr = extrusion.get_Geometry(options).Objects;
                    IEnumerator <GeometryObject> Objects = form.get_Geometry(options).GetEnumerator();
                    //foreach (GeometryObject geoObj in geoArr)
                    while (Objects.MoveNext())
                    {
                        GeometryObject geoObj = Objects.Current;

                        if (geoObj is Solid)
                        {
                            Solid s = geoObj as Solid;
                            foreach (Face fc in s.Faces)
                            {
                                //MessageBox.Show(fc.ComputeNormal(new UV(0, 0)).X.ToString() + "/n" + fc.ComputeNormal(new UV(0, 0)).Y.ToString() + "/n" + fc.ComputeNormal(new UV(0, 0)).Z.ToString());
                                if (Math.Round((fc.ComputeNormal(new UV(0, 0))).Z) == 1 || Math.Round((fc.ComputeNormal(new UV(0, 0))).Z) == -1)
                                {
                                    faces.Append(fc);
                                }
                            }
                            //**************************************************************************************************************
                            //****************************Here is the Error **********************************************************************
                            //************************************************************************************************************************
                            //windowInsetDimension = AddDimension( FamDoc, view3d, faces.get_Item( 0 ), faces.get_Item( 1 ) );
                            View viewElevation = new FilteredElementCollector(FamDoc).OfClass(typeof(View)).Cast <View>().Where <View>(v => ViewType.Elevation == v.ViewType).FirstOrDefault <View>();
                            windowInsetDimension = AddDimension(FamDoc, viewElevation, faces.get_Item(0), faces.get_Item(1));
                        }
                    }
                }

                //Test for creating dimension
                #region two lines creating dimenstion
                //// first create two lines
                //XYZ pt1 = new XYZ(5, 0, 5);
                //XYZ pt2 = new XYZ(5, 0, 10);
                //Line line = Line.CreateBound(pt1, pt2);
                //Plane plane = app.Create.NewPlane(pt1.CrossProduct(pt2), pt2);

                //SketchPlane skplane = SketchPlane.Create(FamDoc, plane);

                //ModelCurve modelcurve1 = FamDoc.FamilyCreate.NewModelCurve(line, skplane);

                //pt1 = new XYZ(10, 0, 5);
                //pt2 = new XYZ(10, 0, 10);
                //line = Line.CreateBound(pt1, pt2);
                //plane = app.Create.NewPlane(pt1.CrossProduct(pt2), pt2);

                //skplane = SketchPlane.Create(FamDoc, plane);

                //ModelCurve modelcurve2 = FamDoc.FamilyCreate.NewModelCurve(line, skplane);



                //// now create a linear dimension between them
                //ReferenceArray ra = new ReferenceArray();
                //ra.Append(modelcurve1.GeometryCurve.Reference);
                //ra.Append(modelcurve2.GeometryCurve.Reference);

                //pt1 = new XYZ(5, 0, 10);
                //pt2 = new XYZ(10, 0, 10);
                //line = Line.CreateBound(pt1, pt2);


                //Dimension dim = FamDoc.FamilyCreate.NewLinearDimension(view3d, line, ra);
                #endregion

                //creates a prameter named index for each family.
                BuiltInParameterGroup paramGroup = (BuiltInParameterGroup)Enum.Parse(typeof(BuiltInParameterGroup), "PG_GENERAL");
                ParameterType         paramType  = (ParameterType)Enum.Parse(typeof(ParameterType), "Length");
                FamilyManager         m_manager  = FamDoc.FamilyManager;

                FamilyParameter famParam = m_manager.AddParameter("Height", paramGroup, paramType, true);

                //Set the value for the parameter
                if (m_manager.Types.Size == 0)
                {
                    m_manager.NewType("Type 1");
                }

                m_manager.Set(famParam, height);

                //connects dimension to lable called with
                //windowInsetDimension.FamilyLabel = famParam;

                AddParamTrans.Commit();
            }


            SaveAsOptions opt = new SaveAsOptions();
            opt.OverwriteExistingFile = true;
            FamDoc.SaveAs(familyFileName, opt);
            FamDoc.Close(false);
            return(success);
        }
예제 #8
0
파일: Element.cs 프로젝트: RobertiF/Dynamo
        /// <summary>
        /// Recursively traverse the GeometryElement obtained from this Element, collecting the Curves
        /// </summary>
        /// <param name="geomElement"></param>
        /// <param name="faces"></param>
        private static void GetFaces(IEnumerable<Autodesk.Revit.DB.GeometryObject> geomElement, ref FaceArray faces)
        {

                foreach (Autodesk.Revit.DB.GeometryObject geob in geomElement)
                {
                    if (geob is GeometryInstance)
                    {
                        GetFaces((geob as GeometryInstance).GetInstanceGeometry(), ref faces);
                    }
                    else if (geob is Autodesk.Revit.DB.Solid)
                    {
                        var mySolid = geob as Autodesk.Revit.DB.Solid;
                        if (mySolid != null)
                        {
                            foreach (var f in mySolid.Faces.Cast<Autodesk.Revit.DB.Face>().ToList())
                            {
                                faces.Append(f);
                            }
                        }

                    } else if (geob is Autodesk.Revit.DB.GeometryElement)
                    {
                        GetFaces(geob as GeometryElement, ref faces);
                    }
                }

        }
예제 #9
0
        /// <summary>
        /// create a new curtain system
        /// </summary>
        /// <param name="faceIndices">
        /// the faces to be covered with new curtain system
        /// </param>
        /// <param name="byFaceArray">
        /// indicates whether the curtain system will be created by face array
        /// </param>
        public void CreateCurtainSystem(List <int> faceIndices, bool byFaceArray)
        {
            // just refresh the main UI
            if (null == faceIndices ||
                0 == faceIndices.Count)
            {
                if (null != CurtainSystemChanged)
                {
                    CurtainSystemChanged();
                }
                return;
            }
            SystemInfo resultInfo = new SystemInfo(m_mydocument);

            resultInfo.ByFaceArray      = byFaceArray;
            resultInfo.GridFacesIndices = faceIndices;
            resultInfo.Index            = ++m_csIndex;

            //
            // step 1: create the curtain system
            //
            // create the curtain system by face array
            if (true == byFaceArray)
            {
                FaceArray faceArray = new FaceArray();
                foreach (int index in faceIndices)
                {
                    faceArray.Append(m_mydocument.MassFaceArray.get_Item(index));
                }

                Autodesk.Revit.DB.CurtainSystem curtainSystem = null;
                Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString());
                t.Start();
                try
                {
                    curtainSystem = m_mydocument.Document.Create.NewCurtainSystem(faceArray, m_mydocument.CurtainSystemType);
                }
                catch (System.Exception)
                {
                    m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed;
                    t.RollBack();
                    return;
                }

                t.Commit();

                resultInfo.CurtainForm = curtainSystem;
            }
            // create the curtain system by reference array
            else
            {
                ReferenceArray refArray = new ReferenceArray();
                foreach (int index in faceIndices)
                {
                    refArray.Append(m_mydocument.MassFaceArray.get_Item(index).Reference);
                }

                ICollection <ElementId> curtainSystems = null;
                Transaction             t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString());
                t.Start();
                try
                {
                    curtainSystems = m_mydocument.Document.Create.NewCurtainSystem2(refArray, m_mydocument.CurtainSystemType);
                }
                catch (System.Exception)
                {
                    m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed;
                    t.RollBack();
                    return;
                }
                t.Commit();

                // internal fatal error, quit the sample
                if (null == curtainSystems ||
                    1 != curtainSystems.Count)
                {
                    m_mydocument.FatalErrorMsg = Properties.Resources.MSG_MoreThan1CSCreated;
                    return;
                }

                // store the curtain system
                foreach (ElementId cs in curtainSystems)
                {
                    resultInfo.CurtainForm = m_mydocument.Document.GetElement(cs) as Autodesk.Revit.DB.CurtainSystem;
                    break;
                }
            }
            //
            // step 2: update the curtain system list in the main UI
            //
            m_curtainSystemInfos.Add(resultInfo);
            if (null != CurtainSystemChanged)
            {
                CurtainSystemChanged();
            }
        }
예제 #10
0
파일: Command.cs 프로젝트: AMEE/revit
 private FaceArray GetFaces(ICollection<Element> elements)
 {
     FaceArray faceArray = new FaceArray();
      Options options = new Options();
      options.ComputeReferences = true;
      foreach (Element element in elements)
      {
     GeometryElement geomElem = element.get_Geometry(options);
     if (geomElem != null)
     {
        foreach (GeometryObject geomObj in geomElem.Objects)
        {
           Solid solid = geomObj as Solid;
           if (solid != null)
           {
              foreach (Face f in solid.Faces)
              {
                 faceArray.Append(f);
              }
           }
           GeometryInstance inst = geomObj as GeometryInstance;
           if (inst != null) // in-place family walls
           {
              foreach (Object o in inst.SymbolGeometry.Objects)
              {
                 Solid s = o as Solid;
                 if (s != null)
                 {
                    foreach (Face f in s.Faces)
                    {
                       faceArray.Append(f);
                    }
                 }
              }
           }
        }
     }
      }
      return faceArray;
 }
예제 #11
0
파일: SystemData.cs 프로젝트: AMEE/revit
        /// <summary>
        /// create a new curtain system
        /// </summary>
        /// <param name="faceIndices">
        /// the faces to be covered with new curtain system
        /// </param>
        /// <param name="byFaceArray">
        /// indicates whether the curtain system will be created by face array
        /// </param>
        public void CreateCurtainSystem(List<int> faceIndices, bool byFaceArray)
        {
            // just refresh the main UI
             if (null == faceIndices ||
             0 == faceIndices.Count)
             {
            if (null != CurtainSystemChanged)
            {
               CurtainSystemChanged();
            }
            return;
             }
             SystemInfo resultInfo = new SystemInfo(m_mydocument);
             resultInfo.ByFaceArray = byFaceArray;
             resultInfo.GridFacesIndices = faceIndices;
             resultInfo.Index = ++m_csIndex;

             //
             // step 1: create the curtain system
             //
             // create the curtain system by face array
             if (true == byFaceArray)
             {
            FaceArray faceArray = new FaceArray();
            foreach (int index in faceIndices)
            {
               faceArray.Append(m_mydocument.MassFaceArray.get_Item(index));
            }

            Autodesk.Revit.DB.CurtainSystem curtainSystem = null;
            Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString());
            t.Start();
            try
            {
               curtainSystem = m_mydocument.Document.Create.NewCurtainSystem(faceArray, m_mydocument.CurtainSystemType);
            }
            catch (System.Exception)
            {
               m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed;
               t.RollBack();
               return;
            }

            t.Commit();

            resultInfo.CurtainForm = curtainSystem;
             }
             // create the curtain system by reference array
             else
             {
            ReferenceArray refArray = new ReferenceArray();
            foreach (int index in faceIndices)
            {
               refArray.Append(m_mydocument.MassFaceArray.get_Item(index).Reference);
            }

            ElementSet curtainSystems = null;
            Transaction t = new Transaction(m_mydocument.Document, Guid.NewGuid().GetHashCode().ToString());
            t.Start();
            try
            {
               curtainSystems = m_mydocument.Document.Create.NewCurtainSystem(refArray, m_mydocument.CurtainSystemType);
            }
            catch (System.Exception)
            {
               m_mydocument.FatalErrorMsg = Properties.Resources.MSG_CreateCSFailed;
               t.RollBack();
               return;
            }
            t.Commit();

            // internal fatal error, quit the sample
            if (null == curtainSystems ||
                1 != curtainSystems.Size)
            {
               m_mydocument.FatalErrorMsg = Properties.Resources.MSG_MoreThan1CSCreated;
               return;
            }

            // store the curtain system
            foreach (Autodesk.Revit.DB.CurtainSystem cs in curtainSystems)
            {
               resultInfo.CurtainForm = cs;
               break;
            }
             }
             //
             // step 2: update the curtain system list in the main UI
             //
             m_curtainSystemInfos.Add(resultInfo);
             if (null != CurtainSystemChanged)
             {
            CurtainSystemChanged();
             }
        }