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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值