Revit SDK 内容摘要: 2008.0 - 2009.0 部分

前提

不包含已单独写博客部分。

Revit SDK Samples

2008.0

APIAppStartup

添加启动页面。

csharp 复制代码
namespace APIAppStartup
{
   [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
   [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
   [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
   public class AppSample : IExternalApplication
   {
      #region IExternalApplication Members

      public Autodesk.Revit.UI.Result OnShutdown(UIControlledApplication application)
      {
         TaskDialog.Show("Revit", "Quit External Application!");
         return Autodesk.Revit.UI.Result.Succeeded;
      }

       public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
      {
         String version = application.ControlledApplication.VersionName;

         //display splash window for 10 seconds
         SplashWindow.StartSplash();
         SplashWindow.ShowVersion(version);
         System.Threading.Thread.Sleep(10000);
         SplashWindow.StopSplash();

         return Autodesk.Revit.UI.Result.Succeeded;
      }

      #endregion
   }
}

AutoTagRooms

csharp 复制代码
        /// <summary>
        /// Auto tag rooms with specified RoomTagType in a level
        /// </summary>
        /// <param name="level">The level where rooms will be auto tagged</param>
        /// <param name="tagType">The room tag type</param>
        public void AutoTagRooms(Level level, RoomTagType tagType)
        {
            PlanTopology planTopology = m_revit.ActiveUIDocument.Document.get_PlanTopology(level);

            SubTransaction subTransaction = new SubTransaction(m_revit.ActiveUIDocument.Document);
            subTransaction.Start();
            foreach (ElementId eid in planTopology.GetRoomIds())
            {
                Room tmpRoom = m_revit.ActiveUIDocument.Document.GetElement(eid) as Room;

                if (m_revit.ActiveUIDocument.Document.GetElement(tmpRoom.LevelId) != null && tmpRoom.Location != null)
                {
                    // Create a specified type RoomTag to tag a room
                    LocationPoint locationPoint = tmpRoom.Location as LocationPoint;
                    Autodesk.Revit.DB.UV point = new Autodesk.Revit.DB.UV(locationPoint.Point.X, locationPoint.Point.Y);
                    RoomTag newTag = m_revit.ActiveUIDocument.Document.Create.NewRoomTag(new LinkElementId(tmpRoom.Id), point, null);
                    newTag.RoomTagType = tagType;

                    List<RoomTag> tagListInTheRoom = m_roomWithTags[newTag.Room.Id.IntegerValue];
                    tagListInTheRoom.Add(newTag);
                }

            }
            subTransaction.Commit();
        }

CurvedBeam

// 传入的曲线可以是直线、圆弧、椭圆、nurbs曲线等
beam = m_revit.ActiveUIDocument.Document.Create.NewFamilyInstance(curve, fsBeam, level, StructuralType.Beam);

ImportExport

导入导出各种格式,略。

NewOpenings

NewPathReinforcement

csharp 复制代码
        public override PathReinforcement CreatePathReinforcement(List<Vector4> points, bool flip)
        {
            Autodesk.Revit.DB.XYZ p1, p2; Line curve;
            IList<Curve> curves = new List<Curve>();
            for (int i = 0; i < points.Count - 1; i++)
            {
                p1 = new Autodesk.Revit.DB.XYZ(points[i].X, points[i].Y, points[i].Z);
                p2 = new Autodesk.Revit.DB.XYZ(points[i + 1].X, points[i + 1].Y, points[i + 1].Z);
                curve = Line.CreateBound(p1, p2);
                curves.Add(curve);
            }
            ElementId pathReinforcementTypeId = PathReinforcementType.CreateDefaultPathReinforcementType(m_document);
            ElementId rebarBarTypeId = RebarBarType.CreateDefaultRebarBarType(m_document);
            ElementId rebarHookTypeId = RebarHookType.CreateDefaultRebarHookType(m_document);
            return PathReinforcement.Create(m_document, m_data, curves, flip, pathReinforcementTypeId, rebarBarTypeId, rebarHookTypeId, rebarHookTypeId);
        }

PathReinforcement

csharp 复制代码
namespace Autodesk.Revit.DB.Structure
{
    public class PathReinforcement : Element
    {
        public ReinforcementBarOrientation PrimaryBarOrientation { get; set; }
        public PathReinforcementType PathReinforcementType { get; }
        public double AdditionalOffset { get; set; }
        public ElementId PrimaryBarShapeId { get; set; }
        public ElementId AlternatingBarShapeId { get; set; }
        public ReinforcementBarOrientation AlternatingBarOrientation { get; set; }
        public static PathReinforcement Create(Document document, Element hostElement, IList<Curve> curveArray, bool flip, ElementId pathReinforcementTypeId, ElementId rebarBarTypeId, ElementId startRebarHookTypeId, ElementId endRebarHookTypeId, ElementId rebarShapeId);
        public static PathReinforcement Create(Document document, Element hostElement, IList<Curve> curveArray, bool flip, ElementId pathReinforcementTypeId, ElementId rebarBarTypeId, ElementId startRebarHookTypeId, ElementId endRebarHookTypeId);
        public static ElementId GetOrCreateDefaultRebarShape(Document document, ElementId rebarBarTypeId, ElementId startRebarHookTypeId, ElementId endRebarHookTypeId);
        public static bool IsValidRebarShapeId(Document aDoc, ElementId elementId);
        public IList<ElementId> GetRebarInSystemIds();
        public bool IsAlternatingLayerEnabled();
        public bool IsValidAlternatingBarOrientation(ReinforcementBarOrientation orientation);
        public bool IsValidPrimaryBarOrientation(ReinforcementBarOrientation orientation);
        public void SetSolidInView(View3D view, bool solid);
        public void SetUnobscuredInView(View view, bool unobscured);
    }
}

ProjectInfo

csharp 复制代码
namespace Autodesk.Revit.DB
{
    public class ProjectInfo : Element
    {
        public string OrganizationDescription { get; set; }
        public string OrganizationName { get; set; }
        public string BuildingName { get; set; }
        public string Author { get; set; }
        public string Number { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string ClientName { get; set; }
        public string Status { get; set; }
        public string IssueDate { get; set; }
    }
}

ShaftHolePuncher

创建各种类型洞口,均属于 Document

csharp 复制代码
// class Document
//     This method forms opening on a beam, brace and column.
public Opening NewOpening(DB.Element famInstElement, CurveArray profile, eRefFace iFace);
//     This method forms an opening on floor, ceiling and roof. Make sure topLevel is
//     higher than bottomLevel, otherwise an exception will be returned.
public Opening NewOpening(Level bottomLevel, Level topLevel, CurveArray profile);
//     Creates a new opening in a roof, floor and ceiling.
public Opening NewOpening(DB.Element hostElement, CurveArray profile, bool bPerpendicularFace);
//     Creates a rectangular opening on a wall.
public Opening NewOpening(Wall wall, DB.XYZ pntStart, DB.XYZ pntEnd);

SpotDimension

csharp 复制代码
public SpotDimension NewSpotElevation(View view, Reference reference, DB.XYZ origin, DB.XYZ bend, DB.XYZ end, DB.XYZ refPt, bool hasLeader);
namespace Autodesk.Revit.DB
{
    public class SpotDimension : Dimension
    {
        public SpotDimensionType SpotDimensionType { get; set; }
        public override Location Location { get; }
    }
}

TagBeam

csharp 复制代码
        public void CreateTag(TagMode tagMode,
            FamilySymbolWrapper tagSymbol, bool leader,
            TagOrientation tagOrientation)
        {
            foreach(FamilyInstance beam in m_beamList)
            {
                //Get the start point and end point of the selected beam.
                Autodesk.Revit.DB.LocationCurve location = beam.Location as Autodesk.Revit.DB.LocationCurve;
                Autodesk.Revit.DB.Curve curve = location.Curve;

                Transaction t = new Transaction(m_revitDoc.Document);
                t.Start("Create new tag");
                //Create tag on the beam's start and end.
                Reference beamRef = new Reference(beam);
                IndependentTag tag1 = IndependentTag.Create(m_revitDoc.Document,
                    m_view.Id, beamRef, leader, tagMode, tagOrientation, curve.GetEndPoint(0));
                IndependentTag tag2 = IndependentTag.Create(m_revitDoc.Document,
                    m_view.Id, beamRef, leader, tagMode, tagOrientation, curve.GetEndPoint(1));

                //Change the tag's object Type.
                tag1.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                tag2.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                t.Commit();
            }
        }

TestFloorThickness

VB 省略。

TestWallThickness

VB 省略。

TransactionControl

csharp 复制代码
Transaction
SubTransaction
TransactionGroup

ViewPrinter

视图与图纸打印,略。

VisibilityControl

csharp 复制代码
// class View
public void SetCategoryHidden(ElementId categoryId, bool hide);

2008.2

ModelLines

Line geometryLine = Line.CreateBound(startPoint, endPoint);
ModelLine line = m_createDoc.NewModelCurve(geometryLine, workPlane) as ModelLine;

RoomSchedule

// 创建房间
Room newRoom = m_document.Create.NewRoom(curPhase);

除了创建房间,还包括共享参数的操作以及导出数据。

2009.0

NewHostedSweep

Fascia - (屋顶的)封檐板

Gutter - (屋顶的)檐槽

Slab Edge - 天板边缘

csharp 复制代码
Fascia fascia = m_rvtDoc.Create.NewFascia(symbol as FasciaType, refArr);
Gutter gutter = m_rvtDoc.Create.NewGutter(symbol as GutterType, refArr);
SlabEdge slabEdge = m_rvtDoc.Create.NewSlabEdge(symbol as SlabEdgeType, refArr);

NewRebar

csharp 复制代码
m_createdRebar = Rebar.CreateFromRebarShape(m_rvtUIDoc.Document, barShape, barType, m_rebarHost, origin, xVec, yVec);
csharp 复制代码
        private void LayoutRebar()
        {
            List<Autodesk.Revit.DB.XYZ> profilePoints = m_geometryData.OffsetPoints(0.1);
            Autodesk.Revit.DB.XYZ origin = profilePoints[0];
            Autodesk.Revit.DB.XYZ yVec = profilePoints[1] - origin;
            Autodesk.Revit.DB.XYZ xVec = profilePoints[3] - origin;

            RebarShapeDefinitionByArc arcDef =
                 (m_createdRebar.Document.GetElement(m_createdRebar.GetShapeId()) as RebarShape).GetRebarShapeDefinition() as RebarShapeDefinitionByArc;

            RebarShapeDrivenAccessor rebarShapeDrivenAccessor = m_createdRebar.GetShapeDrivenAccessor();
            if (arcDef != null && arcDef.Type == RebarShapeDefinitionByArcType.Spiral)
            {
               rebarShapeDrivenAccessor.ScaleToBoxFor3D(origin, xVec, yVec, 10.0);
               rebarShapeDrivenAccessor.Height = m_geometryData.DrivingLength - 0.1;
               rebarShapeDrivenAccessor.Pitch = 0.1;
               rebarShapeDrivenAccessor.BaseFinishingTurns = 3;
               rebarShapeDrivenAccessor.TopFinishingTurns = 3;
            }
            else
            {
                rebarShapeDrivenAccessor.ScaleToBox(origin, xVec, yVec);
                double barSpacing = 0.1;
                int barNum = (int)(m_geometryData.DrivingLength / barSpacing);
                rebarShapeDrivenAccessor.SetLayoutAsNumberWithSpacing(
                    barNum, barSpacing, true, true, true);
            }
        }

NewRoof

// 拉伸屋顶
ExtrusionRoof extrusionRoof = m_creationDoc.NewExtrusionRoof(profile, refPlane, level, roofType, extrusionStart, extrusionEnd);
// 迹线屋顶
FootPrintRoof footprintRoof = m_creationDoc.NewFootPrintRoof(footPrint, level, roofType, out footPrintToModelCurveMapping);

PowerCircuit

继承关系:

csharp 复制代码
// 创建电力系统
ElectricalSystem es = ElectricalSystem.Create(m_revitDoc.Document, selectionElementId, ElectricalSystemType.PowerCircuit);
// 编辑电力系统
m_selectedElectricalSystem.AddToCircuit(es);
m_selectedElectricalSystem.RemoveFromCircuit(es);
m_selectedElectricalSystem.SelectPanel(fi);
m_selectedElectricalSystem.DisconnectPanel();

RvtSamples

把例子列在 UI 界面,内容略。

SlabShapeEditing

csharp 复制代码
      public SlabShapeCrease AddCrease(PointF point1, PointF point2)
      {
         //create first vertex
         Transaction transaction = new Transaction(
            m_commandData.Application.ActiveUIDocument.Document, "AddCrease");
         transaction.Start();
         Vector4 v1 = new Vector4(new Autodesk.Revit.DB.XYZ(point1.X, point1.Y, 0));
         v1 = m_restoreMatrix.Transform(v1);
         SlabShapeVertex vertex1 = m_slabShapeEditor.DrawPoint(new Autodesk.Revit.DB.XYZ(v1.X, v1.Y, v1.Z));
         //create second vertex
         Vector4 v2 = new Vector4(new Autodesk.Revit.DB.XYZ(point2.X, point2.Y, 0));
         v2 = m_restoreMatrix.Transform(v2);
         SlabShapeVertex vertex2 = m_slabShapeEditor.DrawPoint(new Autodesk.Revit.DB.XYZ(v2.X, v2.Y, v2.Z));
         //create crease
         SlabShapeCreaseArray creases = m_slabShapeEditor.DrawSplitLine(vertex1, vertex2);

         SlabShapeCrease crease = creases.get_Item(0);
         transaction.Commit();
         //re-calculate geometry info 
         GetSlabProfileInfo();
         return crease;
      }

Truss

桁架

csharp 复制代码
Autodesk.Revit.DB.Structure.Truss.Create(document, m_selectedTrussType.Id, sketchPlane.Id, baseLine);
相关推荐
黄金小码农3 小时前
C# 2024/12/26 周四
c#
坐井观老天5 小时前
使用 C# 测量程序运行消耗的的时间
开发语言·c#
小哈龙5 小时前
c++ 类似与c# 线程 AutoResetEvent 和 ManualResetEvent的实现
c++·c#·多线程
YYY_小后知6 小时前
C# 中 Webclient和Httpclient
开发语言·c#
monstercl8 小时前
【C#】元组
开发语言·c#
Dm_dotnet8 小时前
C#调用C++代码,以OpenCV为例
c#
奔跑的犀牛先生9 小时前
C#学习1:初接触,C#的一些基础,和相关报错
开发语言·c#
滴_咕噜咕噜9 小时前
学习笔记 --C#基础其他知识点(持续更新)
笔记·学习·c#
工业甲酰苯胺11 小时前
聊一聊 C#线程池 的线程动态注入
java·开发语言·c#
向宇it11 小时前
【从零开始入门unity游戏开发之——C#篇30】C#常用泛型数据结构类——list<T>列表、`List<T>` 和数组 (`T[]`) 的选择
java·开发语言·数据结构·unity·c#·游戏引擎·list