Revit二次开发之“显示或隐藏3D视图中的元素“

判断3D视图{3D}
// 显示或隐藏3D视图中的元素
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
// [Journaling(JournalingMode.NoCommandData)]
public   class  HideUnHideIn3DView : IExternalCommand
{
    
public  Result Execute(ExternalCommandData commandData,  ref   string  message, ElementSet elements)
    {
        UIDocument uiDoc 
=  commandData.Application.ActiveUIDocument;
        Selection selection 
=  uiDoc.Selection;

        
// 根据Id找到元素的方法
        ElementId elId  =   new  ElementId( 618621 );
        Element el 
=  commandData.Application.ActiveUIDocument.Document.get_Element(elId);

        Transaction ts 
=   new  Transaction(uiDoc.Document,  " HideUnHide " );
        ts.Start();

        Autodesk.Revit.DB.View view 
=  uiDoc.Document.ActiveView;
        
// 判断是不是3D视图
         if  (view.Name  !=   " {3D} " )
        {
            ts.RollBack();
            
return  Result.Cancelled;
        }
        
// 判断在此视图下是否可以隐藏
         if  (el.CanBeHidden(view)  ==   true )
        {
            ElementSet elementSet 
=   new  ElementSet();
            elementSet.Clear();
            elementSet.Insert(el);

            
if  (el.IsHidden(view)  ==   true )
            {
                view.Unhide(elementSet);
            }
            
else
            {
                view.Hide(elementSet);
            }
        }

        ts.Commit();

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

转载于:https://www.cnblogs.com/greatverve/archive/2011/08/17/revit-show-hide-3d-view.html

你可能感兴趣的:(Revit二次开发之“显示或隐藏3D视图中的元素“)