Revit二次开发 风管连接

Revit机电核心功能风管连接,往往建模的时候基本都能用到的功能。首先先讲讲思路,
1.管道连接就是管道的Connector的连接,只要Connector的顺序对和布管系统配置设置好,就可以实现管道连接了。
2.判断风管管件的类型和风管是否在正确位置上,比如是中/底/顶对齐,还是中/左/右对齐,根据对齐方式选择正确的管件
3.风管四通有4个Connector要判断正确顺序,这个就要区分好(重点)
以上就是实现风管连接的思路,直接上代码。

 UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;
            Selection sel = uidoc.Selection;
            Transaction trs = new Transaction(doc, "风管连接");
            string familyfile = FilePathData.FittingFamilyfilepath;//族放置的文件夹

            try
            {
                //选择第一个风管
                var reference0 = sel.PickObject(ObjectType.Element, new MEPFilter(), "选择第一个主管");
                var pipecurve0 = doc.GetElement(reference0) as MEPCurve;

                var neartpoint0 = Tools.Nearpoint(reference0.GlobalPoint, pipecurve0);
                var farpoint0 = Tools.Farpoint(reference0.GlobalPoint, pipecurve0);
                var dirline0 = Line.CreateBound(neartpoint0, farpoint0);

                var dir0 = dirline0.Direction.Normalize();
                var zdir = Line.CreateBound(neartpoint0, neartpoint0.PointZOffset(neartpoint0.Z + 1)).Direction.Normalize();
                var dotdir = dir0.CrossProduct(zdir);

                var connector0 = reference0.GlobalPoint.ThisNearConnector(pipecurve0);
                var farcon0 = farpoint0.ThisNearConnector(pipecurve0);
         

                //选择第二个风管
                var reference1 = sel.PickObject(ObjectType.Element, new MEPFilter(), "选择第二个主管");
                var pipecurve1 = doc.GetElement(reference1) as MEPCurve;

                var connector1 = reference1.GlobalPoint.ThisNearConnector(pipecurve1);
                var neartpoint1 = Tools.Nearpoint(reference1.GlobalPoint, pipecurve1);
                var farpoint1 = Tools.Farpoint(reference1.GlobalPoint, pipecurve1);
                var dirline1 = Line.CreateBound(neartpoint1, farpoint1).Direction.Normalize();


                //选择第三个风管
                var reference2 = sel.PickObject(ObjectType.Element, new MEPFilter(), "选择第一个支管");
                var pipecurve2 = doc.GetElement(reference2) as MEPCurve;
                var connector2 = reference2.GlobalPoint.ThisNearConnector(pipecurve2);

                var neartpoint2 = Tools.Nearpoint(reference2.GlobalPoint, pipecurve2);
                var farpoint2 = Tools.Farpoint(reference2.GlobalPoint, pipecurve2);
                var dirline2 = Line.CreateBound(neartpoint2, farpoint2).Direction.Normalize();
                var dirline2Z = Line.CreateBound(neartpoint2, neartpoint2.PointZOffset(neartpoint2.Z + 1)).Direction.Normalize();
                var dirline2cross = dirline2.CrossProduct(dirline2Z);

                //选择第四个风管
                var reference3 = sel.PickObject(ObjectType.Element, new MEPFilter(), "选择第二个支管");
                var pipecurve3 = doc.GetElement(reference3) as MEPCurve;
                var connector3 = reference3.GlobalPoint.ThisNearConnector(pipecurve3);

                bool flagdir = dir0.IsSameDirection(dirline2cross);
                string familynameside = "矩形圆角变径四通-水平中-竖直中";

                //如果项目没有族则加载族
                var sybolfilter = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_DuctFitting).OfClass(typeof(FamilySymbol)).ToList();
                Tools.SearchFamilySybolLoadFamily(doc, familyfile, familynameside, sybolfilter);
                trs.Start();
                //设置布管系统配置
                RoutingPreferenceManager Rpm = (reference0.GetElement(doc) as Duct).DuctType.RoutingPreferenceManager;
                FilteredElementCollector collector = new FilteredElementCollector(doc);

                if (familynameside != null)
                {
                    var familysymbol = collector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_DuctFitting).ToList().FirstOrDefault(x => (x as FamilySymbol).FamilyName.Contains(familynameside));
                    var familysymbolID = (familysymbol as FamilySymbol).Id;

                    //设置类型
                    RoutingPreferenceRule routinPFrule = new RoutingPreferenceRule(familysymbolID, familynameside);
                    Rpm.AddRule(RoutingPreferenceRuleGroupType.Crosses, routinPFrule, 0);
                }
                else
                {
                    MessageBox.Show("找不到族" + familynameside);
                    return Result.Cancelled;
                }
                //MessageBox.Show(familynameside.ToString());

                //创建管件
                FamilyInstance ft = null;

                if (flagdir)
                {
                    ft = doc.Create.NewCrossFitting(connector0, connector1, connector2, connector3);
                }
                else
                {
                    ft = doc.Create.NewCrossFitting(connector0, connector1, connector3, connector2);
                }
              
                Rpm.RemoveRule(RoutingPreferenceRuleGroupType.Crosses, 0);

                trs.Commit();
            }

            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                if (trs.GetStatus() == TransactionStatus.Started)
                {
                    trs.RollBack();
                }
            }
            return Result.Succeeded;

在这里插入图片描述

该功能本插件就有(MagicTools),免费试用,全是干货。
如有需要的可以加企鹅群:630552940

分享一个自制Revit插件,本人是个BIM工程师,该插件是根据自己做工程一些经验和对插件功能的频繁度,自己整合开发功能,初衷是提高效率。
目前MagicTools的功能包括通用功能、土建、机电、审图、出图功能。还有好多功能都想做,如果有好的需求也可以提,后续有新增继续增加上去,努力弄个实用的插件,希望能帮到真正有需要的BIMer。
如有需要的可以加企鹅群:630552940

插件下载地址,免费试用
链接:https://pan.baidu.com/s/1GDnHeWwZ5r_HrnT3Mo7twA?pwd=jhlt
提取码:jhlt

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值