Revit二次开发知识分享(二十一)修改墙的厚度(楼板同理)

最近总会遇到对墙构件的厚度进行修改,就去了解了一下墙修改的类,下面和大家分享一下~~~


主要想通过代码去修改墙类型属性中结构相关内容

在这里插入图片描述
在这里插入图片描述

对应的类是CompoundStructure 类

在这里插入图片描述

  • 每一行数据都对应的一个CompoundStructureLayer ,CompoundStructure 类中提供了获取和修改的方法,GetLayer方法可以获取,SetLayer方法可以设置修改。CompoundStructureLayer 里面包含功能、材质、厚度这些参数都可以手动修改
    在这里插入图片描述
  • 下面是实操的代码块。
[Transaction(TransactionMode.Manual)]
    public class ChangeWallThicknessDemo : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            Reference selRef = null;
            try
            {
                selRef = uidoc.Selection.PickObject(ObjectType.Element,new SelectedWall(),"请选择需要改变厚度的墙");
            }
            catch 
            {
                return Result.Failed;
            }

            //改变后墙的厚度
            double nwWallThickness = 500;

            Wall selWall = doc.GetElement(selRef) as Wall;
            WallType selWallType = selWall.WallType;
            //墙结构的编辑部件界面
            CompoundStructure wallTypeStructure = selWallType.GetCompoundStructure();
            //拿到墙的整体厚度
            double wallThickness = wallTypeStructure.GetWidth();
            //拿到核心边界里面的第一个图层再所有图层里面的开始编号和结束编号。如果两个不一样的时候,需要考虑改变的是哪一个图层的厚度
            int startIndex = wallTypeStructure.GetFirstCoreLayerIndex();
            int eneIndex = wallTypeStructure.GetLastCoreLayerIndex();
            
            Transaction trans = new Transaction(doc, "修改墙厚度");
            trans.Start();
            //修改厚度
            wallTypeStructure.SetLayerWidth(startIndex, nwWallThickness / 304.8);
            //墙类型重新赋值
            selWallType.SetCompoundStructure(wallTypeStructure);
            trans.Commit();

            return Result.Succeeded;
        }
    }

    public class SelectedWall : ISelectionFilter
    {
        public bool AllowElement(Element elem)
        {
            if (elem is Wall) return true;
            return false;
        }

        public bool AllowReference(Reference reference, XYZ position)
        {
            return true;
        }
    }

这个类里面可以挖掘的方法还有很多,这里不一一叙述,后面可以继续挖掘。这次分享的内容不多,希望可以给你指个方向。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

baobao熊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值