使用Revit自带命令进行风管绘制,绘制后自动选择所绘制的风管。使用自带命令是用uiapp.ActiveUIDocument.PostRequestForElementTypePlacement;
思路:
1.用自带命令画风管(这里需要用到空闲事件,不然经过PostRequestForElementTypePlacement后会提前结束功能)
2.获取所画风管
代码安排上:
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
uiapp = commandData.Application;
main(doc, uidoc);
reurn Result.Succeeded;
}
private void main(Document doc, UIDocument uidoc)
{
var re = doc.GetElement(new ElementId(72989)) as ElementType;//风管类型
uidoc.PostRequestForElementTypePlacement(re);
uiapp.Application.DocumentChanged += Application_DocumentChanged;
}
private void Application_DocumentChanged(object sender, DocumentChangedEventArgs e)
{
Document doc = e.GetDocument();
// ElementCategoryFilter genericmodelFilter = new ElementCategoryFilter(BuiltInCategory.OST_DuctCurves);
// var addlist = e.GetAddedElementIds(genericmodelFilter);//过滤单个风管
var addlist = e.GetAddedElementIds();//所有新增内容,例如风管,系统名称等
foreach (var item in addlist)
{
if (doc.GetElement(item).GetType().Equals(typeof(MechanicalSystem)))
continue;
elemids.Add(item);
}
uiapp.Idling += GetCuct;
}
private void GetCuct(object sender, IdlingEventArgs e)
{
UIApplication uiapp = sender as UIApplication;
try
{
if (uiapp != null)
{
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
if (uidoc != null && doc != null)
{
if (elemids.Count > 0)
{
uidoc.Selection.SetElementIds(elemids);
}
uiapp.Idling -= GetCuct;
uiapp.Application.DocumentChanged -= Application_DocumentChanged;
}
else
{
MessageBox.Show("Must should Idling!");
}
}
}
catch (Exception)
{
MessageBox.Show("CanSel");
uiapp.Idling -= GetCuct;
uiapp.Application.DocumentChanged -= Application_DocumentChanged;
}
}
分享一个自制Revit插件,本人是个BIM工程师,该插件是根据自己做工程一些经验和对插件功能的频繁度,自己整合开发功能,初衷是提高效率。
目前MagicTools的功能包括通用功能、土建、机电、审图、出图功能。还有好多功能都想做,如果有好的需求也可以提,后续有新增继续增加上去,努力弄个实用的插件,希望能帮到真正有需要的BIMer。
如有需要的可以加企鹅群:630552940
插件下载地址,免费试用
链接:https://pan.baidu.com/s/1qNnagumXlN6yrIBvRr1dNA?pwd=bljw
提取码:bljw
版权声明:本文为weixin_46563153原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。