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 RevitAddinWizardcan take care of all these.

Parameter of Revit API – 19: Add FamilyParameter (FamilyManager.AddParameter)的更多相关文章

  1. Revit API 操作共享参数和项目参数

    1.获取共享参数 private string GetSharInfo(Autodesk.Revit.ApplicationServices.Application revitApp) { Strin ...

  2. Revit API射线法读取空间中相交的元素

    Revit API提供根据射线来寻找经过的元素.方法是固定模式,没什么好说.关键代码:doc.FindReferencesWithContextByDirection(ptStart, (ptEnd  ...

  3. 【Revit API】梁构件支座检查算法

    一.前言         应该是第二次写关于Revit API的博文了.虽然在BIM企业中工作,从事桌面BIM软件开发,但是我是不怎么喜欢写Revit API相关的代码.平时更多的是在写界面展示,架构 ...

  4. Revit API 判断一个构件在某个视图中的可见性

    查看 Revit API.发现有Element::IsHidden这个方法.通过UI创建一个element,注意要使得这个element在某些视图可见,但是在另一些视图不可见.运行下面的方法,你会发现 ...

  5. minSdk(API 26) > deviceSdk(API 19)解决方式

    运行项目时出现“minSdk(API 26) > deviceSdk(API 19)”的提示,因为我用的是手机是sdk(API19)的,而项目要求是最低版本是minSdk(API 26),在我的 ...

  6. Revit API 加载族并生成实例图元

    在Revit API中加载族可以使用Doc.LoadFamily方法,传入要加载的族文件路径名,但是这种方式有一种缺点,就是如果族文件在当前工程中没有加载的话则返回成功,如果已经加载过,则返回失败,也 ...

  7. 安卓 API 19 低版本设置自带的圆圈效果

    在 Android API 19 环境下,RadioButton 消除或者自定义自带的圆圈效果的形式来设置: 自定义自身选择图标 android:button="@drawable/sele ...

  8. Revit API根据链接文件开洞

    开洞信息数据: ]);             ;                     ;                     ;                     ;          ...

  9. Revit api 创建族并加载到当前项目

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

随机推荐

  1. 在Eclipse中创建Maven多模块工程的例子

    .配置eclipse的maven .在Eclipse里面New -> Maven Project -> 选择“Create a simple project” Group Id: com. ...

  2. GTID复制之二

    在线启用GTID,这样就不会对生产造成影响. 1.在每个Server上,执行 SET @@GLOBAL.ENFORCE_GTID_CONSISTENCY=WARN;确保在ErrorLog中没有WARN ...

  3. 常用iOS的第三方框架

    图像:1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等 ...

  4. echarts基本使用

    基本操作: 1,准备好需要渲染chart图的div层 <div id="org-data-percent" class="org-data-percent" ...

  5. 使用HttpWebRequest发送自定义POST请求

    平时用浏览器看网页的时候,点击一下submit按钮的时候其实就是给服务器发送了一个POST请求.但是如何在自己的C#程序里面实现类似的功能呢?本文给出了一个简单的范例,可以实现类似的和web serv ...

  6. Ubuntu开机自启动

    http://www.jb51.net/os/Ubuntu/181138.html http://blog.csdn.net/elim051/article/details/6173367

  7. **PHP中替换换行符

    PHP中替换换行符 php 不同系统的换行不同系统之间换行的实现是不一样的linux 与unix中用 \nMAC 用 \rwindow 为了体现与linux不同 则是 \r\n所以在不同平台上 实现方 ...

  8. Linux 标准目录结构

    初学Linux,首先需要弄清Linux 标准目录结构 / root --- 启动Linux时使用的一些核心文件.如操作系统内核.引导程序Grub等. home --- 存储普通用户的个人文件 ftp ...

  9. 比较各大挪动门户网站淘宝、京东、网易、新浪、腾讯meta标签的异同

    首先先展示一下各个网站的有关meta标签的代码: 网易 <meta charset="UTF-8"> <meta content="width=devi ...

  10. 在Eclipse中自定义类似syso的快捷代码模板

    sysout/syso syserr/ syse 点击菜单栏的“Window”->“Preferences”,打开“Preferences”对话框.在Preferences”对话框中点击“Jav ...