Revit二次开发之“创建空间Newspace”

这里涉及到一些专业知识,没有成功,但是代码是从示例中取出来的,示例可以创建空间。
有时间再研究,先记录下来。
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public   class  CreateSpace : IExternalCommand
{
    
public  Result Execute(ExternalCommandData cmdData,  ref   string  msg, ElementSet elements)
    {
        UIDocument uiDoc 
=  cmdData.Application.ActiveUIDocument;

        
try
        {
            Transaction ts 
=   new  Transaction(uiDoc.Document,  " space " );
            ts.Start();

            
// Level
            Level level  =   null ;
            FilteredElementIterator levelsIterator 
=  ( new  FilteredElementCollector(uiDoc.Document)).OfClass( typeof (Level)).GetElementIterator();
            levelsIterator.Reset();
            
while  (levelsIterator.MoveNext())
            {
                level 
=  levelsIterator.Current  as  Level;
                
break ;
            }

            
// Phase面域
            Parameter para  =  uiDoc.Document.ActiveView.get_Parameter(BuiltInParameter.VIEW_PHASE);
            ElementId phaseId 
=  para.AsElementId();
            Phase phase 
=  uiDoc.Document.get_Element(phaseId)  as  Phase;

            
if  (phase  ==   null )
            {
                System.Windows.Forms.MessageBox.Show(
" The phase of the active view is null, you can't create spaces in a null phase " );
            }

            
// CreateSpace
             if  (uiDoc.Document.ActiveView.ViewType  ==  ViewType.FloorPlan)
            {
                uiDoc.Document.Create.NewSpaces(level, phase, uiDoc.ActiveView);
            }
            
else
            {
                System.Windows.Forms.MessageBox.Show(
" You can not create spaces in this plan view " );
            }

            ts.Commit();
        }
        
catch  (Exception ex)
        {
            TaskDialog.Show(
" ex " , ex.ToString());
        }

        
return  Result.Succeeded;
    }
}
from: http://revit.5d6d.com/thread-1252-1-1.html

转载于:https://www.cnblogs.com/greatverve/archive/2011/09/16/revit-api-newspace.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值