创建新的管道类型,并且修改管道的弯头类型和T形连接弯头类型
2011-08-11 12:46
204 查看
这是一个典型的增加新类型(Duplicate()来实现),并且修改类型的参数值。这里一个特殊的情况是这里的两个参数值都是Revit的接头类型对象。实际上保存在这两个参数中的是ElementId类型的值,指向实际的两种接头类型。
在参数中如何修改参数存储类型是对象Id的值呢? 请看下面的代码。
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using Autodesk.Revit .DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[RegenerationAttribute(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class RevitCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document rvtDoc = app.ActiveUIDocument.Document;
PipeType pipeType = null;
List<Autodesk.Revit.DB.Element> ptypes = new List<Autodesk.Revit.DB.Element>();
FilteredElementCollector collector = new FilteredElementCollector(rvtDoc);
collector.OfCategory(BuiltInCategory.OST_PipeCurves);
collector.OfClass(typeof(ElementType));
ptypes.AddRange(collector.ToElements());
foreach (Element ptype in ptypes)
{
if (string.Compare(ptype.Name, "standard", true) == 0)
{
pipeType = ptype as PipeType;
break;
}
}
if (pipeType != null)
{
string name = "ADNNewType";
Transaction trans = new Transaction(rvtDoc, "ExComm");
trans.Start();
Autodesk.Revit.DB.ElementType newType = pipeType.Duplicate(name);
trans.Commit();
if (newType != null)
{
Transaction t = new Transaction(rvtDoc, "ExComm1");
t.Start();
ElementId id1 = FindFamilyType(rvtDoc, typeof(FamilySymbol), "Elbow - Threaded - MI - Class 150", "Standard", BuiltInCategory.OST_PipeFitting).Id;
ElementId id2 = FindFamilyType(rvtDoc, typeof(FamilySymbol), "Tee - Threaded - MI - Class 150", "Standard", BuiltInCategory.OST_PipeFitting).Id;
//change Elbow parameter value
newType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_ELBOW_PARAM).Set(id1);
//change Tee parameter value
newType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_TEE_PARAM).Set(id2);
//change "Preferred unction Type" parameter value
newType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_PREFERRED_BRANCH_PARAM).Set(0);
t.Commit();
}
}
return Result.Succeeded;
}
//====================================================================
// Helper Functions
//====================================================================
/// <summary>
/// Helper function: find an element of the given type, name, and category(optional)
/// You can use this, for example, to find a specific wall and window family with the given name.
/// e.g.,
/// FindFamilyType(_doc, GetType(WallType), "Basic Wall", "Generic - 200mm")
/// FindFamilyType(_doc, GetType(FamilySymbol), "M_Single-Flush", "0915 x 2134mm", BuiltInCategory.OST_Doors)
/// </summary>
public static Element FindFamilyType(Document rvtDoc, Type targetType,
string targetFamilyName, string targetTypeName, Nullable<BuiltInCategory> targetCategory)
{
// First, narrow down to the elements of the given type and category
var collector = new FilteredElementCollector(rvtDoc).OfClass(targetType);
if (targetCategory.HasValue)
{
collector.OfCategory(targetCategory.Value);
}
// Parse the collection for the given names
// Using LINQ query here.
var targetElems =
from element in collector
where element.Name.Equals(targetTypeName) &&
element.get_Parameter(BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM).
AsString().Equals(targetFamilyName)
select element;
// Put the result as a list of element fo accessibility.
IList<Element> elems = targetElems.ToList();
// Return the result.
if (elems.Count > 0)
{
return elems[0];
}
return null;
}
}
这篇文章与本博中的这个文章有些类似。不过这里修改的是参数值类型不一样,而且是针对管道类型。
在Revit中,如何编程创建新类型(如窗户或墙) http://blog.csdn.net/joexiongjin/article/details/6191299
在参数中如何修改参数存储类型是对象Id的值呢? 请看下面的代码。
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using Autodesk.Revit .DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[RegenerationAttribute(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class RevitCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
{
UIApplication app = commandData.Application;
Document rvtDoc = app.ActiveUIDocument.Document;
PipeType pipeType = null;
List<Autodesk.Revit.DB.Element> ptypes = new List<Autodesk.Revit.DB.Element>();
FilteredElementCollector collector = new FilteredElementCollector(rvtDoc);
collector.OfCategory(BuiltInCategory.OST_PipeCurves);
collector.OfClass(typeof(ElementType));
ptypes.AddRange(collector.ToElements());
foreach (Element ptype in ptypes)
{
if (string.Compare(ptype.Name, "standard", true) == 0)
{
pipeType = ptype as PipeType;
break;
}
}
if (pipeType != null)
{
string name = "ADNNewType";
Transaction trans = new Transaction(rvtDoc, "ExComm");
trans.Start();
Autodesk.Revit.DB.ElementType newType = pipeType.Duplicate(name);
trans.Commit();
if (newType != null)
{
Transaction t = new Transaction(rvtDoc, "ExComm1");
t.Start();
ElementId id1 = FindFamilyType(rvtDoc, typeof(FamilySymbol), "Elbow - Threaded - MI - Class 150", "Standard", BuiltInCategory.OST_PipeFitting).Id;
ElementId id2 = FindFamilyType(rvtDoc, typeof(FamilySymbol), "Tee - Threaded - MI - Class 150", "Standard", BuiltInCategory.OST_PipeFitting).Id;
//change Elbow parameter value
newType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_ELBOW_PARAM).Set(id1);
//change Tee parameter value
newType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_DEFAULT_TEE_PARAM).Set(id2);
//change "Preferred unction Type" parameter value
newType.get_Parameter(BuiltInParameter.RBS_CURVETYPE_PREFERRED_BRANCH_PARAM).Set(0);
t.Commit();
}
}
return Result.Succeeded;
}
//====================================================================
// Helper Functions
//====================================================================
/// <summary>
/// Helper function: find an element of the given type, name, and category(optional)
/// You can use this, for example, to find a specific wall and window family with the given name.
/// e.g.,
/// FindFamilyType(_doc, GetType(WallType), "Basic Wall", "Generic - 200mm")
/// FindFamilyType(_doc, GetType(FamilySymbol), "M_Single-Flush", "0915 x 2134mm", BuiltInCategory.OST_Doors)
/// </summary>
public static Element FindFamilyType(Document rvtDoc, Type targetType,
string targetFamilyName, string targetTypeName, Nullable<BuiltInCategory> targetCategory)
{
// First, narrow down to the elements of the given type and category
var collector = new FilteredElementCollector(rvtDoc).OfClass(targetType);
if (targetCategory.HasValue)
{
collector.OfCategory(targetCategory.Value);
}
// Parse the collection for the given names
// Using LINQ query here.
var targetElems =
from element in collector
where element.Name.Equals(targetTypeName) &&
element.get_Parameter(BuiltInParameter.SYMBOL_FAMILY_NAME_PARAM).
AsString().Equals(targetFamilyName)
select element;
// Put the result as a list of element fo accessibility.
IList<Element> elems = targetElems.ToList();
// Return the result.
if (elems.Count > 0)
{
return elems[0];
}
return null;
}
}
这篇文章与本博中的这个文章有些类似。不过这里修改的是参数值类型不一样,而且是针对管道类型。
在Revit中,如何编程创建新类型(如窗户或墙) http://blog.csdn.net/joexiongjin/article/details/6191299
相关文章推荐
- Revit2014 支持编程创建管道并且立即赋予系统类型名称
- 创建一个public static final 类型的map 并能赋初值,并且只能在初始化的时间赋值,而不能中途修改它的值
- 如果不空null并且不是空字符串才去修改这个值,但这样写只能针对字符串(String)类型,如果是Integer类型的话就会有问题了。 int i = 0; i!=''。 mybatis中会返回tr
- 创建/修改/调整/连接/分离/删除虚拟磁盘(二)
- sqlite数据类型、关键词及创建、修改、删除数据表
- 表管理(数据类型、创建/修改表、添加/修改/删除数据、数据查询) 1.Oracle表的管理
- sqlite数据类型、关键词及创建、修改、删除数据表
- CF MVC3此操作要求连接到 'master' 数据库。无法创建与 'master' 数据库之间的连接,这是因为已打开原始数据库连接,并且已从连接字符串中删除凭据。请提供未打开的连接 解决方法
- 【转】用JS创建json数据,并且可以动态往json数据里面添加新值,也可以修改值。
- sql server 2005 中数据库表 的创建 ,查看表 属性,表的名称重命名,情况表中信息,删除表 ; 表中列重命名,添加新列,修改列的数据类型,删除列,设置列的主键外键
- 【傻瓜式】QT5+sql server(ODBC)创建数据源并且连接数据库
- QT5+sql server(ODBC)创建数据源并且连接数据库
- 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL
- Oracle设置和修改system和scott的口令,并且如何连接到system和scott模式下
- 练习 2017-08-22 通过控制台,获取类名,字段名称,字段类型,根据一个模板文件,自动创建这个类文件,并且为字段提供setter和getter方法
- ArcEngine新建拓扑 Error creating topology:-2147220960 Message:应用程序未获得创建或修改此类型数据的方案的许可
- 一步步学习SPD2010--第七章节--使用BCS业务连接服务(3)--创建外部内容类型
- java使用http创建https连接,并且使用http实现webservice服务端
- 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL
- mysql导入导出数据中文乱码解决方法小结(1、navicat导入问题已解决,创建连接后修改连接属性,选择高级->将使用Mysql字符集复选框去掉,下拉框选择GBK->导入sql文件OK;2、phpmyadmin显示乱码的问题也解决,两步:1.将sql文件以utf8的字符集编码另存,2.将文件中sql语句中的字段字符集编码改成utf8,导入OK)