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. linux more AND less

    ================================more================================ more 是我们最常用的工具之一,最常用的就是显示输出的内容, ...

  2. 【转】字符集和字符编码(Charset & Encoding)

    相信大家一定碰到过,打开某个网页,却显示一堆像乱码,如"бЇЯАзЪСЯ"."�????????"?还记得HTTP中的Accept-Charset.Accept ...

  3. [译] 用 Swift 创建自定义的键盘

    本文翻译自 How to make a custom keyboard in iOS 8 using Swift 我将讲解一些关于键盘扩展的基本知识,然后使用iOS 8 提供的新应用扩展API来创建一 ...

  4. AngularJS 服务(Service)

    AngularJS 中你可以创建自己的服务,或使用内建服务. 什么是服务? 在 AngularJS 中,服务是一个函数或对象,可在你的 AngularJS 应用中使用. AngularJS 内建了30 ...

  5. profiler加入计划任务

    创建profiler的存储过程: USE [xxxDB] GO /****** Object: StoredProcedure [dbo].[CreateProfile] Script Date: 2 ...

  6. ListView介绍

    原文:http://blog.csdn.net/qingye_love/article/details/13772391?utm_source=tuicool&utm_medium=refer ...

  7. K-MEANS算法总结

    K-MEANS算法 摘要:在数据挖掘中,K-Means算法是一种 cluster analysis 的算法,其主要是来计算数据聚集的算法,主要通过不断地取离种子点最近均值的算法. 在数据挖掘中,K-M ...

  8. foreach与Iterable学习

    以前对于foreach的使用都是自然而然的感觉,没有深究过为什么可以用,什么时候可以用.最近才发现,原来那些可以使用的类,都是实现了Iterable接口的,否则根本就不能用. 下面是我之前学习时候写的 ...

  9. C# 遍历指定目录下的所有文件及文件夹

    // DirectoryInfo di = new DirectoryInfo(@"D:\Test"); // FindFile(di); static void FindFile ...

  10. emc 郵件設置

    1. 進入Data Domain管理界面后,在Administration--->Settings界面.點擊More mail Server--->Set Mail Server---&g ...