Revit C#更改族类型

问题描述 投票:0回答:1

我正在尝试在项目中改变家庭。新家庭成功加载,但抛出异常Autodesk.Revit.Exceptions.InvalidOperationException:'无法分配此元素的类型。'当我尝试将旧Family的ChangeTypeId更改为新Family GetTypeId()时;

    public void ReplaceTitleblock (Document cdoc)
    {
        string targetName = "TITLEBLOCK_AHMB";

        Family oldFamily = (from element in new FilteredElementCollector(cdoc).OfClass(typeof(Family))
                                           where element.Name == targetName && element.IsValidObject
                                           select element as Family).FirstOrDefault();

        Family newFamily;

        if (oldFamily != null)
        {
            cdoc.LoadFamily(newTitleblockPath, out newFamily);
            ElementId newElId = newFamily.GetTypeId();
            oldFamily.ChangeTypeId(newElId);
        }

有关此操作的任何帮助?

谢谢,卢卡

c# revit-api revit
1个回答
0
投票

我知道了它的工作。

我现在遍历Family的FamilyInstances,并用新的FamilySymbol代替FamilySymbol

            foreach (FamilyInstance fam in oldFamilyInstancesFilter)
            {
                FamilySymbol newSymbol = cdoc.GetElement(newFamily.GetFamilySymbolIds().FirstOrDefault()) as FamilySymbol;
                fam.Symbol = newSymbol;
            }

我知道只有一个符号,因此是FirstOrDefault()方法

© www.soinside.com 2019 - 2024. All rights reserved.