Files
06-Note/Revit-API/Document.md
sherlockforrest bf2ed2e31f 更新
2023-06-20 09:22:53 +08:00

657 lines
19 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## Document
### ActiveProjectLocation
- 获得项目的地址信息
- 继承与ProjectLocation
### ActiveView
- 获得激活视图
- View
### Application
- 获得应用对象
### Close()
- 关闭文件
### CombineElementsCombinewElementSet set
- 连接几何图元
### ConvertDetailToModelCurvesDetailCurveArray array
- 将细线转为模型线
### ConvertModelToDetailCurvesDetailCurveArray array
### SymbolicCurve
### Create
- 获得Create对象用于创建物体
- Create.Document
- Create(可用doc.GetdeFaultTypeId()获得Type
- Alignment
- 对齐尺寸
- NewArea(ViewPlan plan ,UV uv)
- 创建一个面积 必须在面积平面ViewPlan必须为面积平面 UV为面积的中心点且该中心点需要被闭合的边界线包围
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
ViewPlan view = doc.ActiveView as ViewPlan;
var create = doc.Create;
using (Transaction transaction = new Transaction(doc))
{
//通过创建四条面积边界线来形成一个正方形的闭合区域
transaction.Start("as");
var sketchPlane = view.SketchPlane;
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(20, 20, 0), new XYZ(40, 20, 0)), view);
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(40, 20, 0), new XYZ(40, 40, 0)), view);
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(40, 40, 0), new XYZ(20, 40, 0)), view);
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(20, 40, 0), new XYZ(20, 20, 0)), view);
create.NewArea(view, new UV(30, 30));
transaction.Commit();
}
- NewAreas(List<AreaCreationData〉dataList) 创建多个面积
- NewAreaBoundaryLine(SketchPlane sketchPlaneCurve geometryCurveViewPlan areaView)
-
该方法可创建一个闭合面取中点给Area创建
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
ViewPlan view = doc.ActiveView as ViewPlan;
var create = doc.Create;
using (Transaction transaction = new Transaction(doc))
{
//通过创建四条面积边界线来形成一个正方形的闭合区域
transaction.Start("as");
var sketchPlane = view.SketchPlane;
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(20, 20, 0), new XYZ(40, 20, 0)), view);
transaction.Commit();
}
- NewAreaTagViewPlan view,Area room,UV point
- 创建面积标签
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
ViewPlan view = doc.ActiveView as ViewPlan;
var create = doc.Create;
using (Transaction transaction = new Transaction(doc))
{
//通过创建四条面积边界线来形成一个正方形的闭合区域
transaction.Start("as");
var sketchPlane = view.SketchPlane;
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(20, 20, 0), new XYZ(40, 20, 0)), view);
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(40, 20, 0), new XYZ(40, 40, 0)), view);
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(40, 40, 0), new XYZ(20, 40, 0)), view);
create.NewAreaBoundaryLine(sketchPlane,
Line.CreateBound(new XYZ(20, 40, 0), new XYZ(20, 20, 0)), view);
Area area = create.NewArea(view, new UV(30, 30));
create.NewAreaTag(view, area, new UV(30, 30));
transaction.Commit();
}
- NewCrossFitting四个Connector
- 创建四通四个Connector必须以主管方向的两个Connector在前面
- NewCurtainSystemFaceArray array,CurtainSystemType
- 创建幕墙系统参数为面和系统的type
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
Reference r = sel.PickObject(ObjectType.Face);
Element element = doc.GetElement(r);
Face face = element.GetGeometryObjectFromReference(r) as Face;
CurtainSystemType type = doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.CurtainSystemType)) as CurtainSystemType;
FaceArray faceArray = new FaceArray();
faceArray.Append(face);
using (Transaction tr = new Transaction(doc))
{
tr.Start("Create Curtain System");
doc.Create.NewCurtainSystem(faceArray, type);
tr.Commit();
}
- NewDetailCurve(View view,Curve geometryCurve)
- 创建细线
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
using (Transaction tr = new Transaction(doc))
{
tr.Start("Create Detail Curve");
doc.Create.NewDetailCurve(doc.ActiveView,Line.CreateBound(new XYZ(0,0,0),new XYZ(10,0,0)));
tr.Commit();
}
- NewDimensionView view,Line line,ReferenceArray array,Type
- 创建尺寸标注line为标注的线可为射线参照数组为 线面的参照
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
Reference r1 = sel.PickObject(ObjectType.PointOnElement);
Reference r2 = sel.PickObject(ObjectType.PointOnElement);
ReferenceArray array = new ReferenceArray();
array.Append(r1);
array.Append(r2);
Element element = doc.GetElement(r1);
Line line = element.GetGeometryObjectFromReference(r1) as Line;
// 根据线的方向计算与之垂直的方向,新建一条线用于创建尺寸标注
double direc = Math.Acos(line.Direction.X) + Math.PI / 2;
Line l = Line.CreateUnbound(line.Origin, new XYZ(Math.Cos(direc), Math.Sin(direc), 0));
using (Transaction tr = new Transaction(doc))
{
tr.Start("Create Dimension");
doc.Create.NewDimension(doc.ActiveView, l, array);
tr.Commit();
}
- NewDuct两个Connector一个Type
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
using (Transaction tr = new Transaction(doc))
{
tr.Start("Create Duct");
DuctType type = doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.DuctType)) as DuctType;
doc.Create.NewDuct(new XYZ(0,0,0),new XYZ(20,0,0), type);
tr.Commit();
}
- NewElbowFitting(两个Connector)
- 创建弯头
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
using (Transaction tr = new Transaction(doc))
{
tr.Start("Create Duct");
DuctType type = doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.DuctType)) as DuctType;
Duct duct1 = doc.Create.NewDuct(new XYZ(0,0,0),new XYZ(20,0,0), type);
Duct duct2 = doc.Create.NewDuct(new XYZ(20, 20, 0), new XYZ(20, 0, 0), type);
Connector connector1 = GetConnector(duct1, new XYZ(20, 0, 0));
Connector connector2 = GetConnector(duct2, new XYZ(20, 0, 0));
doc.Create.NewElbowFitting(connector1, connector2);
tr.Commit();
}
=====================================================
private Connector GetConnector(Duct duct, XYZ xyz)
{
ConnectorSetIterator iterator = duct.ConnectorManager.Connectors.ForwardIterator();
Connector connector = null;
while (iterator.MoveNext())
{
Connector c = iterator.Current as Connector;
if (c.Origin.DistanceTo(xyz)>0.005) continue;
connector = c;
}
return connector;
}
- NewExtrusionRoof (CurveArray profile, ReferencePlane refPlane, Level level, RoofType roofType, double extrusionStart, double extrusionEnd);
- 拉伸屋顶(给定一组形状线,一个参照平面,***
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
var create = doc.Create;
CurveArray array = new CurveArray();
array.Append(Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 20, 20)));
array.Append(Line.CreateBound(new XYZ(0, 20, 20), new XYZ(0, 40, 0)));
Transaction tr = new Transaction(doc);
tr.Start("create roof");
ReferencePlane plane = create.NewReferencePlane(new XYZ(0, 0, 0), new XYZ(0, 20, 0), new XYZ(0, 0, 20),doc.ActiveView);
Level level = doc.ActiveView.GenLevel;
RoofType roofType = doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.RoofType)) as RoofType;
create.NewExtrusionRoof(array, plane, level, roofType, 0, 40);
tr.Commit();
- NewFamilyInstance(Curve curve,FamilySymbol symbol,Level level,StructuralType structuralType)
- curve为locationCurve
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
var create = doc.Create;
FilteredElementCollector col = new FilteredElementCollector(doc);
col.OfCategory(BuiltInCategory.OST_StructuralFraming);
FamilySymbol symbol = null;
foreach(Element e in col)
{
FamilySymbol familySymbol = e as FamilySymbol;
if (familySymbol == null) continue;
symbol = familySymbol;
break;
}
Transaction tr = new Transaction(doc);
tr.Start("create beam");
Curve curve = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(0, 20, 0));
Level level = doc.ActiveView.GenLevel;
create.NewFamilyInstance(curve, symbol, level, StructuralType.Beam);
tr.Commit();
- NewFasciaargs
- 挡泥板?
- NewFlexDuctargs
- 软风管
- NewFlexPipeargs
- 软管
- NewFloor(args)
- NewFootPrintRoof(args)
- 迹线屋顶
ModelCurveArray modelCurveArray = new ModelCurveArray();
FootPrintRoof roof =
RevitDoc.Create.NewFootPrintRoof(curveArray, level, roofType, out modelCurveArray);
//设置屋顶坡度
ModelCurve curve1 = modelCurveArray.get_Item(0);
ModelCurve curve3 = modelCurveArray.get_Item(2);
roof.set_DefinesSlope(curve1, true);
roof.set_SlopeAngle(curve1, 0.5);
roof.set_DefinesSlope(curve3, true);
roof.set_SlopeAngle(curve3, 1.6);
- curveArr为创建时的迹线Out为输出的模型线可根据模型线设置坡度
- NewFoundationSlabargs
- 基础板
- NewFoundationWallargs
- 基础墙
- NewGroupList<ElementId ids>
- 创建模型组
- NewGutterType,Reference r
- 根据参照面创建檐沟
- NewMechanicalSystemargs
- https://www.cnblogs.com/greatverve/archive/2011/07/18/revit-MechanicalSystem.html
- NewModelCurve(Curve geoCurve,SketchPlane plane)
- 创建模型线
- NewOpeningargs)
- 开洞口
- https://blog.csdn.net/ruiqi317/article/details/6939692
- NewReferencePlane3个XYZ一个View
- 为两点,和一个向量创建平面
- NewReferencePlane23个XYZ一个View
- 用3个点创建一个平面
- NewTakeoffFittingConnector,Curve
- 根据线和Connector创建两个T型风管链接
- NewTeeFitting3个Connector
- 创建三通前两个Connector必须为主管方向上
- NewTransitionFittingConnector,Connector
- 创建过度件
- NewUnionFitting两个Connector
- 创建管套
### DeleteElementId
- 根据ElementId删除Element
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
Reference r = sel.PickObject(ObjectType.Element);
Element element = doc.GetElement(r);
// 删除选择构件
using(Transaction tr = new Transaction(doc))
{
tr.Start("test");
doc.Delete(element.Id);
tr.Commit();
}
### DisplayUnitSystem
- 项目使用的单位制度
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
// 打印项目单位制度
TaskDialog.Show("as", doc.DisplayUnitSystem.ToString());
### DocumentColsing
### DocumentPrinted
### DocumentPrinting
### DocumentSave
### DocumentSaveAs
### DocumentSaving
### DocumentSaveAsing
### EditFamily(Family family)
- 获得族的Document,通过Document编辑族
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
Reference r = sel.PickObject(ObjectType.Element);
Element element = doc.GetElement(r);
FamilyInstance instance = element as FamilyInstance;
if (instance == null) return Result.Failed;
Family family = instance.Symbol.Family;
// 选择一个Element 如果是FamilyInstance则打开编辑文档打印文档的标题
Document famDoc = doc.EditFamily(family);
TaskDialog.Show("AS",famDoc.Title);
### Exportargs
- 根据地址和设置导出gbXML
### ExportImageImageExportOptions options
- 根据选项导出图片
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
string filePath = @"C:\Users\Administrator\Desktop\test.jpg";
ImageExportOptions imageExportOptions = new ImageExportOptions();
imageExportOptions.FilePath = filePath;
doc.ExportImage(imageExportOptions);
### FamilyCreate
- 获得FamilyItemFactory对象用于创建FamilyItem
### FamilyManager
- 用于管理Family对象和属性
### GetDefaultElementTypeIdElementiTypeGroup **
- 获得默认的ElementType
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
WallType type = doc.GetElement(doc.GetDefaultElementTypeId(ElementTypeGroup.WallType)) as WallType;
if (type == null) return Result.Failed;
using(Transaction tr = new Transaction(doc))
{
tr.Start("test");
type.Name = "哈哈哈";
tr.Commit();
}
### GetDocumentPreviewSettings()
- 获得预览设置对象,可强制视图更新
- DocumentPreviewSettings
### GetElement(ElementId id)
- 根据ID获得Element
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
Reference r = sel.PickObject(ObjectType.Element);
Element element = doc.GetElement(r);
// int id = 123456;
// Element e = doc.GetElement(new ElementId(id));
### GetPaintedMaterial(ElementId id ,Face face)
- 获得构件该面的材质的Id
- EelementId
### GetPrintSettingIds
- 获得打印设置列表
- ICollection<EelementId>
### GetRoomAtPointXYZ xyz
- 根据一个点获得包含这个点的房间
- Room
### GetSpaceAtPointXYZ xyz
- 根据一个点获得包含这个点的Space
- Space
### Units ()
- 获得设置格式
### GetWorksetIdElementId
- 获得该构件工作集的ElementId
### GetWorksetTable()
- 获得工作集列表
### GetWorksharingCentralModelPath
- 获得中心文件的路径
### get_PlanTopologies
### get_TypeOfStorage
- 获得属性储存用的数据类型
### Importargs
- 导入DGN文件 本特利的
### IsDetached
- 是否分离中心文件
### IsFamilyDocument
- 是否为族文件
### IsLinked
- 是否为链接文件
### IsPaintedElementId id,Face face)
- 判断该面是否有材质
### Linkstring fileName,Options
- 链接文件
### LoadFamilystring fileName
- 加载族
### LoadFamily(args)
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
string familyFilePath = @"C:\Users\Administrator\Desktop\1.rfa";
doc.LoadFamily(familyFilePath);
### MassDisplayTemporaryOverride
###
MullionTypes
竖艇
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
MullionTypeSetIterator iterator = doc.MullionTypes.ForwardIterator();
while (iterator.MoveNext())
{
MullionType type = iterator.Current as MullionType;
TaskDialog.Show("SA", type.Name);
}
### OwnerFamily
- 获得当前FamilyDocument的Family
### Paint(args)
- 给构件添加材质
### PanelTypes
- 获得所有的平面类型
### ParameterBindings
### Phases
- 获得所有Phase集合
### print(args)
- 打印
### PrintManager
- 打印管理对象
### ProjectInformation
- 项目信息
### RemovePaintargs
- 删除材质
### SaveToProjectAsImageOPTIONS
- 将当前视图保存为图片
### SeparateElements
- 分离所有链接图元
### SetDefaultElementTypeIdElementTypeGroup group,ElementId typeId
- 设置TypeGroup的默认类型
### SetDefaultFamilyTypeId
- 设置默认族类型
### Settings
- 获得Document的设置对象
- UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
Settings settings = doc.Settings;
Category category = settings.Categories.get_Item("墙");
TaskDialog.Show("as", category.Name);
### SiteLocation
### SynchronizeWithCentral
### Title
- 获得标题