Beispiel #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            if (FilesOption())
            {
                foreach (var file in files)
                {
                    string     codeBase        = Assembly.GetExecutingAssembly().CodeBase;
                    UriBuilder uri             = new UriBuilder(codeBase);
                    string     path            = Uri.UnescapeDataString(uri.Path);
                    var        placeholderFile = Path.GetDirectoryName(path) + @"\placeholderFile.rte";

                    UIApplication uiapp = commandData.Application;
                    UIDocument    uidoc = uiapp.OpenAndActivateDocument(file);
                    Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
                    Document doc             = uidoc.Document;
                    AssetSet objlibraryAsset = app.get_Assets(AssetType.Appearance);

                    #region///判断是否为空视图,若为空视图,切换为3d视图
                    View3D view = doc.ActiveView as View3D;
                    if (null == view)
                    {
                        IEnumerable <ViewFamilyType> viewFamilyTypes = from elem in new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
                                                                       let type = elem as ViewFamilyType
                                                                                  where type.ViewFamily == ViewFamily.ThreeDimensional
                                                                                  select type;
                        Transaction ts = new Transaction(doc, "Change3D");
                        try
                        {
                            ts.Start();
                            XYZ    direction = new XYZ(-1, 1, -1);
                            View3D view3D    = View3D.CreateIsometric(doc, viewFamilyTypes.First().Id);
                            //View3D view3D = uiDoc.Document.Create.NewView3D(new XYZ(-1, 1, -1));//斜视45度
                            ts.Commit();
                            //切换视图必须在事务结束后,否则会提示错误:
                            //Cannot change the active view of a modifiable document
                            uidoc.ActiveView = view3D;
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("ex", ex.ToString());
                            ts.RollBack();
                        }
                        //Util.ErrorMsg("You must be in a 3D view to export.");
                    }
                    #endregion

                    ExportView3D(doc.ActiveView as View3D, CreatFilePath(doc), objlibraryAsset);

                    //通过占位文件关闭当前文件
                    var docPlaceholder = commandData.Application.OpenAndActivateDocument(placeholderFile);
                    doc.Close(false);
                }
                MessageBox.Show("导出成功!", "通知");
            }
            return(Result.Succeeded);
        }
Beispiel #2
0
        /// <summary>
        /// 加载外观元素到文档中
        /// </summary>
        /// <param name="revitApp"></param>
        public static void loadAppearance(Autodesk.Revit.ApplicationServices.Application revitApp, Document doc, Material mat)
        {
            AssetSet theAssets = revitApp.get_Assets(AssetType.Appearance);

            foreach (Asset theAsset in theAssets)
            {
                // AppearanceAssetElement assetElem = AppearanceAssetElement.Create(doc, "haipi", theAsset);

                // FilteredElementCollector cotr = new FilteredElementCollector(doc);
                //     IEnumerable<AppearanceAssetElement> allApperar = cotr.OfClass(typeof(AppearanceAssetElement)).Cast<AppearanceAssetElement>();
                // mat.AppearanceAssetId = allApperar.First<AppearanceAssetElement>().Id;
            }
        }
Beispiel #3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = commandData.Application.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Document doc = uidoc.Document;

            AssetSet objlibraryAsset = app.get_Assets(AssetType.Appearance);

            ///判断是否为空视图
            View3D view = doc.ActiveView as View3D;

            if (null == view)
            {
                Util.ErrorMsg("You must be in a 3D view to export.");
            }
            try
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();
                dialog.Description = "请选择文件保存路径";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    foldPath = dialog.SelectedPath;
                }
                string filename = doc.PathName;
                if (0 == filename.Length)
                {
                    filename = doc.Title;
                }
                filename = Path.GetFileNameWithoutExtension(filename) + ".obj";
                string subPath = foldPath + "\\" + Path.GetFileNameWithoutExtension(filename);
                if (!Directory.Exists(subPath))
                {
                    Directory.CreateDirectory(subPath);
                }
                filename = Path.Combine(subPath + "\\" + filename);

                ExportView3D(doc.ActiveView as View3D, filename, objlibraryAsset);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(Result.Succeeded);
        }