public static Dictionary <string, object> ExportZonesToGBXML(string FilePath, List <ElementId> ZoneIds, List <AbstractFamilyInstance> MassShadingInstances, Boolean Run = false) { // Local variables Boolean IsSuccess = false; string FileName = string.Empty; string Folder = string.Empty; // Check if path and directory valid if (System.String.IsNullOrEmpty(FilePath) || FilePath == "No file selected.") { throw new Exception("No File selected !"); } FileName = Path.GetFileNameWithoutExtension(FilePath); Folder = Path.GetDirectoryName(FilePath); // Check if Directory Exists if (!Directory.Exists(Folder)) { throw new Exception("Folder doesn't exist. Input valid Directory Path!"); } //make RUN? inputs set to True mandatory if (Run == false) { throw new Exception("Set 'Connect' to True!"); } //local varaibles Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document; //enable the analytical model in the document if it isn't already try { PrepareEnergyModel.ActivateEnergyModel(RvtDoc); } catch (Exception) { throw new Exception("Something went wrong when trying to enable the energy model."); } //convert the ElementId wrapper instances to actual Revit ElementId objects List <Autodesk.Revit.DB.ElementId> outZoneIds = ZoneIds.Select(e => new Autodesk.Revit.DB.ElementId(e.InternalId)).ToList(); // get shading Ids List <Autodesk.Revit.DB.ElementId> ShadingIds = new List <Autodesk.Revit.DB.ElementId>(); for (int i = 0; i < MassShadingInstances.Count(); i++) { // make sure input mass is valid as a shading if (MassInstanceUtils.GetMassLevelDataIds(RvtDoc, MassShadingInstances[i].InternalElement.Id).Count() > 0) { throw new Exception("Item " + i.ToString() + " in MassShadingInstances has mass floors assigned. Remove the mass floors and try again."); } ShadingIds.Add(MassShadingInstances[i].InternalElement.Id); } if (ShadingIds.Count != 0) { // Create gbXML with shadings MassGBXMLExportOptions gbXmlExportOptions = new MassGBXMLExportOptions(outZoneIds.ToList(), ShadingIds); // two constructors RvtDoc.Export(Folder, FileName, gbXmlExportOptions); } else { // Create gbXML MassGBXMLExportOptions gbXmlExportOptions = new MassGBXMLExportOptions(outZoneIds.ToList()); // two constructors RvtDoc.Export(Folder, FileName, gbXmlExportOptions); } // if the file exists return success message if not return failed message string path = Path.Combine(Folder, FileName + ".xml"); if (System.IO.File.Exists(path)) { // Modify the xml Program Info element, aithorize the XmlDocument doc = new XmlDocument(); doc.Load(path); // EE: There must be a shorter way ! XmlNode node = doc.DocumentElement; foreach (XmlNode node1 in node.ChildNodes) { foreach (XmlNode node2 in node1.ChildNodes) { if (node2.Name == "ProgramInfo") { foreach (XmlNode childnode in node2.ChildNodes) { if (childnode.Name == "ProductName") { string productname = "Dynamo _ " + childnode.InnerText; childnode.InnerText = productname; } } } } } doc.Save(path); IsSuccess = true; } string message = "Failed to create gbXML file!"; if (IsSuccess) { message = "Success! The gbXML file was created"; } else { path = string.Empty; } return(new Dictionary <string, object> { { "report", message }, { "gbXMLPath", path } }); }
public static Dictionary <string, object> ExportMassToGBXML(string FilePath, AbstractFamilyInstance MassFamilyInstance, List <AbstractFamilyInstance> MassShadingInstances, Boolean Run = false) { Boolean IsSuccess = false; string FileName = Path.GetFileNameWithoutExtension(FilePath); string Folder = Path.GetDirectoryName(FilePath); //make RUN? inputs set to True mandatory if (Run == false) { throw new Exception("Set 'Connect' to True!"); } //local variables Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document; //enable the analytical model in the document if it isn't already try { PrepareEnergyModel.ActivateEnergyModel(RvtDoc); } catch (Exception) { throw new Exception("Something went wrong when trying to enable the energy model."); } //get the id of the analytical model associated with that mass Autodesk.Revit.DB.ElementId myEnergyModelId = MassEnergyAnalyticalModel.GetMassEnergyAnalyticalModelIdForMassInstance(RvtDoc, MassFamilyInstance.InternalElement.Id); MassEnergyAnalyticalModel mea = (MassEnergyAnalyticalModel)RvtDoc.GetElement(myEnergyModelId); ICollection <Autodesk.Revit.DB.ElementId> ZoneIds = mea.GetMassZoneIds(); // get shading Ids List <Autodesk.Revit.DB.ElementId> ShadingIds = new List <Autodesk.Revit.DB.ElementId>(); for (int i = 0; i < MassShadingInstances.Count(); i++) { // make sure input mass is valid as a shading if (MassInstanceUtils.GetMassLevelDataIds(RvtDoc, MassShadingInstances[i].InternalElement.Id).Count() > 0) { throw new Exception("Item " + i.ToString() + " in MassShadingInstances has mass floors assigned. Remove the mass floors and try again."); } ShadingIds.Add(MassShadingInstances[i].InternalElement.Id); } if (ShadingIds.Count != 0) { MassGBXMLExportOptions gbXmlExportOptions = new MassGBXMLExportOptions(ZoneIds.ToList(), ShadingIds); // two constructors RvtDoc.Export(Folder, FileName, gbXmlExportOptions); } else { MassGBXMLExportOptions gbXmlExportOptions = new MassGBXMLExportOptions(ZoneIds.ToList()); // two constructors RvtDoc.Export(Folder, FileName, gbXmlExportOptions); } // if the file exists return success message if not return failed message string path = Path.Combine(Folder, FileName + ".xml"); if (System.IO.File.Exists(path)) { // Modify the xml Program Info element, aithorize the XmlDocument doc = new XmlDocument(); doc.Load(path); // EE: There must be a shorter way ! XmlNode node = doc.DocumentElement; foreach (XmlNode node1 in node.ChildNodes) { foreach (XmlNode node2 in node1.ChildNodes) { if (node2.Name == "ProgramInfo") { foreach (XmlNode childnode in node2.ChildNodes) { if (childnode.Name == "ProductName") { string productname = "Dynamo _ " + childnode.InnerText; childnode.InnerText = productname; } } } } } //doc.DocumentElement.Attributes["ProgramInfo"].ChildNodes[1].Value += "Dynamo "; doc.Save(path); IsSuccess = true; } string message = "Failed to create gbXML file!"; if (IsSuccess) { message = "Success! The gbXML file was created"; } else { path = string.Empty; } // Populate Output Values return(new Dictionary <string, object> { { "report", message }, { "gbXMLPath", path } }); }
public static Dictionary <string, object> SetEnergySettings(string BldgTyp = "", double GlzPer = 0, double ShadeDepth = 0, double SkylightPer = 0, string HVACSystem = "", string OSchedule = "") { //Get active document Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document; //enable the analytical model in the document if it isn't already try { PrepareEnergyModel.ActivateEnergyModel(RvtDoc); } catch (Exception) { throw new Exception("Something went wrong when trying to enable the energy model."); } //Load the default energy setting from the active Revit instance EnergyDataSettings myEnergySettings = Autodesk.Revit.DB.Analysis.EnergyDataSettings.GetFromDocument(RvtDoc); //make sure we are in a transaction TransactionManager.Instance.EnsureInTransaction(RvtDoc); if (!string.IsNullOrEmpty(BldgTyp)) { Autodesk.Revit.DB.Analysis.gbXMLBuildingType type; try { type = (Autodesk.Revit.DB.Analysis.gbXMLBuildingType)Enum.Parse(typeof(Autodesk.Revit.DB.Analysis.gbXMLBuildingType), BldgTyp); } catch (Exception) { throw new Exception("Building type is not found"); } myEnergySettings.BuildingType = type; } if (!string.IsNullOrEmpty(HVACSystem)) { Autodesk.Revit.DB.Analysis.gbXMLBuildingHVACSystem type; try { type = (Autodesk.Revit.DB.Analysis.gbXMLBuildingHVACSystem)Enum.Parse(typeof(Autodesk.Revit.DB.Analysis.gbXMLBuildingHVACSystem), HVACSystem); } catch (Exception) { throw new Exception("HVAC system is not found"); } myEnergySettings.BuildingHVACSystem = type; } if (!string.IsNullOrEmpty(OSchedule)) { Autodesk.Revit.DB.Analysis.gbXMLBuildingOperatingSchedule type; try { type = (Autodesk.Revit.DB.Analysis.gbXMLBuildingOperatingSchedule)Enum.Parse(typeof(Autodesk.Revit.DB.Analysis.gbXMLBuildingOperatingSchedule), OSchedule); } catch (Exception) { throw new Exception("Operating Schedule is not found"); } myEnergySettings.BuildingOperatingSchedule = type; } if (GlzPer > 0.0 && GlzPer <= 1.0) { try { myEnergySettings.PercentageGlazing = GlzPer; } catch (Exception) { throw new Exception("The Glazing Percentage input range should be 0 - 1"); } } if (ShadeDepth > 0.0) { myEnergySettings.IsGlazingShaded = true; myEnergySettings.ShadeDepth = ShadeDepth * UnitConverter.DynamoToHostFactor; } else { myEnergySettings.IsGlazingShaded = false; myEnergySettings.ShadeDepth = 0; } // add skylight percentage myEnergySettings.PercentageSkylights = SkylightPer; //done with the transaction TransactionManager.Instance.TransactionTaskDone(); // Report string report = "Building type is " + Enum.GetName(typeof(gbXMLBuildingType), myEnergySettings.BuildingType) + ".\n" + "Glazing percentage is set to " + myEnergySettings.PercentageGlazing.ToString() + ".\n" + "Shading depth is " + ShadeDepth.ToString() + ".\n" + "Current HVAC system is " + Enum.GetName(typeof(gbXMLBuildingHVACSystem), myEnergySettings.BuildingHVACSystem) + ".\n" + "Current Operating Schedule is " + Enum.GetName(typeof(gbXMLBuildingOperatingSchedule), myEnergySettings.BuildingOperatingSchedule) + "."; return(new Dictionary <string, object> { { "EnergySettings", myEnergySettings }, { "report", report } }); }
public static Dictionary <string, object> ExportZonesToGBXML(string FilePath, List <ElementId> ZoneIds, Boolean Run = false) { Boolean IsSuccess = false; string FileName = Path.GetFileNameWithoutExtension(FilePath); string Folder = Path.GetDirectoryName(FilePath); //make RUN? inputs set to True mandatory if (Run == false) { throw new Exception("Set 'Connect' to True!"); } //local varaibles Document RvtDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument.Document; //enable the analytical model in the document if it isn't already try { PrepareEnergyModel.ActivateEnergyModel(RvtDoc); } catch (Exception) { throw new Exception("Something went wrong when trying to enable the energy model."); } //convert the ElementId wrapper instances to actual Revit ElementId objects List <Autodesk.Revit.DB.ElementId> outZoneIds = ZoneIds.Select(e => new Autodesk.Revit.DB.ElementId(e.InternalId)).ToList(); // Create gbXML MassGBXMLExportOptions gbXmlExportOptions = new MassGBXMLExportOptions(outZoneIds); RvtDoc.Export(Folder, FileName, gbXmlExportOptions); // if the file exists return success message if not return failed message string path = Path.Combine(Folder, FileName + ".xml"); if (System.IO.File.Exists(path)) { // Modify the xml Program Info element, aithorize the XmlDocument doc = new XmlDocument(); doc.Load(path); // EE: There must be a shorter way ! XmlNode node = doc.DocumentElement; foreach (XmlNode node1 in node.ChildNodes) { foreach (XmlNode node2 in node1.ChildNodes) { if (node2.Name == "ProgramInfo") { foreach (XmlNode childnode in node2.ChildNodes) { if (childnode.Name == "ProductName") { string productname = "Dynamo _ " + childnode.InnerText; childnode.InnerText = productname; } } } } } doc.Save(path); IsSuccess = true; } string message = "Failed to create gbXML file!"; if (IsSuccess) { message = "Success! The gbXML file was created"; } else { path = string.Empty; } return(new Dictionary <string, object> { { "report", message }, { "gbXMLPath", path } }); }