打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Revit二次开发之“族”操作
风管 - 类别Category
圆形风管 - 族Family
T形三通 - 族型号FamilySymbol
画出来 - 族实例FamilyInstance
http://revit.5d6d.com

加载族

[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Manual)]
[Journaling(JournalingMode.NoCommandData)]
public class LoadFamily : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {
        Document doc = commandData.Application.ActiveUIDocument.Document;
        doc.LoadFamily(@"C:\Documents and Settings\All Users\Application Data\Autodesk\RME 2011\Metric Library\窗\M_带贴面窗.rfa");
        return Result.Succeeded;
    }
}
end
    [Transaction(TransactionMode.Automatic)]
    [Regeneration(RegenerationOption.Manual)]
    [Journaling(JournalingMode.NoCommandData)]
    public class LoadFamily : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;
            //加载族
            
//doc.LoadFamily(@"C:\Documents and Settings\All Users\Application Data\Autodesk\RME 2011\Metric Library\窗\M_带贴面窗.rfa");
            
//加载族中的一个Symbol
            
//doc.LoadFamilySymbol(@"C:\Documents and Settings\All Users\Application Data\Autodesk\RME 2011\Metric Library\窗\M_带贴面窗.rfa"
            
//, "0406 x 0610 mm");
            
//遍历族
            TraversqlFamily(doc);

            return Result.Succeeded;
        }
        public Result TraversqlFamily(Document doc)
        {
            Family family = null;
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            ICollection<Element> collection = collector.OfClass(typeof(Family)).ToElements();
            string sMsg = "Standard families already loaded in this model:";
            foreach (Element e in collection)
            {
                family = e as Family;
                if (null != family)
                {
                    /*
                    //获得族的类别名称
                    string famCatName = (null == family.FamilyCategory) ? "?" : family.FamilyCategory.Name;
                    sMsg += "\r\n Name=" + family.Name + ";Category=" + famCatName;

                    if (family.Name == "M_圆形四通")//M_风管尺寸标记//M_圆形软风管标记
                        MessageBox.Show(family.Name);
                    if (family.Name == "风管")
                        MessageBox.Show(family.Name);
                    if (family.Name == "圆形风管")
                        MessageBox.Show(family.Name);
                    if (family.Name == "接头")
                        MessageBox.Show(family.Name);

                    if (family.Name.Contains("风管"))
                        MessageBox.Show(family.Name);
*/
                    if (family.FamilyCategory.Name == "圆形风管")
                    //if (family.FamilyCategory.Name == "风管")
                        sMsg += "\r\n Name=" + family.Name + ";Category=" + family.FamilyCategory.Name;
                }
            }
            MessageBox.Show(sMsg);

            return Result.Succeeded;
        }
end
创建族实例
[Transaction(TransactionMode.Automatic)]
[Regeneration(RegenerationOption.Automatic)]
public class CreateFamilyInstance : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        UIApplication uiApp = commandData.Application;
        Document doc = uiApp.ActiveUIDocument.Document;
        Selection sel = uiApp.ActiveUIDocument.Selection;

        FamilySymbol familySymbol = null;
        FilteredElementCollector collector = new FilteredElementCollector(doc);//过滤元素
        ICollection<Element> collection = collector.OfClass(typeof(FamilySymbol)).ToElements();

        foreach (Element e in collection)
        {
            familySymbol = e as FamilySymbol;
            if (null != familySymbol.Category)
            {
                if ("风管管件" == familySymbol.Category.Name)//这里不知道怎样用内参BuiltInCategory.o
                {
                    if (familySymbol.Family.Name == "矩形弯头 - 法兰")
                    {
                        //遍历族符号的方法
                        FamilySymbolSetIterator symbolItor = familySymbol.Family.Symbols.ForwardIterator();
                        FamilySymbol fs = null;
                        while (symbolItor.MoveNext())
                        {
                            fs = symbolItor.Current as FamilySymbol;
                        }
                        break;
                    }
                }
            }
        }

        XYZ point = new XYZ(101010);

        //创建族实例
        FamilyInstance fi = doc.Create.NewFamilyInstance(point, familySymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

        //修改族实例
        FamilySymbol newFamilySymbol = null;
        foreach (Element e in collection)
        {
            newFamilySymbol = e as FamilySymbol;
            if (null != newFamilySymbol.Category)
            {
                if ("风管管件" == newFamilySymbol.Category.Name)
                {
                    if (newFamilySymbol.Family.Name == "矩形弯头 - 平滑半径 - 法兰")
                    {
                        FamilySymbolSetIterator symbolItor = newFamilySymbol.Family.Symbols.ForwardIterator();
                        FamilySymbol fs = null;
                        while (symbolItor.MoveNext())
                        {
                            fs = symbolItor.Current as FamilySymbol;
                            //MessageBox.Show(fs.Name);
                        }
                        break;
                    }
                }
            }
        }
        fi.Symbol = newFamilySymbol;

        return Result.Succeeded;
    }
}
end
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Revit开发
C#根据Word模版生成Word文件
基于.Net平台应用程序唯一运行实例实现
Microsoft Service Manager
How do I automatically destroy child processes in Windows?
第一个真正的Windows程序(在C语言中程序都是黑屏的称为控制台程序(Console Application)这套教程要讲的是带界面的Windows程序(Windows Application)GU
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服