Esempio n. 1
0
        /// <summary>
        /// Create one temporary door instance with this family.
        /// </summary>
        /// <returns>the created door.</returns>
        private FamilyInstance CreateOneInstanceWithThisFamily()
        {
            Autodesk.Revit.DB.Document          doc    = m_app.ActiveUIDocument.Document;
            Autodesk.Revit.Creation.Document    creDoc = doc.Create;
            Autodesk.Revit.Creation.Application creApp = m_app.Application.Create;

            // get one level. A project has at least one level.
            Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).FirstElement() as Level;

            // create one wall as door's host
            Line wallCurve = creApp.NewLineBound(new Autodesk.Revit.DB.XYZ(0, 0, 0), new Autodesk.Revit.DB.XYZ(100, 0, 0));
            Wall host      = creDoc.NewWall(wallCurve, level, false);

            doc.Regenerate();

            // door symbol.
            FamilySymbolSetIterator doorSymbolIter = m_family.Symbols.ForwardIterator();

            doorSymbolIter.MoveNext();
            FamilySymbol doorSymbol = doorSymbolIter.Current as FamilySymbol;

            // create the door
            FamilyInstance createdFamilyInstance = creDoc.NewFamilyInstance(new Autodesk.Revit.DB.XYZ(0, 0, 0), doorSymbol, host, level,
                                                                            StructuralType.NonStructural);

            doc.Regenerate();

            return(createdFamilyInstance);
        }
Esempio n. 2
0
        public void Make()
        {
            try
            {
                Document familyDoc = _ProjectDoc.Application.NewFamilyDocument(_TemplateFileName);
                if (null == familyDoc)
                {
                    throw new Exception("Failed to open the family document");
                }
                CreateFamily(familyDoc);

                if (!familyDoc.SaveAs(_TempLocation + @"\" + _Name + @".rfa"))
                {
                    throw new Exception("Failed to save family document!");
                }

                FamilySymbolSetIterator symbolItor = null;
                Transaction             transLoad  = new Transaction(familyDoc, "Load Family");
                if (transLoad.Start() == TransactionStatus.Started)
                {
                    FamilyLoadOpt flo    = new FamilyLoadOpt();
                    Family        family = familyDoc.LoadFamily(_ProjectDoc, flo);
                    symbolItor = family.Symbols.ForwardIterator();
                    transLoad.Commit();
                }

                Transaction transPlace = new Transaction(_ProjectDoc, "PlaceFamily");
                if (transPlace.Start() == TransactionStatus.Started)
                {
                    double y = 0.0;

                    symbolItor.MoveNext();
                    while (_Count > 0)
                    {
                        FamilySymbol   symbol   = symbolItor.Current as FamilySymbol;
                        XYZ            location = new XYZ(_X, y, 0.0);
                        FamilyInstance instance = _ProjectDoc.Create.NewFamilyInstance(location, symbol, StructuralType.NonStructural);
                        y += _Y;
                        --_Count;
                    }
                    transPlace.Commit();
                }
                familyDoc.Close(false);

                //File.Delete(_TempLocation + @"\" + _Name + @".rfa");

                _X += _Side + FormFile.xPad;
            }

            catch (Exception ex)
            {
                TaskDialog.Show("Load Error", ex.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="family"></param>
        /// <param name="famInst"></param>
        /// <param name="famSymbolString"></param>
        private void UpdateFamilySymbol(Family family, FamilyInstance famInst, string familySymbolString)
        {
            FamilySymbolSet         famSymSet     = family.Symbols;
            FamilySymbolSetIterator famSymSetIter = famSymSet.ForwardIterator();

            while (famSymSetIter.MoveNext())
            {
                FamilySymbol famSymbol = famSymSetIter.Current as FamilySymbol;
                if (famSymbol.Name == familySymbolString)
                {
                    famInst.Symbol = famSymbol;
                    break;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Update Left/Right feature based on family's actual geometry and country's standard.
        /// </summary>
        public void UpdateOpeningFeature()
        {
            // get current Left/Right feature's value of this door family.
            FamilySymbolSetIterator doorSymbolIter = m_family.Symbols.ForwardIterator();

            while (doorSymbolIter.MoveNext())
            {
                FamilySymbol doorSymbol = doorSymbolIter.Current as FamilySymbol;

                // update the the related family shared parameter's value if user already added it.
                if (doorSymbol.ParametersMap.Contains("BasalOpening"))
                {
                    Parameter basalOpeningParam = doorSymbol.ParametersMap.get_Item("BasalOpening");
                    bool      setResult         = basalOpeningParam.Set(m_basalOpeningValue);
                }
            }
        }
Esempio n. 5
0
        GetFamilySymbol(Autodesk.Revit.DB.Family fam, string famSymName)
        {
            FamilySymbolSetIterator famSymSetIter = fam.Symbols.ForwardIterator();

            while (famSymSetIter.MoveNext())
            {
                FamilySymbol famSymTemp = famSymSetIter.Current as FamilySymbol;
                if (famSymTemp != null)
                {
                    if (famSymTemp.Name == famSymName)
                    {
                        return(famSymTemp);
                    }
                }
            }
            return(null);
        }
Esempio n. 6
0
        private FamilyInstance LoadMassFamily(string fileName, Level level)
        {
            FamilyInstance familyInstance = null;

            using (Transaction trans = new Transaction(doc))
            {
                trans.Start("Load Mass Family");
                try
                {
                    Family newFamily = null;
                    bool   loaded    = doc.LoadFamily(fileName, new FamilyOption(), out newFamily);
                    if (loaded)
                    {
#if RELEASE2013 || RELEASE2014
                        FamilySymbolSetIterator symbolIterator = newFamily.Symbols.ForwardIterator();
                        symbolIterator.MoveNext();
                        FamilySymbol symbol = symbolIterator.Current as FamilySymbol;

#if RELEASE2013
                        FilteredElementCollector collector = new FilteredElementCollector(doc);
                        SketchPlane skPlane = collector.OfClass(typeof(SketchPlane)).First <Element>(e => e.Name.Equals(level.Name)) as SketchPlane;
                        familyInstance = doc.Create.NewFamilyInstance(new XYZ(0, 0, skPlane.Plane.Origin.Z), symbol, skPlane, StructuralType.NonStructural);
#elif RELEASE2014
                        if (!symbol.IsActive)
                        {
                            symbol.Activate();
                        }
                        SketchPlane skPlane = SketchPlane.Create(doc, level.Id);
                        familyInstance = doc.Create.NewFamilyInstance(new XYZ(0, 0, skPlane.GetPlane().Origin.Z), symbol, skPlane, StructuralType.NonStructural);
#endif
#elif RELEASE2015 || RELEASE2016
                        List <ElementId> elementIds = newFamily.GetFamilySymbolIds().ToList();
                        if (elementIds.Count > 0)
                        {
                            ElementId    symbolId = elementIds.First();
                            FamilySymbol fSymbol  = doc.GetElement(symbolId) as FamilySymbol;
                            if (null != fSymbol)
                            {
                                if (!fSymbol.IsActive)
                                {
                                    fSymbol.Activate();
                                }
                                SketchPlane skPlane = SketchPlane.Create(doc, level.Id);
                                if (null != skPlane)
                                {
                                    familyInstance = doc.Create.NewFamilyInstance(new XYZ(0, 0, skPlane.GetPlane().Origin.Z), fSymbol, skPlane, StructuralType.NonStructural);
                                }
                            }
                        }
#endif
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to load mass family.\n" + ex.Message, "MassCreator : Load Mass Family", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    trans.RollBack();
                }
            }
            return(familyInstance);
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of TagBeamData.
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command</param>
        public TagBeamData(ExternalCommandData commandData)
        {
            //Get beams selected
            m_revitDoc   = commandData.Application.ActiveUIDocument;
            m_docCreator = m_revitDoc.Document.Create;
            m_view       = m_revitDoc.Document.ActiveView;

            SelElementSet      elementSet = m_revitDoc.Selection.Elements;
            ElementSetIterator itor       = elementSet.ForwardIterator();

            while (itor.MoveNext())
            {
                FamilyInstance familyInstance = itor.Current as FamilyInstance;
                if ((familyInstance != null) && (familyInstance.StructuralType == Autodesk.Revit.DB.Structure.StructuralType.Beam))
                {
                    m_beamList.Add(familyInstance);
                }
            }
            if (m_beamList.Count < 1)
            {
                throw new ApplicationException("there is no beam selected");
            }

            //Get the family symbols of tag in this document.
            FilteredElementCollector collector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document);
            IList <Element>          elements  = collector.OfClass(typeof(Family)).ToElements();

            foreach (Family family in elements)
            {
                if (family != null && family.Symbols != null)
                {
                    FamilySymbolSetIterator it = family.Symbols.ForwardIterator();
                    while (it.MoveNext())
                    {
                        try
                        {
                            FamilySymbol tagSymbol = it.Current as FamilySymbol;
                            if (tagSymbol != null)
                            {
                                switch (tagSymbol.Category.Name)
                                {
                                case "Structural Framing Tags":
                                    m_categoryTagTypes.Add(new FamilySymbolWrapper(tagSymbol));
                                    continue;

                                case "Material Tags":
                                    m_materialTagTypes.Add(new FamilySymbolWrapper(tagSymbol));
                                    continue;

                                case "Multi-Category Tags":
                                    m_multiCategoryTagTypes.Add(new FamilySymbolWrapper(tagSymbol));
                                    continue;

                                default:
                                    continue;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }
            }
        }