Creation Methods
Revit 作为一个以构件 Element
为基础的软件,它的大多数构件都是有创建方法的,大致有两种类型,一种是构件对应的 Element 派生中有静态的 Create
方法。另外一种是通过 Autodesk.Revit.Creation.Document
和 Autodesk.Revit.Creation.FamilyItemFactory
这样的 utility
类来创建。除此之外,可能还有一些特殊的创建方式,比如楼梯。
类型的 Create 方法
使用这种方式的构件都列在下面,个人更倾向于这种创建构件的方法。只需要找到对应的构件的 Class
,则创建、修改的逻辑都可以在同一个地方找到,非常直观,减少了需要了解的信息量。
墙
墙是 Revit 的内建族,创建一堵墙的基本元素包含需要:
- 文档
Document
,即在哪个项目中创建墙 - 墙的几何形体定义,可以是墙轮廓
profile
,也可以是墙的基准线 baseline,一条curve
- 墙的类型
wallTypeId
,如果没有就是使用默认的 - 墙所在的标高
levelId
具体如下:
namespace Autodesk.Revit.DB
{
public class Wall : HostObject
{
// normal 定义墙的内外朝向,structural 表示墙是否为结构墙
public static Wall Create(Document document, IList<Curve> profile, ElementId wallTypeId, ElementId levelId, bool structural, XYZ normal);
public static Wall Create(Document document, IList<Curve> profile, ElementId wallTypeId, ElementId levelId, bool structural);
public static Wall Create(Document document, IList<Curve> profile, bool structural);
// height 是墙的高度,它会重写墙的默认高度,offset 为墙的底部偏移,flip 表示墙的是否要给墙反向
public static Wall Create(Document document, Curve curve, ElementId wallTypeId, ElementId levelId, double height, double offset, bool flip, bool structural);
public static Wall Create(Document document, Curve curve, ElementId levelId, bool structural);
}
}
轴网 Grid
namespace Autodesk.Revit.DB
{
public class Grid : DatumPlane
{
public static Grid Create(Document document, Arc arc);
public static Grid Create(Document document, Line line);
}
}
标高 Level
namespace Autodesk.Revit.DB
{
public class Level : DatumPlane
{
public static Level Create(Document document, double elevation);
}
}
扶手 Railing
namespace Autodesk.Revit.DB.Architecture
{
public class Railing : Element
{
// Creates new railings with the specified railing type on all sides of a stairs
// instance in a Autodesk.Revit.DB.Architecture.MultistoryStairs element.
public static ISet<ElementId> Create(Document document, ElementId multistoryStairsId, ElementId levelId, ElementId railingTypeId, RailingPlacementPosition placePosition);
// Automatically creates new railings with the specified railing type on all sides
// of a stairs or ramp element.
public static ICollection<ElementId> Create(Document document, ElementId stairsOrRampId, ElementId railingTypeId, RailingPlacementPosition placePosition);
// Creates a new railing by specifying the railing path in the project document.
public static Railing Create(Document document, CurveLoop curveLoop, ElementId railingTypeId, ElementId baseLevelId);
}
}
楼梯
楼梯的创建比较复杂,包含梯段和平台,且需要打包。
梯段 StairsRun
梯段的类型:草图绘制的梯段(带坡度和不带坡度)、直梯段、螺旋梯段。
namespace Autodesk.Revit.DB.Architecture
{
public class StairsRun : Element
{
// Creates a sketched run in the project document by providing a group of boundary
// curves and riser curves.
public static StairsRun CreateSketchedRun(Document document, ElementId stairsId, double baseElevation, IList<Curve> boundaryCurves, IList<Curve> riserCurves, IList<Curve> stairsPath);
// Creates a sketched run in the project document by providing a group of boundary
// curves and riser curves, specifying slope type and height for boundary curves.
public static StairsRun CreateSketchedRunWithSlopeData(Document document, ElementId stairsId, double baseElevation, IList<SketchedStairsCurveData> boundaryCurves, IList<Curve> riserCurves, IList<Curve> stairsPath);
// Creates a spiral run in the project document by providing the center, start angle
// and included angle.
public static StairsRun CreateSpiralRun(Document document, ElementId stairsId, XYZ center, double radius, double startAngle, double includedAngle, bool clockwise, StairsRunJustification justification);
// Creates a straight run in the project document.
public static StairsRun CreateStraightRun(Document document, ElementId stairsId, Line locationPath, StairsRunJustification justification);
}
}
平台 StairsLanding
平台的类型:自动创建的平台和草图平台(带坡度和不带坡度的)。
namespace Autodesk.Revit.DB.Architecture
{
public class StairsLanding : Element
{
// Creates automatic landing(s) between two stairs runs.
public static IList<ElementId> CreateAutomaticLanding(Document document, ElementId firstRunId, ElementId secondRunId);
// Creates a customized landing between two runs by providing the closed boundary
// curves of the landing.
public static StairsLanding CreateSketchedLanding(Document document, ElementId stairsId, CurveLoop curveLoop, double baseElevation);
// Creates a customized landing between two runs by providing the closed boundary
// curves of the landing, specifying slope type and height.
public static StairsLanding CreateSketchedLandingWithSlopeData(Document document, ElementId stairsId, IList<SketchedStairsCurveData> curveLoop, double baseElevation);
}
}
楼梯的打包器 StairsEditScope
楼梯是一个复合的构件,它的内部还有梯段和平台,因此,它的创建被放在了一个编辑模式里面。
namespace Autodesk.Revit.DB
{
public class StairsEditScope : EditScope
{
// 开始一个楼梯编辑过程。
public StairsEditScope(Document document, string transactionName);
// 开始编辑一个现有的楼梯构件。
public ElementId Start(ElementId stairsId);
// 创建新的楼梯构件。
public ElementId Start(ElementId baseLevelId, ElementId topLevelId);
}
}
编辑模式的案例:
// 创建一个新的楼梯
private ElementId CreateStairs(Document document, Level levelBottom, Level levelTop)
{
ElementId newStairsId = null;
using (StairsEditScope newStairsScope = new StairsEditScope(document, "New Stairs"))
{
newStairsId = newStairsScope.Start(levelBottom.Id, levelTop.Id);
using (Transaction stairsTrans = new Transaction(document, "Add Runs and Landings to Stairs"))
{
stairsTrans.Start();
// 为楼梯创建一个草图梯段
IList<Curve> bdryCurves = new List<Curve>();
IList<Curve> riserCurves = new List<Curve>();
IList<Curve> pathCurves = new List<Curve>();
XYZ pnt1 = new XYZ(0, 0, 0);
XYZ pnt2 = new XYZ(15, 0, 0);
XYZ pnt3 = new XYZ(0, 10, 0);
XYZ pnt4 = new XYZ(15, 10, 0);
// 边界
bdryCurves.Add(Line.CreateBound(pnt1, pnt2));
bdryCurves.Add(Line.CreateBound(pnt3, pnt4));
// 踏步的线
const int riserNum = 20;
for (int ii = 0; ii <= riserNum; ii++)
{
XYZ end0 = (pnt1 + pnt2) * ii / (double)riserNum;
XYZ end1 = (pnt3 + pnt4) * ii / (double)riserNum;
XYZ end2 = new XYZ(end1.X, 10, 0);
riserCurves.Add(Line.CreateBound(end0, end2));
}
//楼梯的路径
XYZ pathEnd0 = (pnt1 + pnt3) / 2.0;
XYZ pathEnd1 = (pnt2 + pnt4) / 2.0;
pathCurves.Add(Line.CreateBound(pathEnd0, pathEnd1));
// 创建一个草图梯段
StairsRun newRun1 = StairsRun.CreateSketchedRun(document, newStairsId, levelBottom.Elevation, bdryCurves, riserCurves, pathCurves);
// 创建一个直跑梯段
Line locationLine = Line.CreateBound(new XYZ(20, -5, newRun1.TopElevation), new XYZ(35, -5, newRun1.TopElevation));
StairsRun newRun2 = StairsRun.CreateStraightRun(document, newStairsId, locationLine, StairsRunJustification.Center);
newRun2.ActualRunWidth = 10;
// 在两个梯段之间加一个草图平台
CurveLoop landingLoop = new CurveLoop();
XYZ p1 = new XYZ(15, 10, 0);
XYZ p2 = new XYZ(20, 10, 0);
XYZ p3 = new XYZ(20, -10, 0);
XYZ p4 = new XYZ(15, -10, 0);
Line curve_1 = Line.CreateBound(p1, p2);
Line curve_2 = Line.CreateBound(p2, p3);
Line curve_3 = Line.CreateBound(p3, p4);
Line curve_4 = Line.CreateBound(p4, p1);
landingLoop.Append(curve_1);
landingLoop.Append(curve_2);
landingLoop.Append(curve_3);
landingLoop.Append(curve_4);
StairsLanding newLanding = StairsLanding.CreateSketchedLanding(document, newStairsId, landingLoop, newRun1.TopElevation);
stairsTrans.Commit();
}
// 定义错误处理方式
newStairsScope.Commit(new StairsFailurePreprocessor());
}
return newStairsId;
}
其它有 Create 类型的构件
包含以下构件:
桁架 - Truss.Create
梁系统 - BeamSystem.Create
结构基础 - WallFoundation.Create
钢筋 - Rebar.CreateFreeForm
Rebar.CreateFromCurves
Rebar.CreateFromCurvesAndShape
Rebar.CreateFromRebarShape
结构区域钢筋 - AreaReinforcement.Create
结构路径钢筋 - PathReinforcement.Create
钢筋网区域 - FabricArea.Create
钢筋网片 - FabricSheet.Create
钢筋接头 - RebarCoupler.Create
部件 - AssemblyInstance.Create
以及其它水暖电专业的全部非 FamilyInstance
类型构件。
Utility Class For Creation
Autodesk.Revit.Creation.Document
和 Autodesk.Revit.Creation.FamilyItemFactory
都继承自 Autodesk.Revit.Creation.ItemFactoryBase
。这里比较奇怪的是Autodesk.Revit.Creation.FamilyItemFactory
有同时适用于族文档和项目文档的方法,这些方法理论上可以放到父类里面去。
大部分类型构件的创建方法都在这里,包括:
- 楼板 -
Floor
- 柱、梁、竖梃 -
FamilyInstance
- 屋顶 -
Roof
- 幕墙系统 -
CurtainSystem
- 模型文字 -
ModelText
- 房间 -
Room
- 面积 -
Area
- 洞口 -
Opening
- 参考平面 -
ReferencePlane
10.组 -Group
仅列出建筑专业,其它专业可自行查找。
namespace Autodesk.Revit.Creation
{
public class ItemFactoryBase : APIObject
{
public Dimension NewAlignment(View view, Reference reference1, Reference reference2);
public DetailCurve NewDetailCurve(View view, Curve geometryCurve);
public DetailCurveArray NewDetailCurveArray(View view, CurveArray geometryCurveArray);
public Dimension NewDimension(View view, Line line, ReferenceArray references, DB.DimensionType dimensionType);
public Dimension NewDimension(View view, Line line, ReferenceArray references);
public FamilyInstance NewFamilyInstance(DB.XYZ location, DB.FamilySymbol symbol, DB.XYZ referenceDirection, DB.Element host, StructuralType structuralType);
public FamilyInstance NewFamilyInstance(Face face, DB.XYZ location, DB.XYZ referenceDirection, DB.FamilySymbol symbol);
public FamilyInstance NewFamilyInstance(Face face, Line position, DB.FamilySymbol symbol);
public FamilyInstance NewFamilyInstance(DB.XYZ location, DB.FamilySymbol symbol, DB.Element host, StructuralType structuralType);
public FamilyInstance NewFamilyInstance(Reference reference, Line position, DB.FamilySymbol symbol);
public FamilyInstance NewFamilyInstance(DB.XYZ origin, DB.FamilySymbol symbol, View specView);
public FamilyInstance NewFamilyInstance(Line line, DB.FamilySymbol symbol, View specView);
public FamilyInstance NewFamilyInstance(Reference reference, DB.XYZ location, DB.XYZ referenceDirection, DB.FamilySymbol symbol);
public FamilyInstance NewFamilyInstance(DB.XYZ location, DB.FamilySymbol symbol, StructuralType structuralType);
public ICollection<DB.ElementId> NewFamilyInstances2(List<FamilyInstanceCreationData> dataList);
public Group NewGroup(ICollection<DB.ElementId> elementIds);
public ModelCurve NewModelCurve(Curve geometryCurve, SketchPlane sketchPlane);
public ModelCurveArray NewModelCurveArray(CurveArray geometryCurveArray, SketchPlane sketchPlane);
public ReferencePlane NewReferencePlane(DB.XYZ bubbleEnd, DB.XYZ freeEnd, DB.XYZ cutVec, View pView);
public ReferencePlane NewReferencePlane2(DB.XYZ bubbleEnd, DB.XYZ freeEnd, DB.XYZ thirdPnt, View pView);
public Group PlaceGroup(DB.XYZ location, GroupType groupType);
}
public class FamilyItemFactory : ItemFactoryBase
{
// 适用项目文档和族文档
public Dimension NewAngularDimension(View view, Arc arc, Reference firstRef, Reference secondRef);
public Dimension NewAngularDimension(View view, Arc arc, Reference firstRef, Reference secondRef, DB.DimensionType dimensionType);
public Dimension NewArcLengthDimension(View view, Arc arc, Reference arcRef, Reference firstRef, Reference secondRef);
public Dimension NewArcLengthDimension(View view, Arc arc, Reference arcRef, Reference firstRef, Reference secondRef, DB.DimensionType dimensionType);
public Dimension NewDiameterDimension(View view, Reference arcRef, DB.XYZ origin);
public Dimension NewLinearDimension(View view, Line line, ReferenceArray references);
public Dimension NewLinearDimension(View view, Line line, ReferenceArray references, DB.DimensionType dimensionType);
public Opening NewOpening(DB.Element host, CurveArray profile);
public Dimension NewRadialDimension(View view, Reference arcRef, DB.XYZ origin);
public Dimension NewRadialDimension(View view, Reference arcRef, DB.XYZ origin, DB.DimensionType dimensionType);
// 仅适用于族文档
public Blend NewBlend(bool isSolid, CurveArray topProfile, CurveArray baseProfile, SketchPlane sketchPlane);
public Control NewControl(ControlShape controlShape, View view, DB.XYZ origin);
public CurveByPoints NewCurveByPoints(ReferencePointArray points);
public Extrusion NewExtrusion(bool isSolid, CurveArrArray profile, SketchPlane sketchPlane, double end);
public Form NewExtrusionForm(bool isSolid, ReferenceArray profile, DB.XYZ direction);
public Form NewFormByCap(bool isSolid, ReferenceArray profile);
public Form NewFormByThickenSingleSurface(bool isSolid, Form singleSurfaceForm, DB.XYZ thickenDir);
public Form NewLoftForm(bool isSolid, ReferenceArrayArray profiles);
public ModelText NewModelText(string text, ModelTextType modelTextType, SketchPlane sketchPlane, DB.XYZ position, HorizontalAlign horizontalAlign, double depth);
public ReferencePoint NewReferencePoint(DB.XYZ A_0);
public ReferencePoint NewReferencePoint(PointElementReference A_0);
public ReferencePoint NewReferencePoint(Transform A_0);
public Revolution NewRevolution(bool isSolid, CurveArrArray profile, SketchPlane sketchPlane, Line axis, double startAngle, double endAngle);
public FormArray NewRevolveForms(bool isSolid, ReferenceArray profile, Reference axis, double startAngle, double endAngle);
public Sweep NewSweep(bool isSolid, ReferenceArray path, SweepProfile profile, int profileLocationCurveIndex, ProfilePlaneLocation profilePlaneLocation);
public Sweep NewSweep(bool isSolid, CurveArray path, SketchPlane pathPlane, SweepProfile profile, int profileLocationCurveIndex, ProfilePlaneLocation profilePlaneLocation);
public SweptBlend NewSweptBlend(bool isSolid, Reference path, SweepProfile bottomProfile, SweepProfile topProfile);
public SweptBlend NewSweptBlend(bool isSolid, Curve path, SketchPlane pathPlane, SweepProfile bottomProfile, SweepProfile topProfile);
public Form NewSweptBlendForm(bool isSolid, ReferenceArray path, ReferenceArrayArray profiles);
public SymbolicCurve NewSymbolicCurve(Curve curve, SketchPlane sketchPlane);
}
public class Document : ItemFactoryBase
{
public Area NewArea(ViewPlan areaView, DB.UV point);
public BoundaryConditions NewAreaBoundaryConditions(Reference reference, TranslationRotationValue X_Translation, double X_TranslationSpringModulus, TranslationRotationValue Y_Translation, double Y_TranslationSpringModulus, TranslationRotationValue Z_Translation, double Z_TranslationSpringModulus);
public BoundaryConditions NewAreaBoundaryConditions(DB.Element hostElement, TranslationRotationValue X_Translation, double X_TranslationSpringModulus, TranslationRotationValue Y_Translation, double Y_TranslationSpringModulus, TranslationRotationValue Z_Translation, double Z_TranslationSpringModulus);
public ModelCurve NewAreaBoundaryLine(SketchPlane sketchPlane, Curve geometryCurve, ViewPlan areaView);
public ElementSet NewAreas(List<AreaCreationData> dataList);
public AreaTag NewAreaTag(ViewPlan areaView, Area room, DB.UV point);
public FamilyInstance NewCrossFitting(Connector connector1, Connector connector2, Connector connector3, Connector connector4);
public CurtainSystem NewCurtainSystem(FaceArray faces, CurtainSystemType curtainSystemType);
public ICollection<DB.ElementId> NewCurtainSystem2(ReferenceArray faces, CurtainSystemType curtainSystemType);
public FamilyInstance NewElbowFitting(Connector connector1, Connector connector2);
public ExtrusionRoof NewExtrusionRoof(CurveArray profile, ReferencePlane refPlane, Level level, RoofType roofType, double extrusionStart, double extrusionEnd);
public FamilyInstance NewFamilyInstance(DB.XYZ location, DB.FamilySymbol symbol, DB.Element host, Level level, StructuralType structuralType);
public FamilyInstance NewFamilyInstance(DB.XYZ location, DB.FamilySymbol symbol, Level level, StructuralType structuralType);
public FamilyInstance NewFamilyInstance(Curve curve, DB.FamilySymbol symbol, Level level, StructuralType structuralType);
public Fascia NewFascia(FasciaType FasciaType, Reference reference);
public Fascia NewFascia(FasciaType FasciaType, ReferenceArray references);
public FlexDuct NewFlexDuct(Connector connector1, Connector connector2, FlexDuctType ductType);
public FlexDuct NewFlexDuct(Connector connector, IList<DB.XYZ> points, FlexDuctType ductType);
public FlexDuct NewFlexDuct(IList<DB.XYZ> points, FlexDuctType ductType);
public FlexPipe NewFlexPipe(IList<DB.XYZ> points, FlexPipeType pipeType);
public FlexPipe NewFlexPipe(Connector connector1, Connector connector2, FlexPipeType pipeType);
public FlexPipe NewFlexPipe(Connector connector, IList<DB.XYZ> points, FlexPipeType pipeType);
public Floor NewFloor(CurveArray profile, bool structural);
public Floor NewFloor(CurveArray profile, FloorType floorType, Level level, bool structural);
public Floor NewFloor(CurveArray profile, FloorType floorType, Level level, bool structural, DB.XYZ normal);
public FootPrintRoof NewFootPrintRoof(CurveArray footPrint, Level level, RoofType roofType, out ModelCurveArray footPrintToModelCurvesMapping);
public Floor NewFoundationSlab(CurveArray profile, FloorType floorType, Level level, bool structural, DB.XYZ normal);
public Gutter NewGutter(GutterType GutterType, ReferenceArray references);
public Gutter NewGutter(GutterType GutterType, Reference reference);
public BoundaryConditions NewLineBoundaryConditions(DB.Element hostElement, TranslationRotationValue X_Translation, double X_TranslationSpringModulus, TranslationRotationValue Y_Translation, double Y_TranslationSpringModulus, TranslationRotationValue Z_Translation, double Z_TranslationSpringModulus, TranslationRotationValue X_Rotation, double X_RotationSpringModulus);
public BoundaryConditions NewLineBoundaryConditions(Reference reference, TranslationRotationValue X_Translation, double X_TranslationSpringModulus, TranslationRotationValue Y_Translation, double Y_TranslationSpringModulus, TranslationRotationValue Z_Translation, double Z_TranslationSpringModulus, TranslationRotationValue X_Rotation, double X_RotationSpringModulus);
public MechanicalSystem NewMechanicalSystem(Connector baseEquipmentConnector, ConnectorSet connectors, DuctSystemType ductSystemType);
public Opening NewOpening(DB.Element famInstElement, CurveArray profile, eRefFace iFace);
public Opening NewOpening(Level bottomLevel, Level topLevel, CurveArray profile);
public Opening NewOpening(DB.Element hostElement, CurveArray profile, bool bPerpendicularFace);
public Opening NewOpening(Wall wall, DB.XYZ pntStart, DB.XYZ pntEnd);
public PipingSystem NewPipingSystem(Connector baseEquipmentConnector, ConnectorSet connectors, PipeSystemType pipingSystemType);
public BoundaryConditions NewPointBoundaryConditions(Reference reference, TranslationRotationValue X_Translation, double X_TranslationSpringModulus, TranslationRotationValue Y_Translation, double Y_TranslationSpringModulus, TranslationRotationValue Z_Translation, double Z_TranslationSpringModulus, TranslationRotationValue X_Rotation, double X_RotationSpringModulus, TranslationRotationValue Y_Rotation, double Y_RotationSpringModulus, TranslationRotationValue Z_Rotation, double Z_RotationSpringModulus);
public Room NewRoom(Room room, PlanCircuit circuit);
public Room NewRoom(Phase phase);
public Room NewRoom(Level level, DB.UV point);
public ModelCurveArray NewRoomBoundaryLines(SketchPlane sketchPlane, CurveArray curves, View view);
public ICollection<DB.ElementId> NewRooms2(Phase phase, int count);
public ICollection<DB.ElementId> NewRooms2(Level level);
public ICollection<DB.ElementId> NewRooms2(Level level, Phase phase);
public RoomTag NewRoomTag(LinkElementId roomId, DB.UV point, DB.ElementId viewId);
public Floor NewSlab(CurveArray profile, Level level, Line slopedArrow, double slope, bool isStructural);
public SlabEdge NewSlabEdge(SlabEdgeType SlabEdgeType, Reference reference);
public SlabEdge NewSlabEdge(SlabEdgeType SlabEdgeType, ReferenceArray references);
public Space NewSpace(Phase phase);
public Space NewSpace(Level level, DB.UV point);
public Space NewSpace(Level level, Phase phase, DB.UV point);
public ModelCurveArray NewSpaceBoundaryLines(SketchPlane sketchPlane, CurveArray curves, View view);
public ICollection<DB.ElementId> NewSpaces2(Level level, Phase phase, View view);
public ICollection<DB.ElementId> NewSpaces2(Phase phase, int count);
public SpaceTag NewSpaceTag(Space space, DB.UV point, View view);
public SpotDimension NewSpotCoordinate(View view, Reference reference, DB.XYZ origin, DB.XYZ bend, DB.XYZ end, DB.XYZ refPt, bool hasLeader);
public SpotDimension NewSpotElevation(View view, Reference reference, DB.XYZ origin, DB.XYZ bend, DB.XYZ end, DB.XYZ refPt, bool hasLeader);
public FamilyInstance NewTakeoffFitting(Connector connector, MEPCurve curve);
public FamilyInstance NewTeeFitting(Connector connector1, Connector connector2, Connector connector3);
public FamilyInstance NewTransitionFitting(Connector connector1, Connector connector2);
public FamilyInstance NewUnionFitting(Connector connector1, Connector connector2);
public Zone NewZone(Level level, Phase phase);
}
}
其它
零件 - PartUtils.CreateParts