Revit二次开发 管道系统布置

在机电开发的过程中,往往要用到管道布管系统配置相关的API,所以下面简单介绍一下管道系统配置,直接上代码:请添加图片描述
获取数据

//选择管道
            Reference selRef = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
            Pipe selPipe = doc.GetElement(selRef) as Pipe;
            PipeType selPipeType = selPipe.PipeType;
            //已知的一个弯头FamilySymbol Id是我直接用lookup取的。示例使用
            FamilySymbol nwElowsFS = doc.GetElement(new ElementId(211606)) as FamilySymbol;
            //得到布管系统信息
            RoutingPreferenceManager routing = selPipeType.RoutingPreferenceManager;

            #region 获取弯头族信息
            //示例得到弯头的族类型
            RoutingPreferenceRule routingRule = routing.GetRule(RoutingPreferenceRuleGroupType.Elbows, 0);
            //获取弯头设置的familysymbol
            FamilySymbol mid = doc.GetElement(routingRule.MEPPartId) as FamilySymbol;
            PrimarySizeCriterion primarySize = routingRule.GetCriterion(0) as PrimarySizeCriterion;//获取弯头的尺寸设置值
            double minSize = primarySize.MinimumSize;
            double maxSize = primarySize.MaximumSize;
            MessageBox.Show($"族名称{mid.FamilyName} 族类型名称{mid.Name}, 最小尺寸{minSize * 304.8} , 最大尺寸{maxSize * 304.8}");
            #endregion

其中RoutingPreferenceRuleGroupType是一个枚举值,对应参数的枚举值可以自己去试一下就知道了。每一个RoutingPreferenceRule参数代表着一行数据。
下面是添加一行自己定义的规则的代码

 Transaction createTrans = new Transaction(doc, "改变管道系统里面的数值");
            createTrans.Start();
            //设置尺寸
            PrimarySizeCriterion nwPriSize = new PrimarySizeCriterion(25 / 304.8, 150 / 304.8);
            //创建新的布管规则
            RoutingPreferenceRule nwRule = new RoutingPreferenceRule(nwElowsFS.Id, "新建");
            //添加尺寸信息
            nwRule.AddCriterion(nwPriSize);
            //添加新的布管规则
            routing.AddRule(RoutingPreferenceRuleGroupType.Elbows, nwRule, 0);
            createTrans.Commit();

下面是修改第一个规则的族为自己想要的族类型

Transaction replaceTrans = new Transaction(doc, "替换");
            replaceTrans.Start();
            //创建新的布管规则
            RoutingPreferenceRule nwRule = new RoutingPreferenceRule(nwElowsFS.Id, "替换");
            //添加尺寸信息
            nwRule.AddCriterion(primarySize);
            //添加新的布管规则
            routing.AddRule(RoutingPreferenceRuleGroupType.Elbows, nwRule, 0);
            routing.RemoveRule(RoutingPreferenceRuleGroupType.Elbows, 1);
            replaceTrans.Commit();

以上就是管道系统布置的介绍,希望能帮到你。
Magictools插件下载地址,免费试用
链接:https://pan.baidu.com/s/1qNnagumXlN6yrIBvRr1dNA?pwd=bljw
提取码:bljw

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Revit二次开发中,可以使用Revit API来实现管道贴梁布置的功能。具体实现方法包括以下几个步骤: 1. 获取所有的梁和管道对象,并对它们进行分类和分组。 2. 遍历所有的管道,找出管道所在的梁,并计算出管道的位置和方向。 3. 根据管道的位置和方向,计算出管道需要布置的支架位置和方向。 4. 创建支架对象,并将其放置在计算出的位置和方向上。 下面是一个简单的示例代码,用于实现简单的管道贴梁布置功能: ```csharp // 获取当前文档 Document doc = uidoc.Document; // 定义一个过滤器,过滤出所有的梁和管道 ElementCategoryFilter beamFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming); ElementCategoryFilter pipeFilter = new ElementCategoryFilter(BuiltInCategory.OST_Pipe); LogicalOrFilter filter = new LogicalOrFilter(beamFilter, pipeFilter); // 获取所有符合条件的梁和管道 List<Element> elements = new FilteredElementCollector(doc) .WherePasses(filter) .ToList(); // 将梁和管道分组 List<Element> beams = elements.Where(e => e.Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming).ToList(); List<Element> pipes = elements.Where(e => e.Category.Id.IntegerValue == (int)BuiltInCategory.OST_Pipe).ToList(); // 遍历所有的管道 foreach (Element pipe in pipes) { // 获取管道所在的梁 Element beam = null; foreach (Element e in beams) { LocationCurve locationCurve = e.Location as LocationCurve; if (locationCurve.Curve.Project(pipe.Location.LineDirection).Distance < 0.1) { beam = e; break; } } if (beam == null) continue; // 计算管道的位置和方向 LocationCurve pipeLocationCurve = pipe.Location as LocationCurve; XYZ pipeStart = pipeLocationCurve.Curve.GetEndPoint(0); XYZ pipeEnd = pipeLocationCurve.Curve.GetEndPoint(1); XYZ pipeDirection = pipeEnd - pipeStart; // 计算支架的位置和方向 XYZ beamDirection = (beam.Location as LocationCurve).Curve.Direction; XYZ supportDirection = XYZ.BasisZ.CrossProduct(pipeDirection).Normalize(); XYZ supportPosition = pipeStart + (pipeDirection + beamDirection) / 2; // 创建支架对象 // TODO: 创建支架对象并放置在计算出的位置和方向上 } ``` 上述代码中,我们首先使用过滤器获取所有的梁和管道对象,并将它们分组。然后,我们遍历所有的管道,找出管道所在的梁,并计算出管道的位置和方向。接着,我们根据管道的位置和方向,计算出管道需要布置的支架位置和方向。最后,我们创建支架对象,并将其放置在计算出的位置和方向上。需要注意的是,上述代码仅为示例代码,实际应用中可能需要根据具体需求进行修改。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值