Revit二次开发之“预先设置系统族类型”
2011-08-12 08:08
253 查看
像Wall和Duct要预先修改WallType或DuctType,不能用上篇的方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using RevitApp = Autodesk.Revit.ApplicationServices;
namespace RevitCodes
{
public class Common
{
//毫米到英寸,单位换算
public static double mmToFeet(double val) { return val / 304.8; }
//通过族名称,族类型,从过滤器中找到指定的类型。
//WallType fs = Common.FindSystemFamilyType(uiDoc.Document, typeof(WallType), "CW 102-50-140p", BuiltInCategory.OST_Walls) as WallType;
public static Element FindSystemFamilyType(Document doc, Type targetType, string familyTypeName, BuiltInCategory catagory)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(targetType);
if (collector != null)
collector.OfCategory(catagory);
IList<Element> elements = collector.ToElements();
Element elem = null;
foreach (Element e in elements)
{
if (e.Name.Equals(familyTypeName))
{
elem = e;
break;
}
}
return elem;
}
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class SetWallType : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
Transaction tr = new Transaction(uiDoc.Document, "CreateWallWithDefType");
tr.Start();
string type = "CW 102-50-140p";//默认墙类型
double h = Common.mmToFeet(3000);//默认墙高
WallType fs = Common.FindSystemFamilyType(uiDoc.Document, typeof(WallType), type, BuiltInCategory.OST_Walls) as WallType;
XYZ pt1 = uiDoc.Selection.PickPoint("输入起点");
XYZ pt2 = uiDoc.Selection.PickPoint("输入终点");
XYZ first = new XYZ(pt1.X, pt1.Y, 0);
XYZ second = new XYZ(pt2.X, pt2.Y, 0);
XYZ third = new XYZ(pt2.X, pt2.Y, h);
XYZ fourth = new XYZ(pt1.X, pt1.Y, h);
CurveArray profile = new CurveArray();
profile.Append(uiDoc.Document.Application.Create.NewLineBound(first, second));
profile.Append(uiDoc.Document.Application.Create.NewLineBound(second, third));
profile.Append(uiDoc.Document.Application.Create.NewLineBound(third, fourth));
profile.Append(uiDoc.Document.Application.Create.NewLineBound(fourth, first));
Wall wall = uiDoc.Document.Create.NewWall(profile, fs, uiDoc.ActiveView.GenLevel, false);
Parameter para = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
tr.Commit();
return Result.Succeeded;
}
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class SetDuctType : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
Transaction tr = new Transaction(uiDoc.Document, "CreateDuctWithDefType");
tr.Start();
string type = "Taps";//风管类型
DuctType fs = Common.FindSystemFamilyType(uiDoc.Document, typeof(DuctType), type, BuiltInCategory.OST_DuctCurves) as DuctType;
XYZ pt1 = uiDoc.Selection.PickPoint("输入起点");
XYZ pt2 = uiDoc.Selection.PickPoint("输入终点");
uiDoc.Document.Create.NewDuct(pt1, pt2, fs);
tr.Commit();
return Result.Succeeded;
}
}
}from:http://revit.5d6d.com/thread-1023-1-4.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI.Selection;
using RevitApp = Autodesk.Revit.ApplicationServices;
namespace RevitCodes
{
public class Common
{
//毫米到英寸,单位换算
public static double mmToFeet(double val) { return val / 304.8; }
//通过族名称,族类型,从过滤器中找到指定的类型。
//WallType fs = Common.FindSystemFamilyType(uiDoc.Document, typeof(WallType), "CW 102-50-140p", BuiltInCategory.OST_Walls) as WallType;
public static Element FindSystemFamilyType(Document doc, Type targetType, string familyTypeName, BuiltInCategory catagory)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(targetType);
if (collector != null)
collector.OfCategory(catagory);
IList<Element> elements = collector.ToElements();
Element elem = null;
foreach (Element e in elements)
{
if (e.Name.Equals(familyTypeName))
{
elem = e;
break;
}
}
return elem;
}
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class SetWallType : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
Transaction tr = new Transaction(uiDoc.Document, "CreateWallWithDefType");
tr.Start();
string type = "CW 102-50-140p";//默认墙类型
double h = Common.mmToFeet(3000);//默认墙高
WallType fs = Common.FindSystemFamilyType(uiDoc.Document, typeof(WallType), type, BuiltInCategory.OST_Walls) as WallType;
XYZ pt1 = uiDoc.Selection.PickPoint("输入起点");
XYZ pt2 = uiDoc.Selection.PickPoint("输入终点");
XYZ first = new XYZ(pt1.X, pt1.Y, 0);
XYZ second = new XYZ(pt2.X, pt2.Y, 0);
XYZ third = new XYZ(pt2.X, pt2.Y, h);
XYZ fourth = new XYZ(pt1.X, pt1.Y, h);
CurveArray profile = new CurveArray();
profile.Append(uiDoc.Document.Application.Create.NewLineBound(first, second));
profile.Append(uiDoc.Document.Application.Create.NewLineBound(second, third));
profile.Append(uiDoc.Document.Application.Create.NewLineBound(third, fourth));
profile.Append(uiDoc.Document.Application.Create.NewLineBound(fourth, first));
Wall wall = uiDoc.Document.Create.NewWall(profile, fs, uiDoc.ActiveView.GenLevel, false);
Parameter para = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM);
tr.Commit();
return Result.Succeeded;
}
}
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class SetDuctType : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
Transaction tr = new Transaction(uiDoc.Document, "CreateDuctWithDefType");
tr.Start();
string type = "Taps";//风管类型
DuctType fs = Common.FindSystemFamilyType(uiDoc.Document, typeof(DuctType), type, BuiltInCategory.OST_DuctCurves) as DuctType;
XYZ pt1 = uiDoc.Selection.PickPoint("输入起点");
XYZ pt2 = uiDoc.Selection.PickPoint("输入终点");
uiDoc.Document.Create.NewDuct(pt1, pt2, fs);
tr.Commit();
return Result.Succeeded;
}
}
}from:http://revit.5d6d.com/thread-1023-1-4.html
相关文章推荐
- Revit二次开发之“先设置族类型再调用命令”
- &菜鸟收藏:熟知Word箭头样式类型设置&【系统收藏】
- Android开发 -- android设置系统状态栏颜色(沉浸式状态栏)
- android 获取系统中各种类型音量及对音量设置
- Android framework开发全局系统属性设置与获取
- android开发 打开系统设置信息页面
- 开发人员学Linux(2):VirtualBox中安装CentOS7系统设置
- android开发 打开系统设置信息页面
- 嵌入开发(WinCE) 用C#设置系统时间
- 嵌入式系统开发人员C语言测试题--填空题(数据类型和变量)
- 嵌入式系统开发人员C语言测试题(数据类型和变量)
- iOS开发-进阶:设置group类型tableview的section间距
- iOS开发 之字体类型的设置与选择
- iOS开发之如何跳到系统设置里的WiFi界面
- iOS开发之如何跳到系统设置里的WiFi界面
- android 开发-系统设置界面的实现