Revit二次开发之“显示或隐藏3D视图中的元素“
判断3D视图{3D}
from:http://revit.5d6d.com/thread-1077-1-4.html
//显示或隐藏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;
}
}
[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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。