【Revit二次开发】新建墙类型

新建墙类型


1、
在Revit二次开发中,可以使用Revit API来创建、修改和删除Revit中的墙类型。下面是一个创建新墙类型的简单示例:

// 获取当前文档
Document doc = commandData.Application.ActiveUIDocument.Document;

// 创建一个新的墙类型
WallType wallType = WallType.Create(doc, "New Wall Type");

// 设置墙类型的参数
wallType.Width = 0.2; // 设置墙的宽度
wallType.FinishTexture = "Brick"; // 设置墙的纹理

// 将墙类型添加到文档中
doc.SetDefaultWallType(wallType);

在这个示例中,我们首先获取了当前文档对象,然后创建了一个名为“New Wall Type”的新墙类型,并设置了墙的宽度和纹理,最后将新墙类型添加到文档中。

需要注意的是,墙类型的参数是由WallType类中的属性来表示的,可以根据自己的需要设置这些属性。例如,您可以设置墙类型的高度、厚度、材质等参数。

另外,墙类型是可以被修改和删除的,可以使用WallType类的方法和属性来实现这些操作。例如,您可以使用WallType.Delete方法来删除一个墙类型,使用WallType.Parameter方法来获取或设置一个墙类型的参数值。

总的来说,创建新墙类型是Revit二次开发中的常见操作之一,它可以帮助更好地管理Revit中的构件类型和属性,提高Revit模型的可维护性和可扩展性

2、
取一个墙类型,复制并重命名修改参数,就可以迅速得到一个新的墙类型

public static ElementId CreatWallType(Document doc, string wallTypeName, double width)
{

    ElementId wallTypeId = null;
    FilteredElementCollector Col = new FilteredElementCollector(doc);
    var familySymbolList = Col.OfClass(typeof(WallType)).ToList();
    WallType baseWallType = null;
    WallType newWallType = null;
    using (Transaction transaction = new Transaction(doc))
    {
        if (transaction.Start("创建新墙类型") == TransactionStatus.Started)
        {
            try
            {
                //获取一个墙类型复制并重命名
                foreach (WallType item in familySymbolList)
                {
                    if (item.Category.Name == "墙" && item.FamilyName == "基本墙"&& item.Name == "常规 - 200mm")
                    {
                        baseWallType = item;
                        continue;
                    }
                }
                foreach (WallType item in familySymbolList)
                {
                    if (item.Name == wallTypeName)
                    {
                        TaskDialog.Show("创建墙", "墙类型已经存在");
                        transaction.Commit();
                    }
                }
                newWallType = baseWallType.Duplicate(wallTypeName) as WallType;
                doc.Regenerate();
                //改变厚度
                CompoundStructure wallTypeStructure = newWallType.GetCompoundStructure();
                double wallThickness = wallTypeStructure.GetWidth();//得到厚度
                int endIndex = wallTypeStructure.GetLastCoreLayerIndex();//分层看情况
                wallTypeStructure.SetLayerWidth(endIndex, width/304.8);
                newWallType.SetCompoundStructure(wallTypeStructure);//修改后设置
                if (TransactionStatus.Committed != transaction.Commit())
                {
                    TaskDialog.Show("创建新墙类型", "提交失败!");
                }
            }
            catch
            {
                transaction.RollBack();
                throw;
            }
        }
    }
    wallTypeId = newWallType.Id;
    return wallTypeId;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

孤影墨客

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

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

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

打赏作者

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

抵扣说明:

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

余额充值