示例#1
0
        public bool GetTitleblocks(ExternalCommandData commandData, String _selectedWallTypeName)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

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

            //read the settings file
            cmdSettingsReadWrite cls  = new cmdSettingsReadWrite();
            string _sourceProjectPath = cls.GetSetting("<GETTER_SOURCE_PROJECT>");

            //open source project
            Document _openedSourceDoc = app.OpenDocumentFile(_sourceProjectPath);


            WallType _selectedWallType = null;

            //get the wall types in the source doc
            FilteredElementCollector sourceWallTypes = new FilteredElementCollector(_openedSourceDoc).OfClass(typeof(ViewSheet));

            foreach (WallType wt in sourceWallTypes)
            {
                if (wt.Name == _selectedWallTypeName)
                {
                    //the name matches
                    _selectedWallType = wt;
                }
            }



            return(true);
        }
示例#2
0
        //search the source project for titleBlocks
        public DataTable getTitleblocks_dataTable(ExternalCommandData m_commandData)
        {
            UIApplication uiapp = m_commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

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



            //read the settings file
            cmdSettingsReadWrite cls  = new cmdSettingsReadWrite();
            string _sourceProjectPath = cls.GetSetting("<GETTER_SOURCE_PROJECT>");

            //DataTable to hold the gotton catagory
            DataTable _DT_gottonCatagory = new DataTable();

            _DT_gottonCatagory = CreateEmptyDataTable("Gotton Catagory");
            DataRow dtRow;

            //var to hold the selected type
            string _userSelectedType;

            //open source project
            Document _openedSourceDoc = app.OpenDocumentFile(_sourceProjectPath);

            //Find system family to copy, e.g. using a named wall type.
            WallType _selectedWallType = null;

            //Element collector
            FilteredElementCollector sourceWallTypes = new FilteredElementCollector(_openedSourceDoc).OfClass(typeof(WallType));

            //loop thru the types and add them to the DataTable
            int _counter = 0;

            foreach (WallType wt in sourceWallTypes)
            {
                dtRow         = _DT_gottonCatagory.NewRow();
                dtRow["ID"]   = _counter;
                dtRow["Name"] = wt.Name;
                _DT_gottonCatagory.Rows.Add(dtRow);

                //increase the counter
                _counter++;
            }

            //return the DT
            return(_DT_gottonCatagory);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

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

            bool allGoodInTheHood = false;

            //app.SharedParametersFilename = LocalFiles.localSpFile;
            //DefinitionFile defFile = app.OpenSharedParameterFile();
            //DefinitionGroups myGroups = defFile.Groups;
            //DefinitionGroup myGroup = myGroups.get_Item("Mechanical");
            //Definitions myDefinitions = myGroup.Definitions;
            //ExternalDefinition eDef = myDefinitions.get_Item("AirFlowAirTerminal") as ExternalDefinition;

            // Create local directory
            LocalFiles.CreateLocalDir();

            // Checks last time the OpenRFA online database was udpated
            LocalFiles.GetLastUpdateJsonOnline();

            MainWindow appDialog = new MainWindow();

            appDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            // Prompt user to select files
            Microsoft.Win32.OpenFileDialog openFilesDlg = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            openFilesDlg.DefaultExt  = ".rfa";
            openFilesDlg.Filter      = "Revit Family (*.rfa)|*.rfa";
            openFilesDlg.Multiselect = true;
            openFilesDlg.Title       = "Select Revit families to load parameters";

            // Only open window if continueCommand is set true
            if (ImportProcess.continueCommand == true)
            {
                openFilesDlg.ShowDialog();

                // Only open MainWindow if files are selected
                if (openFilesDlg.FileNames.Length > 0)
                {
                    appDialog.ShowDialog();

                    // Print all families to be modified
                    StringBuilder sb = new StringBuilder();
                    sb.Append("The following files will be modified. It is recommended to backup your families before proceeding. Would you like to continue?\n\n");
                    foreach (string fileName in openFilesDlg.FileNames)
                    {
                        sb.Append(fileName + "\n");
                    }

                    MessageBoxResult resultConfirmOverwrite = System.Windows.MessageBox.Show(sb.ToString(), "Warning", MessageBoxButton.OKCancel);
                    switch (resultConfirmOverwrite)
                    {
                    // Execute command if user confirmed
                    case MessageBoxResult.OK:


                        // Only executes if the user clicked "OK" button
                        if (appDialog.DialogResult.HasValue && appDialog.DialogResult.Value)
                        {
                            // Opens configuration window
                            ConfigureImport confDialog = new ConfigureImport();
                            confDialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            confDialog.ShowDialog();

                            // Only execute command if configure process is committed by user
                            if (confDialog.DialogResult.HasValue && confDialog.DialogResult.Value)
                            {
                                // Iterate through selected families and add parameters to each
                                foreach (string fileName in openFilesDlg.FileNames)
                                {
                                    // Check if user is trying to modify active doc
                                    if (fileName == docUi.PathName)
                                    {
                                        System.Windows.MessageBox.Show("This addin cannot be run on the active document. This family has been skipped in the process: \n" + fileName);
                                    }
                                    else
                                    {
                                        System.Windows.MessageBox.Show("Adding parameters to: " + fileName);
                                        doc = app.OpenDocumentFile(fileName);

                                        // Complete import process
                                        ImportProcess.ProcessImport(doc, app, confDialog.DialogResult.HasValue, confDialog.DialogResult.Value);
                                        doc.Close(true);
                                    }
                                }
                            }
                        }

                        // Clear all data in case addin is run again in the same session
                        // TODO: Call this method with every method that uses the datatables?
                        ImportProcess.ClearAllData();

                        allGoodInTheHood = true;
                        break;

                    case MessageBoxResult.Cancel:
                        ImportProcess.ClearAllData();
                        allGoodInTheHood = false;
                        break;
                    }
                }
            }


            // Return results
            if (allGoodInTheHood)
            {
                return(Result.Succeeded);
            }
            else
            {
                return(Result.Cancelled);
            }
        }
示例#4
0
        public FamilyInstance CreateFamily(RoomProperties rp)
        {
            FamilyInstance familyInstance = null;

            try
            {
                string   currentAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()).Location;
                string   massTemplate    = Path.GetDirectoryName(currentAssembly) + "/Resources/Mass.rfa";
                Document familyDoc       = null;
                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start("Open Document");
                    familyDoc = m_app.OpenDocumentFile(massTemplate);
                    trans.Commit();
                }

                if (null != familyDoc)
                {
                    bool createdParam = false;
                    using (Transaction trans = new Transaction(familyDoc))
                    {
                        FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions();
                        FailureHandler         failureHandler         = new FailureHandler();
                        failureHandlingOptions.SetFailuresPreprocessor(failureHandler);
                        failureHandlingOptions.SetClearAfterRollback(true);
                        trans.SetFailureHandlingOptions(failureHandlingOptions);

                        trans.Start("Create Extrusion");
                        try
                        {
                            FamilyType newFamilyType = familyDoc.FamilyManager.NewType(rp.Name);

                            bool createdMass = CreateExtrusion(familyDoc, rp);

                            Dictionary <string, Parameter> parameters = new Dictionary <string, Parameter>();
                            parameters = rp.Parameters;
                            if (createdMass)
                            {
                                createdParam = CreateNewParameters(familyDoc, parameters);
                            }

                            if (failureHandler.FailureMessageInfoList.Count > 0)
                            {
                                failureMessage.AppendLine("[" + rp.ID + ": " + rp.Name + "] :" + failureHandler.FailureMessageInfoList[0].ErrorMessage);
                            }

                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Failed to create family.\n" + ex.Message, "MassCreator: CreateFamily", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            trans.RollBack();
                        }
                    }
                    if (createdParam)
                    {
                        SaveAsOptions opt = new SaveAsOptions();
                        opt.OverwriteExistingFile = true;
                        string fileName = Path.Combine(massFolder, rp.ID + ".rfa");
                        familyDoc.SaveAs(fileName, opt);
                        familyDoc.Close(true);
                        familyInstance = LoadMassFamily(fileName, rp.LevelObj);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create family.\n" + ex.Message, "MassCreator: CreateFamily", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(familyInstance);
        }
示例#5
0
        public bool GetTheTypes(ExternalCommandData commandData, String _selectedWallTypeName)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

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

            //read the settings file
            cmdSettingsReadWrite cls  = new cmdSettingsReadWrite();
            string _sourceProjectPath = cls.GetSetting("<GETTER_SOURCE_PROJECT>");

            //open source project
            Document _openedSourceDoc = app.OpenDocumentFile(_sourceProjectPath);


            WallType _selectedWallType = null;

            //get the wall types in the source doc
            FilteredElementCollector sourceWallTypes = new FilteredElementCollector(_openedSourceDoc).OfClass(typeof(WallType));

            foreach (WallType wt in sourceWallTypes)
            {
                if (wt.Name == _selectedWallTypeName)
                {
                    //the name matches
                    _selectedWallType = wt;
                }
            }


            //Create a wall type in the current document

            using (Transaction tx = new Transaction(doc, "Get Types"))
            {
                tx.Start("Transfer Wall Type");

                WallType newWallType = null;

                //get the wall types in the current doc
                FilteredElementCollector wallTypes = new FilteredElementCollector(doc).OfClass(typeof(WallType));

                foreach (WallType wt in wallTypes)
                {
                    if (wt.Kind == _selectedWallType.Kind)
                    {
                        newWallType = wt.Duplicate(_selectedWallTypeName) as WallType;

                        TaskDialog.Show("Wall Created", "The selected wall has been created.");

                        break;
                    }
                }


                // Assign parameter values from source wall type:

#if COPY_INDIVIDUAL_PARAMETER_VALUE
                // Example: individually copy the "Function" parameter value:

                BuiltInParameter bip      = BuiltInParameter.FUNCTION_PARAM;
                string           function = wallType.get_Parameter(bip).AsString();
                Parameter        p        = newWallType.get_Parameter(bip);
                p.Set(function);


                BuiltInParameter bip            = BuiltInParameter.WALL_ATTR_WIDTH_PARAM;
                Double           _selectedWidth = _selectedWallType.get_Parameter(bip).AsDouble();
                Parameter        newWallWidth   = newWallType.get_Parameter(bip);
                newWallWidth.Set(_selectedWidth);
#endif // COPY_INDIVIDUAL_PARAMETER_VALUE



                Parameter p = null;

                foreach (Parameter p2 in newWallType.Parameters)
                {
                    Definition d = p2.Definition;

                    if (p2.IsReadOnly)
                    {
                        System.Diagnostics.Debug.Print(string.Format("Parameter '{0}' is read-only.", d.Name));
                    }
                    else
                    {
                        p = newWallType.get_Parameter(d);

                        if (null == p)
                        {
                            System.Diagnostics.Debug.Print(string.Format("Parameter '{0}' not found on source wall type.", d.Name));
                        }
                        else
                        {
                            if (p.StorageType == StorageType.ElementId)
                            {
                                // Here you have to find the corresponding
                                // element in the target document.

                                System.Diagnostics.Debug.Print(string.Format("Parameter '{0}' is an element id.", d.Name));
                            }
                            else
                            {
                                if (p.StorageType == StorageType.String)
                                {
                                    p2.Set(p.AsString());
                                }
                                else if (p.StorageType == StorageType.Double)
                                {
                                    p2.Set(p.AsDouble());
                                }
                                else if (p.StorageType == StorageType.Integer)
                                {
                                    p2.Set(p.AsInteger());
                                }
                                System.Diagnostics.Debug.Print(string.Format("Parameter '{0}' copied.", d.Name));
                            }
                        }
                    }
                }

                TaskDialog.Show("Parameter Set", "The walls parameters have been set.");

                MemberInfo[] memberInfos = newWallType.GetType().GetMembers(BindingFlags.GetProperty);

                foreach (MemberInfo m in memberInfos)
                {
                    // Copy the writable property values here.
                    // As there are no property writable for
                    // Walltype, I ignore this process here.
                }

                tx.Commit();
                tx.Dispose();
            }

            return(true);
        }
示例#6
0
//    public void ReadAllFiles(string directory)
//    {
//        var fileNames = Directory.GetFiles(directory);
//        List<string> datedNames = new List<string>;

//    }
//    public string ReadDate(string filename)
//        {
//        if (filename.Length > 8)
//            {
//                var dateTest = filename.Substring(0,8);
//            }
//        if (int.TryParse(dateTest, out fileDate))
//            {
//               return DateTime.ParseExact(dateStub, "yyyyMMdd", null);
//            }
//        else { return DateTime.Today;}
//    }

    public Result Execute(
        ExternalCommandData commandData,
        ref string message,
        ElementSet elements)
    {
        Autodesk.Revit.UI.UIApplication m_app;
        m_app = commandData.Application;
        Autodesk.Revit.ApplicationServices.Application app = m_app.Application;

        // Check worksharing mode of each document
        // Open Revit projects
        OpenFileDialog theDialogRevit = new OpenFileDialog();

        theDialogRevit.Title            = "Select Revit Project Files";
        theDialogRevit.Filter           = "RVT files|*.rvt";
        theDialogRevit.FilterIndex      = 1;
        theDialogRevit.InitialDirectory = @"D:\";
        theDialogRevit.Multiselect      = true;

        if (theDialogRevit.ShowDialog() == DialogResult.OK)
        {
            DateTime            todaysDate           = DateTime.Today;
            string              dateStamp            = string.Format("{0}", todaysDate.ToString("yyyyMMdd"));
            string              mpath                = "";
            string              mpathOnlyFilename    = "";
            FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
            string              currentFolder        = Path.GetDirectoryName(theDialogRevit.FileName);


            folderBrowserDialog1.Description = "Select Folder Where Revit Projects to be Saved in Local";
            //folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
            folderBrowserDialog1.SelectedPath = currentFolder;

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                mpath = folderBrowserDialog1.SelectedPath;
                foreach (String projectPath in theDialogRevit.FileNames)
                {
                    // convert input string to directory info.
                    FileInfo  filePath = new FileInfo(projectPath);
                    ModelPath mp       = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath.FullName);

                    OpenOptions opt = new OpenOptions();
                    opt.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets;
                    mpathOnlyFilename           = string.Format("{0}_{1}", dateStamp, filePath.Name);
                    Document                 openedDoc = app.OpenDocumentFile(mp, opt);
                    SaveAsOptions            options   = new SaveAsOptions();
                    WorksharingSaveAsOptions wsOptions = new WorksharingSaveAsOptions();
                    options.OverwriteExistingFile = true;
                    wsOptions.SaveAsCentral       = true;
                    options.SetWorksharingOptions(wsOptions);
                    ModelPath modelPathout = ModelPathUtils.ConvertUserVisiblePathToModelPath(mpath + "\\" + mpathOnlyFilename);
                    openedDoc.SaveAs(modelPathout, options);
                    openedDoc.Close(false);
                }
            }

            // Scan backup folder and retrieve date prefixes
            //List<string> filesToDelete =  ReadAllFiles(mpath);
        }
        return(Result.Succeeded);
    }