Ejemplo n.º 1
0
        private void InitializeCommand()
        {
            CommandBinding cbApplyParam = new CommandBinding(cmdApplyParam, (sender, e) =>
            {
                using (Transaction trans = new Transaction(doc, "CreateFamilyParameters"))
                {
                    trans.Start();
                    DefinitionFile spfile    = uiapp.Application.OpenSharedParameterFile();
                    DefinitionGroup _grp     = spfile.Groups.get_Item("物理特性");
                    ExternalDefinition _def1 = _grp.Definitions.get_Item("米重") as ExternalDefinition;
                    ExternalDefinition _def2 = _grp.Definitions.get_Item("模图编号") as ExternalDefinition;
                    //添加参数
                    FamilyManager familyMgr  = doc.FamilyManager;
                    bool isInstance          = false;
                    FamilyParameter paramMID = familyMgr.AddParameter(_def2, BuiltInParameterGroup.PG_TEXT, isInstance);
                    FamilyParameter paramWPM = familyMgr.AddParameter(_def1, BuiltInParameterGroup.INVALID, isInstance);

                    familyMgr.Set(paramMID, txtMID.Text);
                    familyMgr.Set(paramWPM, double.Parse(txtWPM.Text));

                    trans.Commit();
                }

                lblApplied.Visibility = System.Windows.Visibility.Visible;
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });

            bnApplyParam.Command = cmdApplyParam;

            ProcFH.CommandBindings.AddRange(new CommandBinding[]
            {
                cbApplyParam
            });
        }
        //Sets the value of the family parameter based on a parameter value
        private void SetDocumentParameter(FamilyParameter docParameter, Parameter famParameter)
        {
            switch (famParameter.StorageType)
            {
            case (StorageType.Double):
                var value = famParameter.AsDouble();
                familyManager.Set(docParameter, famParameter.AsDouble());
                break;

            case (StorageType.Integer):
                familyManager.Set(docParameter, famParameter.AsInteger());
                break;

            case (StorageType.String):
                familyManager.Set(docParameter, famParameter.AsString());
                break;

            case (StorageType.ElementId):
                familyManager.Set(docParameter, famParameter.AsElementId());
                break;

            case (StorageType.None):
                break;
            }
        }
        // ======================================
        //   (3.1) add parameters
        // ======================================
        void addParameters()
        {
            FamilyManager mgr = _doc.FamilyManager;

            // API parameter group for Dimension is PG_GEOMETRY:
            //
            ForgeTypeId     builtinParamGroup = new ForgeTypeId(GroupTypeId.Geometry.TypeId);
            ForgeTypeId     parametertype     = SpecTypeId.Length;
            FamilyParameter paramTw           = mgr.AddParameter(
                "Tw", builtinParamGroup,
                parametertype, false);

            FamilyParameter paramTd = mgr.AddParameter(
                "Td", builtinParamGroup,
                parametertype, false);

            // set initial values:
            //
            double tw = mmToFeet(150.0);
            double td = mmToFeet(150.0);

            mgr.Set(paramTw, tw);
            mgr.Set(paramTd, td);

            // (2)  add a parameter for material finish
            // we are adding material arameter in addMaterials function.
            // See addMaterials for the actual implementation.
            //
        }
Ejemplo n.º 4
0
        // ======================================
        //   (3.1) add parameters
        // ======================================
        void addParameters()
        {
            FamilyManager mgr = _doc.FamilyManager;

            // API parameter group for Dimension is PG_GEOMETRY:
            //
            ForgeTypeId builtinParamGroup = new ForgeTypeId(GroupTypeId.Geometry.TypeId);
            ForgeTypeId parameterTypeId   = SpecTypeId.Length;

            FamilyParameter paramTw = mgr.AddParameter(
                "Tw", builtinParamGroup,
                parameterTypeId, false);

            FamilyParameter paramTd = mgr.AddParameter(
                "Td", builtinParamGroup,
                parameterTypeId, false);

            // set initial values:
            //
            double tw = mmToFeet(150.0);
            double td = mmToFeet(150.0);

            mgr.Set(paramTw, tw);
            mgr.Set(paramTd, td);
        }
        // ======================================
        //   (3.1) add parameters
        // ======================================
        void addParameters()
        {
            FamilyManager mgr = _doc.FamilyManager;

              // API parameter group for Dimension is PG_GEOMETRY:
              //
              FamilyParameter paramTw = mgr.AddParameter(
            "Tw", BuiltInParameterGroup.PG_GEOMETRY,
            ParameterType.Length, false);

              FamilyParameter paramTd = mgr.AddParameter(
            "Td", BuiltInParameterGroup.PG_GEOMETRY,
            ParameterType.Length, false);

              // set initial values:
              //
              double tw = mmToFeet(150.0);
              double td = mmToFeet(150.0);
              mgr.Set(paramTw, tw);
              mgr.Set(paramTd, td);

              // (2)  add a parameter for material finish
              // we are adding material arameter in addMaterials function.
              // See addMaterials for the actual implementation.
              //
        }
        // add one type (version 1)
        //
        void addType(string name, double w, double d)
        {
            // get the family manager from the current doc
              FamilyManager pFamilyMgr = _doc.FamilyManager;

              // add new types with the given name
              //
              FamilyType type1 = pFamilyMgr.NewType(name);

              // look for 'Width' and 'Depth' parameters and set them to the given value
              //
              // first 'Width'
              //
              FamilyParameter paramW = pFamilyMgr.get_Parameter("Width");
              double valW = mmToFeet(w);
              if (paramW != null)
              {
            pFamilyMgr.Set(paramW, valW);
              }

              // same idea for 'Depth'
              //
              FamilyParameter paramD = pFamilyMgr.get_Parameter("Depth");
              double valD = mmToFeet(d);
              if (paramD != null)
              {
            pFamilyMgr.Set(paramD, valD);
              }
        }
 public static void SetParameter(this FamilyManager manager, FamilyParameter parameter, object value)
 {
     if (null == parameter)
     {
         return;
     }
     if (parameter.IsReadOnly || parameter.IsDeterminedByFormula)
     {
         return;
     }
     if (value is ElementId)
     {
         manager.Set(parameter, (ElementId)value);
     }
     else if (value is int)
     {
         manager.Set(parameter, (int)value);
     }
     else if (value is double)
     {
         manager.Set(parameter, (double)value);
     }
     else if (value is string)
     {
         manager.Set(parameter, (string)value);
     }
 }
Ejemplo n.º 8
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document      CurDoc    = commandData.Application.ActiveUIDocument.Document;
            FamilyManager FM        = CurDoc.FamilyManager;
            Reference     reference = commandData.Application.ActiveUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
            Document      Doc       = commandData.Application.ActiveUIDocument.Document;
            Element       e         = Doc.GetElement(reference);

            BuiltInParameterGroup pGroup = BuiltInParameterGroup.PG_CONSTRUCTION;
            string        pName          = "Depth";
            ParameterType pType          = ParameterType.Length;
            bool          isIstance      = false;

            string[] types = { "typ1", "typ2", "typ3", "typ4", "typ5" };

            Transaction t = new Transaction(CurDoc, "doing things");

            t.Start();

            FamilyParameter FP = FM.AddParameter(pName, pGroup, pType, isIstance);

            switch (FP.StorageType)
            {
            case StorageType.Double:
                FM.Set(FP, 15.5); // wartość w STOPACH
                break;

            case StorageType.Integer:
                FM.Set(FP, 16);
                break;

            case StorageType.String:
                FM.Set(FP, "15.5");
                break;

            case StorageType.ElementId:
                break;

            case StorageType.None:
                break;
            }

            /* foreach (string n in types)
             * {
             *   double x = 15.5;
             *   FM.NewType(n);
             *   FM.Set(FP, x);
             *   x += 0.75;
             * }*/
            t.Commit();
            return(Result.Succeeded);
        }
Ejemplo n.º 9
0
        public void CONNECTION(Document doc, c.Application app)
        {
            FamilyManager familyManager = doc.FamilyManager;
            string        origfile      = app.SharedParametersFilename;
            string        tempFile      = @"C:\Program Files\Autodesk\CEGCustomMenu\Shared_Params_2015_v01.json";
            Transaction   tran          = new Transaction(doc, "add parameter");

            tran.Start();
            app.SharedParametersFilename = tempFile;
            DefinitionFile shareParameterfile = app.OpenSharedParameterFile();

            foreach (DefinitionGroup i in shareParameterfile.Groups)
            {
                if (i.Name == "IDENTITY")
                {
                    //group data
                    FamilyParameter p1 = _AddParameter(doc, i, "CONTROL_MARK", BuiltInParameterGroup.PG_DATA, false);
                    FamilyParameter p2 = _AddParameter(doc, i, "IDENTITY_COMMENT", BuiltInParameterGroup.PG_DATA, false);
                    FamilyParameter p3 = _AddParameter(doc, i, "IDENTITY_DESCRIPTION", BuiltInParameterGroup.PG_DATA, false);
                    FamilyParameter p4 = _AddParameter(doc, i, "IDENTITY_DESCRIPTION_SHORT", BuiltInParameterGroup.PG_DATA, false);
                    FamilyParameter p5 = _AddParameter(doc, i, "MANUFACTURER_PLANT_DESCRIPTION", BuiltInParameterGroup.PG_DATA, false);
                    FamilyParameter p6 = _AddParameter(doc, i, "MANUFACTURER_PLANT_ID", BuiltInParameterGroup.PG_DATA, false);
                    FamilyParameter p7 = _AddParameter(doc, i, "MANUFACTURE_COMPONENT", BuiltInParameterGroup.PG_DATA, false);
                    FamilyParameter p8 = _AddParameter(doc, i, "SORTING_ORDER", BuiltInParameterGroup.PG_DATA, false);
                    familyManager.Set(p7, "CONNECTION");
                }
            }
            tran.Commit();
        }
Ejemplo n.º 10
0
        private bool CreateNewParameters(Document familyDoc, Dictionary <string, Parameter> parameters)
        {
            bool result = false;

            try
            {
                FamilyManager familyManager = familyDoc.FamilyManager;

                foreach (string paramName in defDictionary.Keys)
                {
                    ExternalDefinition extDefinition   = defDictionary[paramName] as ExternalDefinition;
                    FamilyParameter    familyParam     = familyManager.AddParameter(extDefinition, BuiltInParameterGroup.INVALID, true);
                    string             originParamName = paramName.Replace("Mass_", "");
                    if (parameters.ContainsKey(originParamName))
                    {
                        Parameter param = parameters[originParamName];

                        switch (param.StorageType)
                        {
                        case StorageType.Double:
                            familyManager.Set(familyParam, param.AsDouble());
                            break;

                        case StorageType.Integer:
                            familyManager.Set(familyParam, param.AsInteger());
                            break;

                        case StorageType.String:
                            if (null != param.AsString())
                            {
                                familyManager.Set(familyParam, param.AsString());
                            }
                            break;
                        }
                    }
                }
                result = true;
                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create new instance parameters.\n" + ex.Message, "MassCreator:CreateNewParameters", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(result);
            }
        }
Ejemplo n.º 11
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication rvtUIAPP = commandData.Application;
            UIDocument    uidoc    = rvtUIAPP.ActiveUIDocument;
            Configuration config   = ConfigurationManager.OpenExeConfiguration
                                         (System.Reflection.Assembly.GetExecutingAssembly().Location);
            string familyRepo = config.AppSettings.Settings["Family_repo_folder"].Value;
            string serverAPI  = config.AppSettings.Settings["Server_API"].Value;

            m_rvtDoc = uidoc.Document;
            m_rvtApp = rvtUIAPP.Application;
            try
            {
                string[] filePaths = Directory.GetFiles(@familyRepo, "*.rfa");
                foreach (string path in filePaths)
                {
                    Document doc = m_rvtApp.OpenDocumentFile(path);
                    if (doc.IsFamilyDocument)
                    {
                        try {
                            Family          f       = doc.OwnerFamily;
                            FamilyManager   manager = doc.FamilyManager;
                            FamilyParameter keynote = null;

                            String note = HttpGET(serverAPI + "GetFamilyKeynote?path=" + path);
                            keynote = manager.get_Parameter(BuiltInParameter.KEYNOTE_PARAM);
                            if (keynote != null)
                            {
                                using (Transaction trans = new Transaction(doc, "SET_PARAM"))
                                {
                                    trans.Start();
                                    if (manager.Types.Size == 0)
                                    {
                                        manager.NewType("Type 1");
                                    }
                                    manager.SetFormula(keynote, null);
                                    manager.Set(keynote, note);
                                    trans.Commit();
                                }
                                doc.Save();
                            }
                        }
                        catch (Exception e)
                        {
                            TaskDialog.Show("Error2", e.Message);
                        }
                    }
                }

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Executes on restore all values
        /// </summary>
        /// <param name="uiapp"></param>
        /// <param name="text"></param>
        /// <param name="values"></param>
        private void ExecuteParameterChange(UIApplication uiapp, String text, List <Tuple <string, string, double> > values)
        {
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            if (!doc.IsFamilyDocument)
            {
                Command.global_message =
                    "Please run this command in a family document.";
                TaskDialog.Show("Message", Command.global_message);
            }

            if ((uidoc != null))
            {
                using (TransactionGroup tg = new TransactionGroup(doc, "Parameter Change"))
                {
                    tg.Start();
                    foreach (var value in values)
                    {
                        using (Transaction trans = new Transaction(uidoc.Document))
                        {
                            FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions();
                            FailureHandler         failureHandler         = new FailureHandler();
                            failureHandlingOptions.SetFailuresPreprocessor(failureHandler);
                            failureHandlingOptions.SetClearAfterRollback(true);
                            trans.SetFailureHandlingOptions(failureHandlingOptions);

                            FamilyManager   mgr = doc.FamilyManager;
                            FamilyParameter fp  = mgr.get_Parameter(value.Item1);
                            // Since we'll modify the document, we need a transaction
                            // It's best if a transaction is scoped by a 'using' block
                            // The name of the transaction was given as an argument
                            if (trans.Start(text) == TransactionStatus.Started)
                            {
                                mgr.Set(fp, value.Item3);
                                //operation(mgr, fp);
                                doc.Regenerate();
                                if (!value.Item1.Equals(value.Item2))
                                {
                                    mgr.RenameParameter(fp, value.Item2);
                                }
                                trans.Commit();
                                uidoc.RefreshActiveView();
                            }
                            if (failureHandler.ErrorMessage != "")
                            {
                                if (EncounteredError != null)
                                {
                                    EncounteredError(this, null);
                                }
                            }
                        }
                    }
                    tg.Assimilate();
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Add type parameters to the family
        /// </summary>
        /// <param name="DWGFileName">Name of imported dwg file</param>
        private void AddParameters(string DWGFileName)
        {
            // Get the family manager
            FamilyManager familyMgr = m_doc.FamilyManager;

            // Add parameter 1: DWGFileName
            familyMgr.NewType("DWGFamilyCreation");
            FamilyParameter paraFileName = familyMgr.AddParameter("DWGFileName", new ForgeTypeId(),
                                                                  SpecTypeId.String.Text, false);

            familyMgr.Set(paraFileName, DWGFileName);

            // Add parameter 2: ImportTime
            String          time           = DateTime.Now.ToString("yyyy-MM-dd");
            FamilyParameter paraImportTime = familyMgr.AddParameter("ImportTime", new ForgeTypeId(),
                                                                    SpecTypeId.String.Text, false);

            familyMgr.Set(paraImportTime, time);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Add type parameters to the family
        /// </summary>
        /// <param name="DWGFileName">Name of imported dwg file</param>
        private void AddParameters(string DWGFileName)
        {
            // Get the family manager
            FamilyManager familyMgr = m_doc.FamilyManager;

            // Add parameter 1: DWGFileName
            familyMgr.NewType("DWGFamilyCreation");
            FamilyParameter paraFileName = familyMgr.AddParameter("DWGFileName", Autodesk.Revit.DB.BuiltInParameterGroup.INVALID,
                                                                  Autodesk.Revit.DB.ParameterType.Text, false);

            familyMgr.Set(paraFileName, DWGFileName);

            // Add parameter 2: ImportTime
            String          time           = DateTime.Now.ToString("yyyy-MM-dd");
            FamilyParameter paraImportTime = familyMgr.AddParameter("ImportTime", Autodesk.Revit.DB.BuiltInParameterGroup.INVALID,
                                                                    Autodesk.Revit.DB.ParameterType.Text, false);

            familyMgr.Set(paraImportTime, time);
        }
Ejemplo n.º 15
0
        // ======================================
        //   (3.1) add parameters
        // ======================================
        void addParameters()
        {
            FamilyManager mgr = _doc.FamilyManager;

            // API parameter group for Dimension is PG_GEOMETRY:
            //
            FamilyParameter paramTw = mgr.AddParameter(
                "Tw", BuiltInParameterGroup.PG_GEOMETRY,
                ParameterType.Length, false);

            FamilyParameter paramTd = mgr.AddParameter(
                "Td", BuiltInParameterGroup.PG_GEOMETRY,
                ParameterType.Length, false);

            // set initial values:
            //
            double tw = mmToFeet(150.0);
            double td = mmToFeet(150.0);

            mgr.Set(paramTw, tw);
            mgr.Set(paramTd, td);
        }
Ejemplo n.º 16
0
        public FamilySymbol CreatNewSymbol(Document doc, Family doorfamily, int doorwidth, int doorheight, string str)
        {
            Document      familydoc     = doc.EditFamily(doorfamily);
            FamilyManager familymanager = familydoc.FamilyManager;
            string        symbolname    = str;

            using (Transaction creatnewsymbol = new Transaction(familydoc))
            {
                creatnewsymbol.Start("新建族类型");
                FamilyType      familytype  = familymanager.NewType(symbolname);
                FamilyParameter para_width  = familymanager.get_Parameter(BuiltInParameter.DOOR_WIDTH);
                FamilyParameter para_height = familymanager.get_Parameter(BuiltInParameter.GENERIC_HEIGHT);
                familymanager.Set(para_width, doorwidth / 304.8);
                familymanager.Set(para_height, doorheight / 304.8);
                creatnewsymbol.Commit();
            }
            LoadOptions loadoptions = new LoadOptions();

            doorfamily = familydoc.LoadFamily(doc, loadoptions);
            FamilySymbol newsymbol = null;

            using (Transaction activesymbol = new Transaction(doc))
            {
                activesymbol.Start("激活族类型");
                ISet <ElementId> idstmp = doorfamily.GetFamilySymbolIds();
                foreach (ElementId id in idstmp)
                {
                    FamilySymbol symbol = doc.GetElement(id) as FamilySymbol;
                    if (symbol.Name.Equals(symbolname))
                    {
                        symbol.Activate();
                        newsymbol = symbol;
                    }
                }
                activesymbol.Commit();
            }

            return(newsymbol);
        }
Ejemplo n.º 17
0
        private void SetElementIdValue(object value, Autodesk.Revit.DB.FamilyParameter familyParameter)
        {
            Autodesk.Revit.DB.ElementId id;
            try
            {
                id = ((Elements.Element)value).InternalElement.Id;
            }
            catch (Exception)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.WrongStorageType, typeof(Elements.Element)));
            }

            FamilyManager.Set(familyParameter, id);
        }
Ejemplo n.º 18
0
        public void MakeNewFamilyType(Document familyDoc, int D1, int L1)
        {
            FamilyManager familyManager = familyDoc.FamilyManager;

            using (Transaction newFamilyTypeTransaction = new Transaction(familyDoc, "Add Type to Family")) {
                int changesMade = 0;
                newFamilyTypeTransaction.Start();

                FamilyType newFamilyType = familyManager.NewType("60 X 100");

                if (newFamilyType != null)
                {
                    FamilyParameter familyParam = familyManager.get_Parameter("D 1");
                    if (null != familyParam)
                    {
                        familyManager.Set(familyParam, D1);
                        changesMade += 1;
                    }

                    familyParam = familyManager.get_Parameter("L 1");
                    if (null != familyParam)
                    {
                        familyManager.Set(familyParam, L1);
                        changesMade += 1;
                    }
                }

                if (2 == changesMade)
                {
                    newFamilyTypeTransaction.Commit();
                }
                else
                {
                    newFamilyTypeTransaction.RollBack();
                }
            }
        }
Ejemplo n.º 19
0
        private void SetStringValue(object value, Autodesk.Revit.DB.FamilyParameter familyParameter)
        {
            string strValue;

            try
            {
                strValue = (string)value;
            }
            catch (Exception)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.WrongStorageType, familyParameter.StorageType));
            }

            FamilyManager.Set(familyParameter, strValue);
        }
Ejemplo n.º 20
0
        private void SetIntValue(object value, Autodesk.Revit.DB.FamilyParameter familyParameter)
        {
            int intValue;

            try
            {
                intValue = (int)value;
            }
            catch (Exception)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.WrongStorageType, familyParameter.StorageType));;
            }
            var intValueToSet = intValue * UnitConverter.DynamoToHostFactor(familyParameter.Definition.GetSpecTypeId());

            FamilyManager.Set(familyParameter, intValueToSet);
        }
        /// <summary>
        /// Change Parameter
        /// </summary>
        /// <param name="uiapp"></param>
        /// <param name="text"></param>
        /// <param name="values"></param>
        public static void ExecuteParameterChange(UIApplication uiapp, String text, Tuple <string, double> value)
        {
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            if (!doc.IsFamilyDocument)
            {
                Command.global_message = "Please run this command in a family document.";
                TaskDialog.Show("Message", Command.global_message);
            }

            if ((uidoc != null))
            {
                using (Transaction trans = new Transaction(uidoc.Document, "Change Parameter Value"))
                {
                    FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions();
                    FailureHandler         failureHandler         = new FailureHandler();
                    failureHandlingOptions.SetFailuresPreprocessor(failureHandler);
                    failureHandlingOptions.SetClearAfterRollback(true);
                    trans.SetFailureHandlingOptions(failureHandlingOptions);

                    FamilyManager   mgr = doc.FamilyManager;
                    FamilyParameter fp  = mgr.get_Parameter(value.Item1);
                    // Since we'll modify the document, we need a transaction
                    // It's best if a transaction is scoped by a 'using' block
                    // The name of the transaction was given as an argument
                    if (trans.Start(text) == TransactionStatus.Started)
                    {
                        if (fp.IsDeterminedByFormula || fp.IsReporting)
                        {
                            trans.RollBack();  //Cannot change parameters driven by formulas, cannot change reporting parameters
                            return;
                        }

                        mgr.Set(fp, value.Item2);
                        doc.Regenerate();
                        trans.Commit();
                        uidoc.RefreshActiveView();
                        if (failureHandler.ErrorMessage != "")
                        {
                            RequestError.ErrorLog.Add(new Message(fp.Definition.Name, failureHandler.ErrorMessage));
                        }
                    }
                }
            }
        }
        public void addMaterials(Extrusion pSolid)
        {
            // We assume Material type "Glass" exists. Template "Metric Column.rft" include "Glass",
            // which in fact is the only interesting one to see the effect.
            // In practice, you will want to include in your template.
            //
            // To Do: For the exersize, create it with more appropriate ones in UI, then use the name here.
            //

            // (1)  get the materials id that we are intersted in (e.g., "Glass")
            //
            Material pMat = findElement(typeof(Material), "Glass") as Material;

            if (pMat != null)
            {
                ElementId idMat = pMat.Id;
                // (2a) this add a material to the solid base.  but then, we cannot change it for each column.
                //
                //pSolid.Parameter("Material").Set(idMat)

                // (2b) add a parameter for material finish
                //
                // this time we use instance parameter so that we can change it at instance level.
                //
                FamilyManager   pFamilyMgr        = _doc.FamilyManager;
                ForgeTypeId     builtinParamGroup = new ForgeTypeId(GroupTypeId.Materials.TypeId);
                ForgeTypeId     parametertype     = SpecTypeId.Reference.Material;
                FamilyParameter famParamFinish    = pFamilyMgr.AddParameter("ColumnFinish", builtinParamGroup, parametertype, true);

                // (2b.1) associate material parameter to the family parameter we just added
                //
                //  // 'Autodesk.Revit.DB.Element.get_Parameter(string)' is obsolete in Revit 2015
                //Parameter paramMat = pSolid.get_Parameter("Material");

                /// Updated for Revit 2015
                ///
                Parameter paramMat = pSolid.LookupParameter("Material");

                pFamilyMgr.AssociateElementParameterToFamilyParameter(paramMat, famParamFinish);

                // (2b.2) for our convenience, let's add another type with Glass finish
                //
                addType("Glass", 600.0, 600.0);
                pFamilyMgr.Set(famParamFinish, idMat);
            }
        }
        /// <summary>
        /// Working sample code for
        /// http://forums.autodesk.com/t5/revit-api/family-types-amp-shared-parameter-values/m-p/6218767
        /// </summary>
        void SetFamilyParameterValueWorks(
            Document doc,
            string paramNameToAmend)
        {
            FamilyManager   mgr = doc.FamilyManager;
            FamilyParameter familyParam
                = mgr.get_Parameter(paramNameToAmend);

            if (familyParam != null)
            {
                foreach (FamilyType familyType in mgr.Types)
                {
                    Debug.Print(familyType.Name);
                    mgr.CurrentType = familyType;
                    mgr.Set(familyParam, 2);
                }
            }
        }
Ejemplo n.º 24
0
        private void SetNewValueParam(Document doc, List <ChangeMaterialModel> listModel)
        {
            FamilyManager FM = doc.FamilyManager;

            foreach (var model in listModel)
            {
                if (model.new_material != null)
                {
                    try
                    {
                        FM.CurrentType = model.familyType;
                        FM.Set(model.fmParam, model.new_material.Id);
                    }
                    catch
                    {
                    }
                }
            }
        }
Ejemplo n.º 25
0
        void modifyFamilyParamValue()
        {
            FamilyManager mgr = _doc.FamilyManager;

            FamilyParameter[] a = new FamilyParameter[] {
                mgr.get_Parameter("Width"),
                mgr.get_Parameter("Depth")
            };

            foreach (FamilyType t in mgr.Types)
            {
                mgr.CurrentType = t;
                foreach (FamilyParameter fp in a)
                {
                    if (t.HasValue(fp))
                    {
                        double x = (double)t.AsDouble(fp);
                        mgr.Set(fp, 2.0 * x);
                    }
                }
            }
        }
        /// <summary>
        /// Non-working sample code for
        /// http://forums.autodesk.com/t5/revit-api/family-types-amp-shared-parameter-values/m-p/6218767
        /// </summary>
        void SetFamilyParameterValueFails(
            Document doc,
            string paramNameToAmend)
        {
            FamilyManager         mgr         = doc.FamilyManager;
            FamilyTypeSet         familyTypes = mgr.Types;
            FamilyTypeSetIterator familyTypeItor
                = familyTypes.ForwardIterator();

            familyTypeItor.Reset();
            while (familyTypeItor.MoveNext())
            {
                FamilyParameter familyParam
                    = mgr.get_Parameter(paramNameToAmend);

                if (familyParam != null)
                {
                    FamilyType familyType = familyTypeItor.Current as FamilyType;
                    Debug.Print(familyType.Name);
                    mgr.Set(familyParam, 2);
                }
            }
        }
Ejemplo n.º 27
0
        public void ProduceProfile(ref Document doc, ref List <string> vs, ref List <string> pv)
        {
            using (Transaction t = new Transaction(doc, "make profile xn * yn"))
            {
                t.Start();
                FamilyManager familyManager = doc.FamilyManager;

                for (int i = 0; i != vs.Count; i++)
                {
                    FamilyParameter familyParameter = familyManager.get_Parameter(vs[i]);
                    try
                    {
                        familyManager.SetValueString(familyParameter, pv[i]);
                    }
                    catch
                    {
                        familyManager.Set(familyParameter, int.Parse(pv[i]));
                    }
                }


                t.Commit();
            }
        }
Ejemplo n.º 28
0
        private void SetDoubleValue(object value, Autodesk.Revit.DB.FamilyParameter familyParameter)
        {
            double doubleValue;

            try
            {
                if (Type.GetTypeCode(value.GetType()) == TypeCode.Int64 || Type.GetTypeCode(value.GetType()) == TypeCode.Int32)
                {
                    doubleValue = Convert.ToDouble(value);
                }
                else
                {
                    doubleValue = (double)value;
                }
            }
            catch (Exception)
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.WrongStorageType, familyParameter.StorageType));
            }

            double doubleValueToSet = doubleValue * UnitConverter.DynamoToHostFactor(familyParameter.Definition.GetSpecTypeId());

            FamilyManager.Set(familyParameter, doubleValueToSet);
        }
Ejemplo n.º 29
0
//		public void Rename_Shared_Parameters(string p_name,string new_name)
//		{
        ////			UIDocument uidoc = this.ActiveUIDocument;
        ////			Document CachedDoc = uidoc.Document;
//			Document doc;
//			//Application app;
//			string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1";
//
//			// loop through all files in the directory
//
//			foreach (string filename in System.IO.Directory.GetFiles(folder))
//			{
//				try
//				{
//					doc = Application.OpenDocumentFile(filename);
//					if (doc.IsFamilyDocument)
//					{
//
//						Transaction trans = new Transaction(doc, "Remove Param");
//						trans.Start();
//						using(trans)
//						{
//							//ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), "CompanyName");
//							FamilyManager fm = doc.FamilyManager;
//							FamilyParameter fp = RawConvertSetToList<FamilyParameter>(fm.Parameters).
//								FirstOrDefault(e => e.Definition.Name.Equals(p_name, StringComparison.CurrentCultureIgnoreCase));
//							if (fp == null) throw new Exception("Invalid ParameterName Input!");
//							if(fp.IsShared)
//							{
//								ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), p_name);
        ////									        Guid guid = extdef.GUID;
        ////									        ParameterType type = extdef.ParameterType;
        ////									        string group_name = extdef.ParameterGroup.ToString();
//
//								//Create_SP(new_name,type,group_name);
//
        ////									        fm.ReplaceParameter(fp,"temp_test",BuiltInParameterGroup.PG_TEXT,true);
        ////									        FamilyParameter new_fp = RawConvertSetToList<FamilyParameter>(fm.Parameters).
        ////									        FirstOrDefault(e => e.Definition.Name.Equals("temp_test", StringComparison.CurrentCultureIgnoreCase));
        ////									        ExternalDefinition new_extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), new_name);
        ////									        fm.ReplaceParameter(new_fp,new_extdef,new_extdef.ParameterGroup,true);
//							}
//							trans.Commit();
//							//		doc.SaveAs(filename);
//							doc.Close(true);
//						}
//					}
//
//				}
//				catch (Autodesk.Revit.Exceptions.ArgumentNullException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//				//	return;
//				}
//				catch (Autodesk.Revit.Exceptions.FamilyContextException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//				//	return;
//				}
//				catch (Autodesk.Revit.Exceptions.FileAccessException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//				//	return;
//				}
//				catch (Autodesk.Revit.Exceptions.FileNotFoundException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//				//	return;
//				}
//				catch (Autodesk.Revit.Exceptions.ApplicationException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//					return;
//				}
//				catch (SystemException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//					//return;
//				}
//			}
//
//			//TaskDialog.Show("Iam","Here");
//
//		}

        /*	public static string GetParameterValue(FamilyParameter p)
         *      {
         *              switch(p.StorageType)
         *              {
         *                      case StorageType.Double:
         *                              return p.AsValueString();
         *                      case StorageType.ElementId:
         *                              return p.AsElementId().IntegerValue.ToString();
         *                      case StorageType.Integer:
         *                              return p.AsValueString();
         *                      case StorageType.None:
         *                              return p.AsValueString();
         *                      case StorageType.String:
         *                              return p.AsString();
         *                      default:
         *                              return "";
         *
         *              }
         *      }*/

        public static void Rename_Family_Parameters(List <string> full_files_name)
        {
//			UIDocument uidoc = this.ActiveUIDocument;
//			Document CachedDoc = uidoc.Document;
            Document doc;

            //Application app;
            //string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1";

            // loop through all files in the directory

            foreach (string filename in full_files_name)
            {
                doc = CachedApp.OpenDocumentFile(filename);
                try
                {
                    if (doc.IsFamilyDocument)
                    {
                        Transaction trans = new Transaction(doc, "Rename Param");

                        using (trans)
                        {
                            //string s = Globals.new_name_for_rename;


                            trans.Start();
                            FamilyManager   fm = doc.FamilyManager;
                            FamilyParameter fp = RawConvertSetToList <FamilyParameter>(fm.Parameters).
                                                 FirstOrDefault(e => e.Definition.Name.Equals(Globals.parm_to_Replace, StringComparison.CurrentCultureIgnoreCase));
                            //		TaskDialog.Show("Revit","Shared Parameter !!");
                            trans.Commit();
                            if (fp.IsShared)
                            {
                                //		TaskDialog.Show("Revit",fm.Types.Size.ToString());
                                //	Element e = FilteredElementCollector(doc).OfClass(fm.CurrentType);

                                //	Parameter p = fm.Parameter(fp.Definition);
//									if (fp == null) throw new Exception("Invalid ParameterName Input!");
//									string tmp = "Parameter name: "+ fp.Definition.Name + "\n" +"Is Shared!";

                                //TaskDialog.Show("Warrning",tmp);
                                ExternalDefinition edf;
                                //	if(!Globals.all_SP_variables.Contains(fp.Definition.Name))
                                edf = Create_SP(Globals.new_name_for_rename,
                                                Globals.new_type,
                                                Globals.new_group);

                                trans.Start();
                                fm.AddParameter(edf, edf.ParameterGroup, Globals.instance_or_not);
                                //	fm.Parameter(edf.Name).Set(fp.ToString());


                                FamilyParameter fp_tmp = fm.get_Parameter(Globals.new_name_for_rename);
                                foreach (FamilyType t in fm.Types)
                                {
                                    if (t.HasValue(fp))
                                    {
                                        //TaskDialog.Show("R","Here");
                                        fm.CurrentType = t;
                                        if (fp_tmp.StorageType == StorageType.Double)
                                        {
                                            fm.Set(fp_tmp, t.AsDouble(fp).Value);
                                        }
                                        else if (fp_tmp.StorageType == StorageType.Integer)
                                        {
                                            fm.Set(fp_tmp, t.AsInteger(fp).Value);
                                        }
                                        else if (fp_tmp.StorageType == StorageType.ElementId)
                                        {
                                            fm.Set(fp_tmp, t.AsElementId(fp).IntegerValue);
                                        }
                                        else if (fp_tmp.StorageType == StorageType.String)
                                        {
                                            fm.Set(fp_tmp, t.AsString(fp));
                                        }
                                    }
                                    // TaskDialog.Show("R",);
                                }
                                //fm.Types
                                trans.Commit();

                                trans.Start();
                                fm.RemoveParameter(fp);
                                trans.Commit();
                                //	string k = "Parameter name: "+ edf.Name + "\n" +"Is Shared!";

                                //	TaskDialog.Show("Warrning",k);

                                //	fm.AddParameter();
                                //		rename_in_shared_parm_file(fp.Definition.Name,Globals.new_name_for_rename);

                                //doc.Close(false);
                                continue;
                            }
//								if (fp == null) throw new Exception("Invalid ParameterName Input!");
//								fm.RenameParameter(fp,new_name);
                            //      Test();
                            trans.Commit();

                            //ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), "CompanyName");
//										FamilyManager fm = doc.FamilyManager;
//										FamilyParameter fp = RawConvertSetToList<FamilyParameter>(fm.Parameters).
//									        FirstOrDefault(e => e.Definition.Name.Equals(p_name, StringComparison.CurrentCultureIgnoreCase));
//									    if (fp == null) throw new Exception("Invalid ParameterName Input!");
//									    fm.RenameParameter(fp,new_name);
                            //                                      trans.Commit();
                            //		doc.SaveAs(filename);
                            doc.Close(true);
                        }
                    }
                }
                catch (Autodesk.Revit.Exceptions.ArgumentNullException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    //trans.Commit();
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FamilyContextException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FileAccessException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FileNotFoundException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.ApplicationException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (SystemException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //		return;
                }
            }

            //TaskDialog.Show("Iam","Here");
        }
Ejemplo n.º 30
0
        public void RawSetFamilyParameterValue(FamilyManager fm, FamilyType ft, FamilyParameter fp, object value)
        {
            FamilyType curFamType = fm.CurrentType;

            fm.CurrentType = ft;

            try
            {
                switch (fp.StorageType)
                {
                case StorageType.None:
                    break;

                case StorageType.Double:
                    if (value.GetType().Equals(typeof(string)))
                    {
                        fm.Set(fp, double.Parse(value as string));
                    }
                    else
                    {
                        fm.Set(fp, Convert.ToDouble(value));
                    }
                    break;

                case StorageType.Integer:
                    if (value.GetType().Equals(typeof(string)))
                    {
                        fm.Set(fp, int.Parse(value as string));
                    }
                    else
                    {
                        fm.Set(fp, Convert.ToInt32(value));
                    }
                    break;

                case StorageType.ElementId:
                    if (value.GetType().Equals(typeof(ElementId)))
                    {
                        fm.Set(fp, value as ElementId);
                    }
                    else if (value.GetType().Equals(typeof(string)))
                    {
                        fm.Set(fp, new ElementId(int.Parse(value as string)));
                    }
                    else
                    {
                        fm.Set(fp, new ElementId(Convert.ToInt32(value)));
                    }
                    break;

                case StorageType.String:
                    fm.Set(fp, value.ToString());
                    break;
                }
            }
            catch
            {
                throw new Exception("Invalid Value Input!");
            }
            finally
            {
                fm.CurrentType = curFamType;
            }
        }