예제 #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument    uiDoc = uiApp.ActiveUIDocument;

            app = uiApp.Application;
            doc = uiDoc.Document;

            //the idea is to filter for all of the electrical fixtures, grab the first element in that list, and then place that item in the thing
            FilteredElementCollector TelephoneCollector = new FilteredElementCollector(doc);

            TelephoneCollector.OfClass(typeof(FamilySymbol));
            TelephoneCollector.OfCategory(BuiltInCategory.OST_TelephoneDevices);

            if (TelephoneCollector.FirstElement() == null)
            {
                TaskDialog.Show("Electrical Devices", "No Telephone Devices family is loaded in the project.");
                return(Result.Cancelled);
            }

            ElementType elemType = TelephoneCollector.FirstElement() as ElementType;

            uiDoc.PostRequestForElementTypePlacement(elemType);

            return(Result.Succeeded);
        }
예제 #2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument    uiDoc = uiApp.ActiveUIDocument;

            app = uiApp.Application;
            doc = uiDoc.Document;

            //the idea is to filter for all of the electrical fixtures, grab the first element in that list, and then place that item in the thing
            FilteredElementCollector ElectricalFixturesCollector = new FilteredElementCollector(doc);

            ElectricalFixturesCollector.OfClass(typeof(FamilySymbol));
            ElectricalFixturesCollector.OfCategory(BuiltInCategory.OST_ElectricalFixtures);

            //NOTES:
            //  doc.Create.FamilyInstanceCreationData(XYZ, FamilySymbol, Element, StructuralType) ?
            //  Element.ElementId ?
            //  Selection.SetElementIds(ICollection<ElementId>) ?
            //  NewFamilyInstance(XYZ, FamilySymbol, Element, StructureType)

            if (ElectricalFixturesCollector.FirstElement() == null)
            {
                TaskDialog.Show("Electrical Devices", "No Electrical Fixrues family is loaded in the project.");
                return(Result.Cancelled);
            }

            ElementType elemType = ElectricalFixturesCollector.FirstElement() as ElementType;

            uiDoc.PostRequestForElementTypePlacement(elemType);

            return(Result.Succeeded);
        }
예제 #3
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            if (listView.SelectedItems.Count > 0)
            {
                foreach (var item in symbols)
                {
                    if (item.symbol_name == listView.SelectedItems[0].Text)
                    {
                        Close();

                        FamilyBrowser.Family_browser.Hide();

                        uidoc.PostRequestForElementTypePlacement(item.family_symbol);
                    }
                }
            }
        }
예제 #4
0
        public void Execute(UIApplication app)
        {
            UIDocument uidoc = app.ActiveUIDocument;

            Document doc = uidoc.Document;

            Family Family;

            //载入族
            using (Transaction trans = new Transaction(uidoc.Document, "载入族"))
            {
                trans.Start();

                uidoc.Document.LoadFamily(FamilyBrowser.fileName, out Family);

                trans.Commit();
            }

            //找到所有指定名称的族

            ISet <ElementId> FamilySymbolIds = Family.GetFamilySymbolIds();

            var symbols = new List <FamilyData>();

            //把Symbol的name,symbol储存在symbols里,以便调用
            foreach (var FamilySymbolId in FamilySymbolIds)
            {
                var FamilyData = new FamilyData();

                FamilyData.family_symbol = Family.Document.GetElement(FamilySymbolId) as FamilySymbol;

                FamilyData.symbol_name = FamilyData.family_symbol.Name;

                symbols.Add(FamilyData);
            }

            if (symbols.Count == 1)
            {
                uidoc.PostRequestForElementTypePlacement(symbols[0].family_symbol);
            }
            //如果族类型数量大于1,就出现选择窗体
            else
            {
                new SymbolChoose(uidoc, symbols).ShowDialog();
            }
        }
예제 #5
0
        private void project创建实例ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //已知catch内容为:SelectedNode=null
            try
            {
                foreach (var item in Data)
                {
                    if (treeView_project.SelectedNode.Text == item.symbol_name)
                    {
                        Hide();

                        uidoc.PostRequestForElementTypePlacement(item.family_symbol);
                    }
                }
            }
            catch (Exception) { }
        }
예제 #6
0
        private void InsertElement(UIDocument uidoc, Element element)
        {
            Document doc = uidoc.Document;
            FilteredElementCollector elementCollector = new FilteredElementCollector(doc);

            BuiltInCategory category = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), element.Category.Id.ToString());

            elementCollector.OfCategory(category).OfClass(typeof(ElementType));

            foreach (var item in elementCollector)
            {
                if (item.Name.Equals(element.Name))
                {
                    ElementType counduitElement = item as ElementType;
                    uidoc.PostRequestForElementTypePlacement(counduitElement);
                }
            }
        }
        public void Execute(UIApplication uiapp)
        {
            UIDocument uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            string FamilyPath = Properties.Settings.Default.FamilyPath;
            string FamilyType = Properties.Settings.Default.FamilyType;
            string FamilyName = Properties.Settings.Default.FamilyName;

            //TaskDialog.Show("Event", "Selected Type " + FamilyType);
            FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(Family));
            FamilySymbol             symbol    = collector.FirstElement() as FamilySymbol;

            Family family = FindFamilyByName(doc, typeof(Family), FamilyPath) as Family;

            if (family == null)
            {
                using (var transaction = new Transaction(doc, "InsertTransaction"))
                {
                    transaction.Start();
                    if (!doc.LoadFamily(FamilyPath, out family))
                    {
                        TaskDialog.Show("Loading", "Unable to load " + FamilyPath);
                    }
                    transaction.Commit();
                }
            }

            ISet <ElementId> familySymbolId = family.GetFamilySymbolIds();

            foreach (ElementId id in familySymbolId)
            {
                // Get name from buffer to compare
                if (family.Document.GetElement(id).Name == FamilyType && FamilyType != null)
                {
                    symbol = family.Document.GetElement(id) as FamilySymbol;
                }
            }
            uidoc.PostRequestForElementTypePlacement(symbol);
        }
예제 #8
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            ElementType elementType
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_Walls) // .OST_Columns
                  .OfClass(typeof(ElementType))
                  .FirstElement() as ElementType;

            uidoc.PostRequestForElementTypePlacement(
                elementType);

            return(Result.Succeeded);
        }
            public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
            {
                try
                {
                    UIDocument uidoc   = commandData.Application.ActiveUIDocument;
                    ElementId  foundId = null;

                    //是否存在族
                    Boolean found = FilterTools.existFamliyByName(uidoc.Document, GlobalSettings.FamilyName.沉降测点.ToString(), out foundId);

                    Family family = null;
                    if (found == true)
                    {
                        //如果存在,获得文件该族
                        family = uidoc.Document.GetElement(foundId) as Family;
                    }
                    else
                    {
                        //如果不存在,载入族
                        Transaction trans = new Transaction(uidoc.Document, "trans");
                        trans.Start();
                        uidoc.Document.LoadFamily(Path.Combine(GlobalSettings.Path_family, GlobalSettings.FamilyName.沉降测点.ToString() + ".rfa"), out family);
                        trans.Commit();
                    }

                    //获得该族的族类型,并且放置族实例
                    FamilySymbol symbol = uidoc.Document.GetElement(family.GetFamilySymbolIds().ElementAt(0)) as FamilySymbol;
                    uidoc.PostRequestForElementTypePlacement(symbol);
                }
                catch (Exception e)
                {
                    message = e.Message;
                    return(Autodesk.Revit.UI.Result.Failed);
                }
                return(Result.Succeeded);
            }
예제 #10
0
        public void Execute(UIApplication uiapp)
        {
            UIDocument uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            string FamilyPath   = Properties.Settings.Default.FamilyPath;
            string FamilySymbol = Properties.Settings.Default.FamilySymbol;
            string FamilyName   = Properties.Settings.Default.FamilyName;

            if (string.IsNullOrEmpty(FamilyPath))
            {
                FamilySymbol historySymbol = null;
                // TaskDialog.Show("History Ok", FamilySymbol);
                Family historyFamily = new FilteredElementCollector(doc)
                                       .OfClass(typeof(Family))
                                       .FirstOrDefault(e => e.Name.Equals(FamilyName)) as Family;

                ISet <ElementId> historyFamilySymbolId = historyFamily.GetFamilySymbolIds();
                foreach (ElementId id in historyFamilySymbolId)
                {
                    // Get name from buffer to compare
                    if (historyFamily.Document.GetElement(id).Name == FamilySymbol && FamilySymbol != null)
                    {
                        historySymbol = historyFamily.Document.GetElement(id) as FamilySymbol;
                    }
                }
                uidoc.PostRequestForElementTypePlacement(historySymbol);
            }

            else
            {
                FilteredElementCollector collector = new FilteredElementCollector(doc).
                                                     OfCategory(BuiltInCategory.OST_ElectricalFixtures).
                                                     OfClass(typeof(Family));

                FamilySymbol symbol = collector.FirstElement() as FamilySymbol;
                Family       family = FindFamilyByName(doc, typeof(Family), FamilyPath) as Family;

                if (null == family)
                {
                    using (var trans = new Transaction(doc, "Insert Transaction"))
                    {
                        trans.Start();
                        if (!doc.LoadFamily(FamilyPath, out family))
                        {
                            TaskDialog.Show("Loading", "Unable to load " + FamilyPath);
                        }
                        trans.Commit();
                    }
                }

                ISet <ElementId> familySymbolId = family.GetFamilySymbolIds();
                foreach (ElementId id in familySymbolId)
                {
                    // Get name from buffer to compare
                    if (family.Document.GetElement(id).Name == FamilySymbol && FamilySymbol != null)
                    {
                        symbol = family.Document.GetElement(id) as FamilySymbol;
                    }
                }
                uidoc.PostRequestForElementTypePlacement(symbol);
            }
            Tools.CollectFamilyData(doc);
            //Tools.CreateImages(doc);
        }
예제 #11
0
        private void InsertarFamilia(UIApplication app)
        {
            string nombreFamilia = System.IO.Path.GetFileNameWithoutExtension(_pathArchivoFamilia);
            string pathArchivoFamiliaDesencriptado = "";

            //pathArchivoFamiliaDesencriptado = crip2aCAD.clsCR.Fichero_DesencriptaEnTempDame(_pathArchivoFamilia);
            if (string.IsNullOrWhiteSpace(pathArchivoFamiliaDesencriptado))
            {
                pathArchivoFamiliaDesencriptado = _pathArchivoFamilia;
            }
            if (System.IO.File.Exists(pathArchivoFamiliaDesencriptado))
            {
                if (app.ActiveUIDocument.Document.IsFamilyDocument == true)
                {
                    System.Windows.MessageBox.Show("No open Projects to Load Family into", "ATTENTION",
                                                   System.Windows.MessageBoxButton.OK,
                                                   System.Windows.MessageBoxImage.Warning);
                    return;
                }
                Document documentoActivo = app.ActiveUIDocument.Document;
                Family   familia;
                Element  encontrado = new FilteredElementCollector(documentoActivo).OfClass(typeof(Family)).FirstOrDefault <Element>(x => x.Name.Equals(nombreFamilia));
                if (encontrado == null)
                {
                    using (Transaction trans = new Transaction(documentoActivo, "Load family from UCBrowser"))
                    {
                        trans.Start();
                        ULMALGFree.clsBase._registraLoadInsert = false;
                        documentoActivo.LoadFamily(pathArchivoFamiliaDesencriptado, new OpcionesDeSobreescrituraDeFamiliasAnidadasYaExistentesEnElDocumento(), out familia);
                        trans.Commit();
                        if (Main.cLcsv != null)
                        {
                            Main.cLcsv.PonLog_ULMA(ULMALGFree.ACTION.BROWSER_LOAD_FAMILY, FILENAME: pathArchivoFamiliaDesencriptado, FAMILY: familia.Name, EApp: ULMALGFree.queApp.ULMASTUDIO);
                        }
                        ULMALGFree.clsBase._registraLoadInsert = true;
                    }
                }
                else
                {
                    familia = (Family)encontrado;

                    List <string> tipos = new List <string>();
                    string        pathCatalogoDeTipos = System.IO.Path.ChangeExtension(_pathArchivoFamilia, "txt");
                    if (System.IO.File.Exists(pathCatalogoDeTipos))
                    {
                        System.IO.StreamReader catalogo = System.IO.File.OpenText(pathCatalogoDeTipos);
                        string linea;
                        System.Text.RegularExpressions.Regex patronABuscar = new System.Text.RegularExpressions.Regex("(^\"([^\"]+?)\",)|(^([^\",]+?),)");
                        System.Text.RegularExpressions.Match resultadoBusqueda;
                        while ((linea = catalogo.ReadLine()) != null)
                        {
                            resultadoBusqueda = patronABuscar.Match(linea);
                            if (resultadoBusqueda.Success)
                            {
                                if (resultadoBusqueda.Groups[2].Value == "")
                                {
                                    tipos.Add(resultadoBusqueda.Groups[4].Value);
                                }
                                else
                                {
                                    tipos.Add(resultadoBusqueda.Groups[2].Value);
                                }
                            }
                        }
                        if (tipos.Count > familia.GetFamilySymbolIds().Count)
                        {
                            using (Transaction trans = new Transaction(documentoActivo, "Reload family types from UCBrowser"))
                            {
                                trans.Start();
                                foreach (string tipo in tipos)
                                {
                                    //Esto del try...catch no es una solucion elegante; pero es mas efectiva que intentar cargar solo los tipos que no estan en la familia.
                                    try
                                    {
                                        documentoActivo.LoadFamilySymbol(pathArchivoFamiliaDesencriptado, tipo);
                                    }
                                    catch (Exception)
                                    {
                                        continue;
                                    }
                                }
                                trans.Commit();
                            }
                        }
                    }
                }
                if (familia != null)
                {
                    ElementId    idPrimerSimboloEnLaFamilia = familia.GetFamilySymbolIds().First();
                    FamilySymbol simbolo = (FamilySymbol)familia.Document.GetElement(idPrimerSimboloEnLaFamilia);
                    UIDocument   interfaceConElDocumento = new UIDocument(documentoActivo);
                    ULMALGFree.clsBase._registraLoadInsert = false;
                    interfaceConElDocumento.PostRequestForElementTypePlacement(simbolo);
                    if (Main.cLcsv != null)
                    {
                        Main.cLcsv.PonLog_ULMA(ULMALGFree.ACTION.BROWSER_INSERT_FAMILY, FILENAME: simbolo.Family.Document.PathName, FAMILY: simbolo.Name, EApp: ULMALGFree.queApp.ULMASTUDIO);
                    }
                    ULMALGFree.clsBase._registraLoadInsert = true;
                }
            }
            else
            {
                TaskDialog.Show(title: "UCBrowser", mainInstruction: "Family file not found. Please, go to settings dialog and check the family folder set in it."
                                + Environment.NewLine + Environment.NewLine
                                + nombreFamilia);
            }
        }
예제 #12
0
        public void Execute(UIApplication uiapp)
        {
            UIDocument uidoc = uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            string FamilyPath = Properties.Settings.Default.FamilyPath;
            string FamilyType = Properties.Settings.Default.FamilyType;
            string FamilyName = Properties.Settings.Default.FamilyName;

            if (FamilyName.Equals("BuiltInFamily"))
            {
                Element element = null;

                //-----Collect Ducts
                FilteredElementCollector ductCollerctor = new FilteredElementCollector(doc);
                ductCollerctor.OfCategory(BuiltInCategory.OST_DuctCurves);
                element = GetElementFromTemplate(ductCollerctor, FamilyType);

                //-----Collect Cable trays
                if (element == null)
                {
                    FilteredElementCollector cableTrayCollector = new FilteredElementCollector(doc);
                    cableTrayCollector.OfCategory(BuiltInCategory.OST_CableTray);
                    element = GetElementFromTemplate(cableTrayCollector, FamilyType);
                }

                //-----Collect Conduits
                if (element == null)
                {
                    FilteredElementCollector conduitCollector = new FilteredElementCollector(doc);
                    conduitCollector.OfCategory(BuiltInCategory.OST_Conduit);
                    element = GetElementFromTemplate(conduitCollector, FamilyType);
                }

                if (element != null)
                {
                    InsertElement(uidoc, element);
                }
                return;
            }

            else
            {
                FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(Family));
                FamilySymbol             symbol    = collector.FirstElement() as FamilySymbol;

                Family family = FindFamilyByName(doc, typeof(Family), FamilyPath) as Family;

                if (family == null)
                {
                    using (var transaction = new Transaction(doc, "InsertTransaction"))
                    {
                        transaction.Start();
                        if (!doc.LoadFamily(FamilyPath, out family))
                        {
                            TaskDialog.Show("Loading", "Unable to load " + FamilyPath);
                        }
                        transaction.Commit();
                    }
                }
                ISet <ElementId> familySymbolId = family.GetFamilySymbolIds();
                foreach (ElementId id in familySymbolId)
                {
                    // Get name from buffer to compare
                    if (family.Document.GetElement(id).Name == FamilyType && FamilyType != null)
                    {
                        symbol = family.Document.GetElement(id) as FamilySymbol;
                    }
                }
                //MessageBox.Show("Symbol to install" + symbol.Name);
                uidoc.PostRequestForElementTypePlacement(symbol);
            }
        }