在Revit 2013里 如何编程创建(东西南北四个方向)的立面图


转载请复制以下信息:
原文链接: http://blog.csdn.net/joexiongjin/article/details/7973028

作者:  叶雄进 , Autodesk ADN


Revit2013 提供了新的API来创建立面视图。创建立面视图要求先创建一个立面视图标记ElevationMarker,然后用这个ElevationMarker的函数CreateElevation() 来创建一个立面视图。

CreateElevation函数的签名如下:

public ViewSection CreateElevation(
	Document document,
	ElementId viewPlanId,
	int index
)

第一个,第二个参数比较容易理解。第三个参数Index的含义是表明立面视图的方向。

=0, 表示生成东立面视图

=1, 生成南立面视图

=2, 生成西立面视图

=3, 生成北立面视图

>=4, 程序运行错误。


下面代码演示了如何创建一个立面视图。创建后修改下立面视图的Crop Box范围。


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Linq;

using  Autodesk.Revit .DB;
using Autodesk.Revit.UI;
using Autodesk.Revit .ApplicationServices;
using Autodesk.Revit.Attributes ;



  [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class RevitCommand : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {

      UIApplication app = commandData.Application;
      Document doc = app.ActiveUIDocument.Document;
      Transaction trans = new Transaction(doc, "ExComm");
      trans.Start();

      FilteredElementCollector collector = new FilteredElementCollector(doc);
      collector.OfClass(typeof(ViewFamilyType));

      
      var viewFamilyTypes = from elem in collector 
                        let type = elem as ViewFamilyType
                        where type.ViewFamily == ViewFamily.Elevation
                        select type;

      ElementId viewtypeId;
      if (viewFamilyTypes.Count() > 0)
        viewtypeId = viewFamilyTypes.First().Id;
      else
        return Result.Cancelled;

      ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, viewtypeId, new XYZ(0, 10, 0), 100);

      ViewSection sv = marker.CreateElevation(doc,doc.ActiveView.Id, 1);

      trans.Commit();

      //chang the cropbox.
      Transaction trans2 = new Transaction(doc,"test2");
      trans2.Start();
      

      doc.Regenerate();

      // get the bounding box of the section
      BoundingBoxXYZ bb = sv.CropBox;

      // by way of example reduce the section height by 3 foot
      XYZ max = bb.Max;
      max = new XYZ(max.X+ 3, max.Y - 3, max.Z);
      bb.Max = max;

      // set the new bounding box
      sv.CropBox = bb;

      trans2.Commit();

        return Result.Succeeded ;
    }
}


你可能感兴趣的:(Revit,Revit,二次开发中级技术)