//private progress fr_status = new progress(); #endregion IExternalCommand Members Implementation public Result HandleData(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //Retrieves the current active project. Autodesk.Revit.UI.UIApplication app = commandData.Application; UIDocument doc = app.ActiveUIDocument; //revitApp = app Autodesk.Revit.DB.View view = commandData.View; String ApplicationName = doc.Document.Title; String WievName = view.Document.Title; //Initialize RenderAppearancesForm CF_WriterForm form = new CF_WriterForm(); form.ExportFileName = ApplicationName; if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return(Autodesk.Revit.UI.Result.Cancelled); } ExportFileName = form.ExportFileName; // Generate a object for Revit materials management. //MaterialsMgr materialsManager = new MaterialsMgr(doc, app); fr_Progress = new Frm_Progress(); // Feed a MaterialsMgr to a dialog Application.DoEvents(); //fr_Progress.progressing_Shown(this, what); fr_Progress.Show(); fr_Progress.prosessProgressBar(ExportFileName); MakeConvertToHSF(app, doc); EndProsess(); fr_Progress.Close(); //fr_status.Close(); // Revit need to do nothing. return(Autodesk.Revit.UI.Result.Succeeded); }//try catch (Exception e) { fr_Progress.Close(); // Exception rised, report it by revit error reporting mechanism. message = "Execute/MakeConvertToHSF fails for Reason:" + Environment.NewLine + e.ToString();; File.AppendAllText(@"C:\CadFaster\Revit\ExeWriter_log.txt", message); return(Autodesk.Revit.UI.Result.Failed); } }
public void execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { //Retrieves the current active project. Autodesk.Revit.UI.UIApplication app = commandData.Application; UIDocument doc = app.ActiveUIDocument; string ExecutingAssemblyPath = Assembly.GetExecutingAssembly().Location; string DllAssemblyPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ExeWriter)).CodeBase); //revitApp = app Autodesk.Revit.DB.View view = commandData.View; String ApplicationName = doc.Document.Title; String WievName = view.Document.Title; //Initialize RenderAppearancesForm //RenderAppearancesFrom.Asssets = app.Application.get_Assets(Autodesk.Revit.Utility.AssetType.Appearance); // Generate a object for Revit materials management. //MaterialsMgr materialsManager = new MaterialsMgr(doc, app); // Feed a MaterialsMgr to a dialog. FilteredElementCollector collector = new FilteredElementCollector(doc.Document); ICollection <Element> AllElements = collector.WhereElementIsNotElementType().ToElements(); ArrayList objs = new ArrayList(); Autodesk.Revit.DB.GeometryElement GeomElem; //Autodesk.Revit.DB.Options Opts= new Options(); Autodesk.Revit.DB.Options geomOp = app.Application.Create.NewGeometryOptions(); writeData.Init(ref message); Autodesk.Revit.DB.GeometryInstance instance = null; foreach (Element element in AllElements) { Autodesk.Revit.DB.Phase phaseCreated = element.PhaseCreated; if (null != phaseCreated) { //Get Geometry element GeomElem = element.get_Geometry(geomOp); if (null == GeomElem) { TopographySurface TyPo = element as TopographySurface; if (null == TyPo) { HostObject HostOb = element as HostObject; if (null == HostOb) { } else { GeomElem = HostOb.get_Geometry(geomOp); } } else { GeomElem = TyPo.get_Geometry(geomOp); } } //Geometry must be if (null != GeomElem) { //GeomElem = element.get_Geometry(Opts); foreach (GeometryObject geomObj in GeomElem.Objects) { uint uCurves = 0; Solid geomSolid = geomObj as Solid; Curve geomCurve = geomObj as Curve; Mesh geomMesh = geomObj as Mesh; Edge geomEdge = geomObj as Edge; instance = geomObj as Autodesk.Revit.DB.GeometryInstance; if (null != instance) { foreach (GeometryObject InstanObj in instance.SymbolGeometry.Objects) { geomSolid = InstanObj as Solid; geomMesh = InstanObj as Mesh; geomEdge = InstanObj as Edge; geomCurve = InstanObj as Curve; if (geomCurve != null) { // transfrom the curve to make it in the instance's coordinate space geomCurve = geomCurve.get_Transformed(instance.Transform); } if (geomSolid != null) { // transfrom the curve to make it in the instance's coordinate space DataProcess(geomSolid, instance); } } } if (null != geomCurve) { uCurves++; } if (null != geomSolid) { DataProcess(geomSolid, instance); } } SendData(element, instance); objs.Add(element); d_VerticesList.Clear(); d_NormalsList.Clear(); d_TextureCoordsList.Clear(); d_FeatureMaterialList.Clear(); u_IndicesList.Clear(); u_FeaturesIndList.Clear(); } } } System.Diagnostics.Trace.WriteLine(AllElements.Count.ToString()); CF_WriterForm form = new CF_WriterForm(objs); //form.ShowDialog(); //using (MaterialsForm dlg = new MaterialsForm(materialsManager,commandData)) //{ form.ExportFileName = ApplicationName; if (form.ShowDialog() != System.Windows.Forms.DialogResult.Cancel) { ExportFileName = form.ExportFileName; EndProsess(ref message); // Revit need to do nothing. //return Autodesk.Revit.UI.Result.Cancelled; } else { // Done some action, ask revit to execute it. //return Autodesk.Revit.UI.Result.Succeeded; } //} } catch (Exception e) { // Exception rised, report it by revit error reporting mechanism. message = e.ToString(); File.AppendAllText(@"C:\CadFaster\Revit\CF_WriterDLLs_log.txt", message); //return Autodesk.Revit.UI.Result.Failed; } }