简体   繁体   English

Revit API - 从 Revit 项目中完全删除族

[英]Revit API - Remove family completely from Revit project

I'm running into a problem trying to remove a family from a project.我在尝试从项目中删除一个家庭时遇到了问题。 I'm able to delete the family types but it seems like the family is still loaded in the project.我可以删除族类型,但该族似乎仍在项目中加载。 Is there a way to remove it completely?有没有办法完全删除它?

so far, i've looked at these sources:到目前为止,我已经查看了这些来源:

1) https://adndevblog.typepad.com/aec/2012/07/supported-workflow-for-unloading-a-family-using-the-revit-api.html 1) https://adndevblog.typepad.com/aec/2012/07/supported-workflow-for-unloading-a-family-using-the-revit-api.html

2) https://adndevblog.typepad.com/aec/2012/07/supported-workflow-for-unloading-a-family-using-the-revit-api.html 2) https://adndevblog.typepad.com/aec/2012/07/supported-workflow-for-unloading-a-family-using-the-revit-api.html

here's my code:这是我的代码:

FilteredElementCollector colTitleBlocks = new FilteredElementCollector(doc)
                .OfClass(typeof(FamilySymbol))
                .OfCategory(BuiltInCategory.OST_TitleBlocks);


using (Transaction tx6 = new Transaction(doc))
{
    tx6.Start("load custom titleblock that you just made");


    Element family2Unload = null;
    foreach (FamilySymbol xfamily in colTitleBlocks )
        {

        if (xfamily.FamilyName == "E1 30 x 42 Horizontal")
             {

             family2Unload = doc.GetElement(xfamily.Id) as Element;

             }
        }
   doc.Delete(family2Unload.Id);

   tx6.Commit();
}

在此处输入图像描述

Families家庭

FamilyInstance => a placed instance of a family FamilyInstance => 放置的族实例

FamilySymbol => a family type with 0-m instances FamilySymbol => 具有 0-m 个实例的族类型

Family => A family with with n types 0-m instances Family => 具有 n 类型 0-m 实例的家庭

Example: FamilyDelete.pushbutton示例: FamilyDelete.pushbutton

Here is one of my script from pyRevitMEP to delete families:这是我从pyRevitMEP删除族的脚本之一:

"""
Copyright (c) 2017 Cyril Waechter
Python scripts for Autodesk Revit
This file is part of pypevitmep repository at https://github.com/CyrilWaechter/pypevitmep
pypevitmep is an extension for pyRevit. It contain free set of scripts for Autodesk Revit:
you can redistribute it and/or modify it under the terms of the GNU General Public License
version 3, as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
See this link for a copy of the GNU General Public License protecting this package.
https://github.com/CyrilWaechter/pypevitmep/blob/master/LICENSE
"""
import rpw
doc = rpw.revit.doc
uidoc = rpw.revit.uidoc

from Autodesk.Revit.DB import Transaction, FamilySymbol

__doc__ = "Delete selected families from project"
__title__ = "Family delete"
__author__ = "Cyril Waechter"
__context__ = "Selection"


with rpw.db.Transaction("Delete families from project"):
    # Find families of selected object and delete it
    for id in uidoc.Selection.GetElementIds():
        el = doc.GetElement(id)
        family_id = el.Symbol.Family.Id
        doc.Delete(family_id)

You have the same one for family types: FamilyTypeDelete.pushbutton对于家庭类型,您有相同的类型: FamilyTypeDelete.pushbutton

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM