Esempio n. 1
0
        static string appData = Environment.ExpandEnvironmentVariables("%appdata%"); //this gives C:\Users\<userName>\AppData\Roaming
        //static string addinsLocation = appData + "/Autodesk/Revit/Addins/2017";
        //static string appUpdater = addinsLocation + "/" + "OAToolsForRevit2017.bundle" + "/" + "AppUpdater.exe";


        // The main Execute method (inherited from IExternalCommand) must be public
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Confirm App has been initialized
            Initilize c       = new Initilize();
            bool      success = c.IsAppInitialized();

            if (!success)
            {
                return(Result.Cancelled);
            }

            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            //Make call to check for updates in AppUpdater project
            //AppUpdater.Program.Main();

            //System.Diagnostics.Process.Start(appUpdater);

            //using (Transaction transaction = new Transaction(doc, "Creating Note BLock"))

            using (Transaction tx = new Transaction(doc, "Update"))
            {
                tx.Start();

                OAToolsUpdater.Updater.RunUpdate();

                tx.Commit();
            }

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Esempio n. 2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Confirm App has been initialized
            Initilize c       = new Initilize();
            bool      success = c.IsAppInitialized();

            if (!success)
            {
                return(Result.Cancelled);
            }

            UIApplication uiapp     = commandData.Application;
            UIDocument    uidoc     = uiapp.ActiveUIDocument;
            Application   app       = uiapp.Application;
            Document      doc       = uidoc.Document;
            Selection     selection = uidoc.Selection;

            frmPCast f = new frmPCast(commandData);

            f.ShowDialog();

            return(Result.Succeeded);
        }
        /// <summary>
        /// External command mainline
        /// </summary>
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Confirm App has been initialized
            Initilize c       = new Initilize();
            bool      success = c.IsAppInitialized();

            if (!success)
            {
                return(Result.Cancelled);
            }

            else
            {
                UIApplication uiapp     = commandData.Application;
                UIDocument    uidoc     = uiapp.ActiveUIDocument;
                Application   app       = uiapp.Application;
                Document      doc       = uidoc.Document;
                Selection     selection = uidoc.Selection;

                //Retrieve the family if it is already present:
                FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(Family));
                Family family = a.FirstOrDefault <Element>(e => e.Name.Equals(FamilyName)) as Family;

                //Check to make sure the user is on a sheet otherwise cancel
                View activeView = doc.ActiveView;
                if (!(activeView is ViewSheet))
                {
                    TaskDialog.Show("ERROR!", "You must be on a sheet to place DNotes");
                    return(Result.Cancelled);
                }

                //Get the active sheet number
                Parameter activeSheetNumber;
                activeSheetNumber = activeView.get_Parameter(BuiltInParameter.SHEET_NUMBER);
                string sheet_number = activeSheetNumber.AsString();

                //Verify that the family path is valid and load the family
                if (null == family)
                {
                    if (!File.Exists(FamilyPath))
                    {
                        //Utilities.Util.ErrorMsg(string.Format(
                        //  "Please ensure that the DNote "
                        //  + "family file '{0}' exists in '{1}'.",
                        //  FamilyName, _family_folder));

                        OAToolsUpdater.Updater c2 = new Updater();
                        bool success2             = c2.getDNoteFile();

                        if (!success2)
                        {
                            TaskDialog.Show("ERROR!", "Cannot download the DNote .rfa file. ERROR CODE:1777");

                            return(Result.Failed);
                        }
                    }

                    // It is not present, so load it:
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Load Family");

                        doc.LoadFamily(FamilyPath, out family);

                        tx.Commit();
                    }
                }

                //Create the symbol var
                FamilySymbol symbol = null;

                //Retrieve the symbol id's
                //This has to happen after the family has been loaded
                ISet <ElementId> symbolIds = family.GetFamilySymbolIds();
                //Loop through the id's, There will only be one, set symbol var
                foreach (ElementId id in symbolIds)
                {
                    symbol = doc.GetElement(id) as FamilySymbol;
                }

                // Place the family symbol:
                //Subscribe to document changed event to retrieve family instance elements added by the PromptForFamilyInstancePlacement operation:
                app.DocumentChanged += new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged);

                _added_element_ids.Clear();

                // PromptForFamilyInstancePlacement cannot
                // be called inside transaction.
                uidoc.PromptForFamilyInstancePlacement(symbol);
                app.DocumentChanged -= new EventHandler <DocumentChangedEventArgs>(OnDocumentChanged);

                // Access the newly placed family instances:
                int n = _added_element_ids.Count();

                //Show the form
                frmCreateDNote form = new frmCreateDNote(sheet_number);
                form.ShowDialog();

                //Get the data from the form
                string DNoteNumberValue = string.Empty;
                DNoteNumberValue = frmCreateDNote.DNoteNumberInput;

                string DNoteSheetValue = string.Empty;
                DNoteSheetValue = frmCreateDNote.DNoteSheetInput;

                string DNoteTextValue = string.Empty;
                DNoteTextValue = frmCreateDNote.DNoteTextInput;

                using (Transaction tx = new Transaction(doc, "Set Parameter"))
                {
                    tx.Start("Set Parameters");

                    //Set the parameters

                    if (0 == symbolIds.Count)
                    {
                        TaskDialog.Show("Error", "No elements selected");
                    }
                    else
                    {
                        foreach (ElementId id in _added_element_ids)
                        {
                            //Gets the element associated with the ID
                            Element eFromId = doc.GetElement(id);

                            ParameterSet pSet = eFromId.Parameters;

                            foreach (Parameter param in pSet)
                            {
                                if (param.Definition.Name.Contains("Number"))
                                {
                                    param.Set(DNoteNumberValue);
                                }
                                if (param.Definition.Name.Contains("Sheet"))
                                {
                                    param.Set(DNoteSheetValue);
                                }
                                if (param.Definition.Name.Contains("Text"))
                                {
                                    param.Set(DNoteTextValue);
                                }
                            }
                        }
                    }

                    tx.Commit();
                }

                //Construct the message
                string msg = string.Format("Placed {0} {1} family instance{2}{3}", n, family.Name, Utilities.Util.PluralSuffix(n), Utilities.Util.DotOrColon(n));
                string ids = string.Join(", ", _added_element_ids.Select <ElementId, string>(id => id.IntegerValue.ToString()));

                //Show the message
                //Util.InfoMsg2(msg, ids);

                return(Result.Succeeded);
            }
        }
Esempio n. 4
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            if (null == commandData)
            {
                throw new ArgumentNullException("commandData");
            }

            Initilize c       = new Initilize();
            bool      success = c.IsAppInitialized();

            if (!success)
            {
                return(Result.Cancelled);
            }


            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

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


            //Set counter
            int counter = 0;


            //Open the form
            using (frmRevitize curForm = new frmRevitize(commandData))
            {
                //Show the form
                curForm.ShowDialog();

                if (curForm.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    //The user canceled
                    return(Result.Cancelled);
                }
                else
                {
                    //Get the selected DWG files
                    List <string> drawingList = curForm.getSelectedDWGs();

                    using (Transaction tx = new Transaction(doc, "Import DWGs to Drafting Views"))
                    {
                        if (tx.Start() == TransactionStatus.Started)
                        {
                            //Loop through DWGs, create Drafting View and insert
                            foreach (string curDWG in drawingList)
                            {
                                //get family type for drafting view
                                ElementId curVFT = getDraftingViewFamilyType(doc);

                                //create drafting view
                                Autodesk.Revit.DB.View curView = ViewDrafting.Create(doc, curVFT);

                                //add the view to the list to be passed out of this
                                createdViewList.Insert(curView);


                                //rename the view to the DWG filename
                                string tmpName  = getFilenameFromPath(curDWG);
                                string viewName = tmpName.Substring(0, tmpName.Length - 4);

                                try
                                {
                                    curView.Name = viewName;
                                }
                                catch (Exception ex)
                                {
                                    TaskDialog.Show("Error", "These is already a Drafting View named " + viewName + "in this project file. The view will be named " + curView.Name + " instead.");
                                    throw;
                                }

                                //set insert settings
                                DWGImportOptions curImportOptions = new DWGImportOptions();



                                switch (curForm.getColorSetting())
                                {
                                case "Invert":
                                    curImportOptions.ColorMode = ImportColorMode.Inverted;
                                    break;

                                case "Preserve":
                                    curImportOptions.ColorMode = ImportColorMode.Preserved;
                                    break;

                                default:
                                    curImportOptions.ColorMode = ImportColorMode.BlackAndWhite;
                                    break;
                                }

                                switch (curForm.getPosSetting())
                                {
                                case "Origin to Origin":
                                    curImportOptions.Placement = ImportPlacement.Origin;
                                    break;

                                case "Center to Center":
                                    curImportOptions.Placement = ImportPlacement.Centered;
                                    break;
                                }

                                //import / link current DWG to current view
                                ElementId curLinkID = null;


                                if (curForm.getInsertType() == "Link")
                                {
                                    doc.Link(curDWG, curImportOptions, curView, out curLinkID);
                                    counter = counter + 1;
                                }
                                else
                                {
                                    doc.Import(curDWG, curImportOptions, curView, out curLinkID);

                                    counter = counter + 1;
                                }
                            }
                        }


                        //commit changes
                        tx.Commit();
                    }
                }
            }



            //ask user if they want to create a sheet
            string      summeryMessage = " Inserted " + counter + " DWG Files.";
            bool        createSheet    = createSheetYesNo(summeryMessage);
            frmRevitize f1             = new frmRevitize(commandData);

            f1.Close();

            if (createSheet)
            {
                cmdSheetsFromViews cmd = new cmdSheetsFromViews();
                cmd.Execute(commandData, ref message, elements, createdViewList);
            }

            return(Result.Succeeded);
        }