/// <summary>
        /// Associate the parameters of the selected family to the current family
        /// </summary>
        public void Wire()
        {
            if (!doc.IsFamilyDocument || !famParam.Any())
            {
                return;                                                         //Only work in Family Document that has parameters to associate with
            }
            var wireFamily = Utils.PickObject(uidoc, "Pick a Nested Family.");  //Get the family to associate to

            if (wireFamily == null)
            {
                return;
            }
            var fam = doc.GetElement(wireFamily) as FamilyInstance;

            if (fam == null)
            {
                return;                                   //We could get a random selection, we haven't implemented a Filter (which we could TO DO)
            }
            AssociateParameters(fam, ParamType.Instance); //Associate all possible Instance parameters
            AssociateParameters(fam, ParamType.Type);     //Associate all possible Type

            if (!String.IsNullOrEmpty(AlertMessage))
            {
                DialogUtils.Alert("Warning", AlertMessage);                                                     //Finally, alert the user if we had any issues
            }
            if (!String.IsNullOrEmpty(SuccessMessage))
            {
                DialogUtils.OK("Wire successful", SuccessMessage);                                                     //And, issue an OK message the user for all the successfully processed parameters
            }
        }
Ejemplo n.º 2
0
        //De-facto the command is here. Will either be started on start (duh) or activated when switched back to a Family Document
        public bool ShowForm()
        {
            GetRevitHandle();

            _presenter = null;
            if (_presenter == null || _presenter._isClosed)
            {
                try
                {
                    if (!Application.App.ActiveUIDocument.Document.IsFamilyDocument)
                    {
                        DialogUtils.Alert("Error", "Usable only in Family Documents");
                        return(false);
                    }

                    handler = new RequestHandler();                         //new handler
                    exEvent = ExternalEvent.Create(handler);                //new event

                    _document  = Application.App.ActiveUIDocument.Document; //set current document
                    _presenter = new FamilyParameterViewModel(_document);

                    _presenter.Show(_hWndRevit);    //pass parent (Revit) thread here
                    _presenter.PresenterClosed += Stop;
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("Error", ex.Message);
                    _presenter.Dispose();
                    _presenter = null;
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Checks if the document is a Family Document and issues a Warning if it isn't
 /// </summary>
 /// <param name="doc"></param>
 internal static bool CheckFamilyDocument(Document doc)
 {
     if (doc.IsFamilyDocument)
     {
         return(true);
     }
     else
     {
         DialogUtils.Alert("Warning", "Not a Family Document.");
         return(false);
     }
 }
        //Associate the parameters
        //NOT IN USE IN THIS VERSION
        private string AssociateParameters(FamilyParameter newParameter)
        {
            using (Transaction tw = new Transaction(doc, "Wire parameters"))
            {
                tw.Start();
                try
                {
                    var nestedParameter = GetNestedParameter(newParameter.Definition.Name);                       //Finds the parameter in the nested family
                    SetDocumentParameter(newParameter, nestedParameter);                                          //Set the value first, we don't want to lose it

                    doc.FamilyManager.AssociateElementParameterToFamilyParameter(nestedParameter, newParameter);  //And associates it to the existing family parameter. The second parameter belongs to the Main family
                    return($"'{newParameter.Definition.Name}' was processed successfully.{Environment.NewLine}"); //Helps to populates the SuccessMessage
                }
                catch (Exception ex) { DialogUtils.Alert("Error", ex.Message); return(null); }
                tw.Commit();
            }
        }
        //Creates a regular parameter
        private FamilyParameter AddProjectParameter(ParameterSelectorModel parameterToPull)
        {
            FamilyParameter parameter = null;

            try
            {
                using (Transaction ft = new Transaction(doc, "Pull parameter"))
                {
                    ft.Start();
                    //Adds a Parameter to the Family
                    parameter = familyManager.AddParameter(parameterToPull.Name, parameterToPull.ParameterGroup, parameterToPull.ParameterType, parameterToPull.IsInstance);
                    ft.Commit();
                }
            }
            catch (Exception ex) { DialogUtils.Alert("Failed", ex.Message); }
            return(parameter);
        }
        //Retrieves a Nested Family Documnet from User Selection
        private Document GetNestedDocument()
        {
            var selection = Utils.PickObject(uidoc, "Pick nested family to pull parameters from.");

            if (selection == null)
            {
                return(null);
            }

            var familyInstance = doc.GetElement(selection.ElementId) as FamilyInstance;               //Cast the current selection as a FamilyInstance

            if (familyInstance == null)
            {
                DialogUtils.Alert("Warning", "No nested family selected");                 //If the selection is not a family instance, issue a warning and fail
                return(null);
            }
            var nestedFamily         = familyInstance.Symbol.Family; //Get the family from the selection
            var nestedFamilyDocument = doc.EditFamily(nestedFamily); //Open the family

            this.familyInstance = familyInstance;                    //remember the family instance to use it later

            return(nestedFamilyDocument);
        }
        /// <summary>
        /// The Main method. Pushes selected parameters into a nested family
        /// </summary>
        public void Push()
        {
            if (pushParameters == null)
            {
                return;                                     //No parameter to be pushed, return
            }
            if (familyInstance == null)
            {
                return;                                         //If we failed to collect a family instance from user in the previous step, return
            }
            foreach (FamilyParameter paramToPush in pushParameters)
            {
                SuccessMessage += ExecutePushParamters(familyInstance, paramToPush);                    //Execute Push Parameter for each Selection and each Selected Paramter
            }

            if (!String.IsNullOrEmpty(AlertMessage))
            {
                DialogUtils.Alert("Warning", AlertMessage);                                                     //Finally, alert the user if we had any issues
            }
            if (!String.IsNullOrEmpty(SuccessMessage))
            {
                DialogUtils.OK("Push successful", SuccessMessage);                                                     //And, issue an OK message the user for all the successfully processed parameters
            }
        }
        /// <summary>
        /// The Main method. Pushes selected parameters into a nested family
        /// </summary>
        public void Pull()
        {
            if (!doc.IsFamilyDocument)
            {
                return;                                     //Only execute in FamilyDocument
            }
            if (pullParameters == null)
            {
                return;                                     //No parameter to be pushed, return
            }
            foreach (ParameterSelectorModel parameterToPull in pullParameters)
            {
                ExecutePullParamters(parameterToPull);                  //Execute Push Parameter for each Selection and each Selected Paramter
            }

            if (!String.IsNullOrEmpty(AlertMessage))
            {
                DialogUtils.Alert("Warning", AlertMessage);                                                     //Finally, alert the user if we had any issues
            }
            if (!String.IsNullOrEmpty(SuccessMessage))
            {
                DialogUtils.OK("Pull successful", SuccessMessage);                                                     //And, issue an OK message the user for all the successfully processed parameters
            }
        }
 /// <summary>
 /// Will alert the user through the alert dialog box
 /// </summary>
 public static void ReprotError()
 {
     DialogUtils.Alert("Alert", ErrorLog);
 }