zoukankan      html  css  js  c++  java
  • Parameter of Revit API – 19: Add FamilyParameter (FamilyManager.AddParameter)

     

    New family parameters (FamilyParameter) can be added to a family document through the FamilyManager.AddParameter() method. It has three different signatures and the most popular one accepts parameters of the parameter name, parameter group (BuiltInParameterGroup), parameter type ParameterType ()  and a flag to indicate if the FamilyParameter applies to instance or type.

    The FamilyParameter can also be associated with a Dimension through its Label property when necessary.

    The following method can create a FamilyParameter, set its value, and associate it with a Dimension:

    public static void RawAddFamilyParamterAndSetValue(Dimension dim, FamilyManager famMan, FamilyType ft,
                string name, BuiltInParameterGroup group, ParameterType type, bool isInstance, object value)
            {
                FamilyParameter fp = famMan.AddParameter(name, group, type, isInstance);
                if( value!= null ) RawSetFamilyParameterValue(famMan, ft, fp, value);
                //if (value != null) fp.SetValue(famMan, ft, value);
                if( dim != null )   dim.Label = fp;
            }
    
            public static 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;
                }
            }

    The help method RawSetFamilyParameterValue() has been introduced before. The FamilyParameter Writer can generate it in no time. If necessary the extension method can be generated as well and be used in the method RawAddFamilyParamterAndSetValue() instead.

    FamilyParameter Creator of RevitAddinWizard can take care of all these.

  • 相关阅读:
    【QT】error: 'connect'/'sender' was not declared in this scope
    【QT】添加图片资源并使用QImage加载图片显示
    【QT】去掉.ui窗口的最大化、最小化和关闭按钮
    【Linux】(一)美化Linux终端之oh-my-zsh开源项目(Linux终端主题)
    【git】配置git命令行别名
    浅谈函数防抖与函数节流
    php连接数据库的天龙八部!
    JavaScript画圆
    表格的即时编辑
    用html+css+js模拟下拉菜单
  • 原文地址:https://www.cnblogs.com/xpvincent/p/4176832.html
Copyright © 2011-2022 走看看