[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;
}
}
[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;
}
}
}
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;
}
}
}