在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 ;
    }
}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值