博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Revit Family API 添加类型
阅读量:6856 次
发布时间:2019-06-26

本文共 2569 字,大约阅读时间需要 8 分钟。

FamilyManager.NewType("");添加新类型,然后设置参数,就是为新类型设置参数。
[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public 
class cmdAddType : IExternalCommand
{
    
//
添加类型
    
void AddType(FamilyManager familyMgr, 
string name, 
double w, 
double d)
    {
        FamilyType type1 = familyMgr.NewType(name);
        FamilyParameter paramW = familyMgr.get_Parameter(
"
Width
");
        
double valW = Util.mmToFeet(w);
        
if (paramW != 
null)
        {
            familyMgr.Set(paramW, valW);
        }
        FamilyParameter paramD = familyMgr.get_Parameter(
"
Depth
");
        
double valD = Util.mmToFeet(d);
        
if (paramD != 
null)
        {
            familyMgr.Set(paramD, valD);
        }
    }
    
public Result Execute(ExternalCommandData commandData, 
ref 
string messages, ElementSet elements)
    {
        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;
        Transaction ts = 
new Transaction(doc, 
"
AddType
");
        ts.Start();
        
//
添加参数
        FamilyManager m_familyMgr = doc.FamilyManager;
        
//
添加类型Type
        AddType(m_familyMgr, 
"
600x900
"
600.0
900.0);
        AddType(m_familyMgr, 
"
600x600
"
600.0
600.0);
        ts.Commit();
        
return Result.Succeeded;
    }
}
public 
class Util
{
    
//
Revit内部单位feet转化为mm即毫米
    
public 
static 
double mmToFeet(
double val) { 
return val / 
304.8; }
    
public 
static 
double feetToMm(
double val) { 
return val * 
304.8; }
    
//
通过类型与名称找Element
    
public 
static Element findElement(Document _rvtDoc, Type targetType, 
string targetName)
    {
        
//
 get the elements of the given type
        
//
        FilteredElementCollector collector = 
new FilteredElementCollector(_rvtDoc);
        collector.WherePasses(
new ElementClassFilter(targetType));
        
//
 parse the collection for the given name
        
//
 using LINQ query here. 
        
//
 
        
var targetElems = 
from element 
in collector 
where element.Name.Equals(targetName) 
select element;
        List<Element> elems = targetElems.ToList<Element>();
        
if (elems.Count > 
0)
        {  
//
 we should have only one with the given name. 
            
return elems[
0];
        }
        
//
 cannot find it.
        
return 
null;
    }
    
#region Formatting and message handlers
    
public 
const 
string Caption = 
"
Revit Family API Labs
";
    
///
 
<summary>
    
///
 MessageBox wrapper for informational message.
    
///
 
</summary>
    
public 
static 
void InfoMsg(
string msg)
    {
        System.Diagnostics.Debug.WriteLine(msg);
        WinForm.MessageBox.Show(msg, Caption, WinForm.MessageBoxButtons.OK, WinForm.MessageBoxIcon.Information);
    }
    
///
 
<summary>
    
///
 MessageBox wrapper for error message.
    
///
 
</summary>
    
public 
static 
void ErrorMsg(
string msg)
    {
        WinForm.MessageBox.Show(msg, Caption, WinForm.MessageBoxButtons.OK, WinForm.MessageBoxIcon.Error);
    }
    
#endregion 
//
 Formatting and message handlers
}
from:

转载于:https://www.cnblogs.com/greatverve/p/revit-family-api-newtype.html

你可能感兴趣的文章
poj2128
查看>>
poj2369
查看>>
JavaScript数据类型检测
查看>>
JS-给对象动态添加属性
查看>>
Struts2 中 result type=”json” 的参数解释
查看>>
25.内置API
查看>>
3.Web项目中使用Log4j实例
查看>>
Codeforces 787 A The Monster 扩欧
查看>>
Python正则表达式之 - ?: / ?= / ?!
查看>>
Java接口中的成员变量的意义
查看>>
用nodejs访问ActiveX对象,以操作Access数据库为例。
查看>>
Silverlight 调用远程地址出错
查看>>
pip更新
查看>>
python之enumerate()函数用法
查看>>
22、学PHP女生多吗,女生可学吗?
查看>>
DotNetTextBox V3.0 所见即所得编辑器控件 For Asp.Net2.0(ver 3.0.7Beta) 增加多语言!
查看>>
spring- 4.2.4
查看>>
基本数据结构学习总结: 二叉树的基本操作
查看>>
迟到的第四周
查看>>
09-数据库的备份和恢复
查看>>