Revit二次开发之“预览”

这里演示已经加载的族的预览,通过FamilySymbol.GetPreviewImage()
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
//[Journaling(JournalingMode.NoCommandData)]
public class GetPreview : IExternalCommand
{
    
public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
    {
        UIDocument uidoc 
= revit.Application.ActiveUIDocument;
        
//得到选择的对象
        Selection selection = uidoc.Selection;
        ElementSet collection 
= selection.Elements;

        Reference refelem 
= selection.PickObject(ObjectType.Element, "选择");

        FamilyInstance fi 
= uidoc.Document.GetElement(refelem) as FamilyInstance;
        FamilySymbol fs 
= fi.Symbol;

        
//MessageBox.Show(fs.Name);

        
//加载族
        
//uidoc.Document.LoadFamily(@"D:\revit\Revit文件\万能窗.rfa");
        
//遍历找到YTC3015
        FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document);
        ICollection
<Element> coll = collector.OfClass(typeof(Family)).ToElements();
        
string strFamily = "";
        
foreach (Element e in coll)
        {
            Family ffi 
= e as Family;
            strFamily 
+= ffi.Name;

            FamilySymbolSetIterator symbolItor 
= ffi.Symbols.ForwardIterator();
            
while (symbolItor.MoveNext())
            {
                FamilySymbol fSymbol 
= symbolItor.Current as FamilySymbol;
                
if (null != fSymbol)
                {
                    
if (fSymbol.Name == "YTC3015")
                        MessageBox.Show(fSymbol.Name 
+ "hi");
                }
            }

        }

        MessageBox.Show(strFamily);

        
//Form1 f1 = new Form1(fs.GetPreviewImage(new System.Drawing.Size(200, 200)));
        
//f1.ShowDialog();

        
return Result.Succeeded;
    }
}
窗体代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RevitCodes
{
    
public partial class Form1 : Form
    {
        System.Drawing.Bitmap bMap 
= null;
        
public Form1()
        {
            InitializeComponent();
        }

        
public Form1(System.Drawing.Bitmap bitmap)
        {
            bMap 
= bitmap;
            InitializeComponent();
        }

        
private void Form1_Load(object sender, EventArgs e)
        {
            
this.pictureBox1.Image = bMap;
        }
    }
}
from:http://revit.5d6d.com/thread-900-1-4.html
posted @ 2011-08-04 07:53  大气象  阅读(2076)  评论(0编辑  收藏  举报
http://www.tianqiweiqi.com