Revit二次开发之“显示或隐藏视图中选中的元素”
Hide();UnHide();
from:http://revit.5d6d.com/thread-1088-1-4.html
//显示或隐藏视图中选中的元素
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class HideUnHideSelectInView : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Selection selection = uiDoc.Selection;
if (selection.Elements.Size == 0)
{
MessageBox.Show("请选择");
return Result.Cancelled;
}
Transaction ts = new Transaction(uiDoc.Document, "HideUnHide");
ts.Start();
Autodesk.Revit.DB.View view = uiDoc.Document.ActiveView;
//判断在此视图下是否可以隐藏
foreach (Element el in selection.Elements)
{
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 HideUnHideSelectInView : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Selection selection = uiDoc.Selection;
if (selection.Elements.Size == 0)
{
MessageBox.Show("请选择");
return Result.Cancelled;
}
Transaction ts = new Transaction(uiDoc.Document, "HideUnHide");
ts.Start();
Autodesk.Revit.DB.View view = uiDoc.Document.ActiveView;
//判断在此视图下是否可以隐藏
foreach (Element el in selection.Elements)
{
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;
}
}
我这个博客废弃不用了,今天想寻找外链的时候,突然想到这个博客权重很高。
有需要免费外链的,留言即可,我准备把这个博客变成免费的友情链接站点。