Revit二次开发之获得项目族预览图

时间:2021-05-15 05:41:25

 

Revit二次开发之获得项目族预览图

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;using Autodesk.Revit.Attributes;using System.Windows.Media.Imaging;using Autodesk.Revit.UI.Selection; namespace HelloWorld{    [Transaction(TransactionMode.Manual)]    [Regeneration(RegenerationOption.Manual)]    public class Test : IExternalCommand    {        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)        {            UIDocument uidoc = commandData.Application.ActiveUIDocument;            Document doc = uidoc.Document;            Reference refer = uidoc.Selection.PickObject(ObjectType.Element,new Filter(), "拾取目标构件");             FamilyInstance instance = doc.GetElement(refer) as FamilyInstance;            FamilySymbol symbol = instance.Symbol;             //可以将image保存或是传递给PictreBox            System.Drawing.Image image = symbol.GetPreviewImage(new System.Drawing.Size(100,100));                        return Result.Succeeded;        }    }    //过滤器    public class Filter : ISelectionFilter    {        public bool AllowElement(Element elem)        {            return elem.Category.Name == "管道附件" & elem.Name == "钢管_沟槽_同径90度弯头_DN25-600";        }         public bool AllowReference(Reference reference, XYZ position)        {            return false;        }    } }