public static Dictionary <string, Room> FromAndToRooms(Revit.Elements.FamilyInstance familyInstance, Revit.Elements.Element phase) { Autodesk.Revit.DB.FamilyInstance uwFi = familyInstance.InternalElement as Autodesk.Revit.DB.FamilyInstance; Autodesk.Revit.DB.Phase uwPhase = phase.InternalElement as Phase; Room fromRoom = null; Room toRoom = null; var tempFromRoom = uwFi.get_FromRoom(uwPhase); var tempToRoom = uwFi.get_ToRoom(uwPhase); if (tempFromRoom != null) { fromRoom = tempFromRoom.ToDSType(true) as Room; } if (tempToRoom != null) { toRoom = tempToRoom.ToDSType(true) as Room; } var returnDict = new Dictionary <string, Room> { { "FromRoom", fromRoom }, { "ToRoom", toRoom }, }; return(returnDict); }
protected override void TrySolveInstance(IGH_DataAccess DA) { // grab input family instance DB.FamilyInstance famInst = default; if (!DA.GetData("Family Instance", ref famInst)) { return; } // grab input phase if provided DB.Phase phase = default; DA.GetData("Phase", ref phase); if (phase is null) { DA.SetData("FromRoom", famInst.FromRoom); DA.SetData("ToRoom", famInst.ToRoom); DA.SetData("Room", famInst.Room); DA.SetData("Space", famInst.Space); } else { DA.SetData("FromRoom", famInst.get_FromRoom(phase)); DA.SetData("ToRoom", famInst.get_ToRoom(phase)); DA.SetData("Room", famInst.get_Room(phase)); DA.SetData("Space", famInst.get_Space(phase)); } }
public static Dictionary <string, List <Revit.Elements.Element> > GetToFromRoom(List <Revit.Elements.Element> FamilyInstance, Revit.Elements.Element Phase) { List <Revit.Elements.Element> toRooms = new List <Revit.Elements.Element>(); List <Revit.Elements.Element> fromRooms = new List <Revit.Elements.Element>(); ElementId phaseId = Spring.Elements.UnwrapElement(Phase); try { Autodesk.Revit.DB.Phase phase = DocumentManager.Instance.CurrentDBDocument.GetElement(phaseId) as Autodesk.Revit.DB.Phase; try { foreach (Revit.Elements.Element v in FamilyInstance) { ElementId elemId = Spring.Elements.UnwrapElement(v); Autodesk.Revit.DB.FamilyInstance elements = DocumentManager.Instance.CurrentDBDocument.GetElement(elemId) as Autodesk.Revit.DB.FamilyInstance; Autodesk.Revit.DB.Architecture.Room fromRoom = elements.get_FromRoom(phase); Autodesk.Revit.DB.Architecture.Room toRoom = elements.get_ToRoom(phase); toRooms.Add(toRoom.ToDSType(true)); fromRooms.Add(fromRoom.ToDSType(true)); } ; } catch (Exception ex) { toRooms.Add(null); fromRooms.Add(null); } } catch (Exception ex) { throw ex; } return(new Dictionary <string, List <Revit.Elements.Element> > { { "From Room", fromRooms }, { "To Room", toRooms } }); }
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; } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { List <string> materialsUsed = new List <string>(); MaterialsVM myVM = new MaterialsVM(); var doc = commandData.Application.ActiveUIDocument.Document; var cats = new List <BuiltInCategory> { BuiltInCategory.OST_StructuralFoundation, BuiltInCategory.OST_StructuralFraming, BuiltInCategory.OST_StructuralColumns, BuiltInCategory.OST_Floors, BuiltInCategory.OST_EdgeSlab, BuiltInCategory.OST_Walls, BuiltInCategory.OST_Ramps, BuiltInCategory.OST_Stairs, BuiltInCategory.OST_Windows, BuiltInCategory.OST_Doors }; //enable volume computations using (Transaction t = new Transaction(doc, "Turn on vol calc")) { t.Start(); var settings = AreaVolumeSettings.GetAreaVolumeSettings(doc); settings.ComputeVolumes = true; t.Commit(); } foreach (var cat in cats) { var catFilters = new List <ElementFilter> { new ElementCategoryFilter(cat) }; var filter = new LogicalOrFilter(catFilters); var structures = new FilteredElementCollector(doc) .WherePasses(filter) .ToElements(); double vol = 0; int counter = 0; foreach (var item in structures) { var mat = item.LookupParameter("Structural Material"); if (mat == null) { var itemType = doc.GetElement(item.GetTypeId()); if (itemType != null) { mat = itemType.LookupParameter("Structural Material"); } } var volParam = item.LookupParameter("Volume"); var elemType = item.GetTypeId(); string name = ""; var elemTy = doc.GetElement(elemType) as ElementType; if (elemTy != null) { name = elemTy.FamilyName + ": " + elemTy.Name; } string matName = ""; if (volParam != null) { if (mat != null) { matName = mat.AsValueString(); if (!materialsUsed.Contains(matName)) { materialsUsed.Add(matName); } } var test = volParam.AsValueString(); double metricVol = volParam.AsDouble() * _cubicFtToM; vol += metricVol; counter++; myVM.AddElement(name, metricVol, matName, doc, cat); } } } CarbonCalculator.ElementSet myset = new CarbonCalculator.ElementSet("Category", "Material", "Level", "Phase", "Design Option"); Window optionsWindow = new Window(); ImportOptionsVM optionsVM = new ImportOptionsVM(optionsWindow); optionsWindow.Content = new CarbonCalculator.ImportOptions(); optionsWindow.DataContext = optionsVM; optionsWindow.Width = 300; optionsWindow.Height = 250; optionsWindow.ShowDialog(); int faceCounter = 0; foreach (var cat in cats) { var counter = 0; var catFilters = new List <ElementFilter> { new ElementCategoryFilter(cat) }; var revitCat = Category.GetCategory(doc, cat); var filter = new LogicalOrFilter(catFilters); var structures = new FilteredElementCollector(doc) .WherePasses(filter) .ToElements(); List <Element> AllElem = new FilteredElementCollector(doc) .WhereElementIsViewIndependent() .WhereElementIsNotElementType() .Where(e => e.IsPhysicalElement()) .ToList <Element>(); double vol = 0; foreach (var item in structures) { var mat = item.LookupParameter("Structural Material"); if (mat == null) { var itemType = doc.GetElement(item.GetTypeId()); if (itemType != null) { mat = itemType.LookupParameter("Structural Material"); } } var volParam = item.LookupParameter("Volume"); var elemType = item.GetTypeId(); string name = ""; var elemTy = doc.GetElement(elemType) as ElementType; if (elemTy != null) { name = elemTy.FamilyName + ": " + elemTy.Name; } string lvlstr = ""; var lvl = item.LevelId; Level level = doc.GetElement(lvl) as Level; if (level != null) { lvlstr = level.Name; } string phaseName = ""; Autodesk.Revit.DB.Phase phaseCreated = doc.GetElement(item.CreatedPhaseId) as Phase; if (phaseCreated == null) { phaseName = ""; } else { phaseName = phaseCreated.Name; } string designOptionName = ""; Autodesk.Revit.DB.DesignOption designOption = null; if (item.DesignOption != null) { designOption = doc.GetElement(item.DesignOption.Id) as DesignOption; } if (designOption == null) { designOptionName = "Main"; } else { designOptionName = designOption.Name; } var mats = item.GetMaterialIds(false); if (mats.Count > 1 && ((optionsVM.ExplodeFloors && cat == BuiltInCategory.OST_Floors) || (optionsVM.ExplodeWalls && cat == BuiltInCategory.OST_Walls))) { foreach (var material in mats) { var materialName = (doc.GetElement(material) as Material).Name; var materialVol = item.GetMaterialVolume(material); var materialArea = item.GetMaterialArea(material, false); double metricVol = materialVol * _cubicFtToM; double metricArea = materialArea * _squareFtToM; myset.AddElement(new CarbonCalculator.Element(name + " " + materialName, metricVol, metricArea, "Revit" + counter, revitCat.Name, materialName, lvlstr, phaseName, designOptionName)); counter++; } } else if (mats.Count == 1) { var material = mats.First(); var materialName = (doc.GetElement(material) as Material).Name; var materialVol = item.GetMaterialVolume(material); var materialArea = item.GetMaterialArea(material, false); double metricVol = materialVol * _cubicFtToM; double metricArea = materialArea * _squareFtToM; myset.AddElement(new CarbonCalculator.Element(name, metricVol, metricArea, "Revit" + counter, revitCat.Name, materialName, lvlstr, phaseName, designOptionName)); counter++; } else if (mats.Count > 1) { var material = mats.First(); var materialName = (doc.GetElement(material) as Material).Name; double metricVol = 0; if (volParam != null) { metricVol = volParam.AsDouble() * _cubicFtToM; } var materialArea = item.GetMaterialArea(material, false); double metricArea = materialArea * _squareFtToM; myset.AddElement(new CarbonCalculator.Element(name, metricVol, metricArea, "Revit" + counter, revitCat.Name, "Mixed materials", lvlstr, phaseName, designOptionName)); counter++; } faceCounter += getGeometry(item); //string matName = ""; //if (volParam != null) //{ // if (mat != null) // { // matName = mat.AsValueString(); // } // double metricVol = volParam.AsDouble() * _cubicFtToM; // myset.AddElement(new CarbonCalculator.Element(name, metricVol, "Revit" + counter, revitCat.Name, matName, lvlstr, phaseName, designOptionName)); //} //counter++; } } var control = new CarbonCalculator.UserControl1(); Window carbonWindow = new Window() { Content = control, DataContext = new CarbonCalculator.AppVM(myset) }; carbonWindow.ShowDialog(); return(Result.Succeeded); }
/// <summary> /// Retrive family instance hosted in boundary elements /// This is the base function for Windows and Doors /// </summary> /// <param name="cat">The category of hosted elements</param> /// <returns></returns> private List <FamilyInstance> BoundaryFamilyInstance(DB.BuiltInCategory cat) { List <FamilyInstance> output = new List <FamilyInstance>(); //the document of the room DB.Document doc = InternalElement.Document; // DocumentManager.Instance.CurrentDBDocument; //Find boundary elements and their associated document List <DB.ElementId> boundaryElements = new List <DB.ElementId>(); List <DB.Document> boundaryDocuments = new List <DB.Document>(); foreach (DB.BoundarySegment segment in InternalBoundarySegments) { DB.Element boundaryElement = doc.GetElement(segment.ElementId); if (boundaryElement.GetType() == typeof(DB.RevitLinkInstance)) { DB.RevitLinkInstance linkInstance = boundaryElement as DB.RevitLinkInstance; boundaryDocuments.Add(linkInstance.GetLinkDocument()); boundaryElements.Add(segment.LinkElementId); } else { boundaryDocuments.Add(doc); boundaryElements.Add(segment.ElementId); } } // Create a category filter DB.ElementCategoryFilter filter = new DB.ElementCategoryFilter(cat); // Apply the filter to the elements in these documents, // Use shortcut WhereElementIsNotElementType() to find family instances in all boundary documents boundaryDocuments = boundaryDocuments.Distinct().ToList(); List <DB.FamilyInstance> familyInstances = new List <DB.FamilyInstance>(); foreach (DB.Document boundaryDocument in boundaryDocuments) { DB.FilteredElementCollector collector = new DB.FilteredElementCollector(boundaryDocument); familyInstances.AddRange(collector.WherePasses(filter).WhereElementIsNotElementType().ToElements().Cast <DB.FamilyInstance>().ToList()); } //Find all family instance hosted on a boundary element IEnumerable <DB.FamilyInstance> boundaryFamilyInstances = familyInstances.Where(s => boundaryElements.Contains(s.Host.Id)); //loop on these boundary family instance to find to and from room foreach (DB.FamilyInstance boundaryFamilyInstance in boundaryFamilyInstances) { DB.Phase familyInstancePhase = boundaryFamilyInstance.Document.GetElement(boundaryFamilyInstance.CreatedPhaseId) as DB.Phase; if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase) != null) { if (boundaryFamilyInstance.get_FromRoom(familyInstancePhase).Id == InternalRoom.Id) { output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance); continue; } } if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase) != null) { if (boundaryFamilyInstance.get_ToRoom(familyInstancePhase).Id == InternalRoom.Id) { output.Add(ElementWrapper.ToDSType(boundaryFamilyInstance, true) as FamilyInstance); } } } output = output.Distinct().ToList(); return(output); }
private void MakeConvertToHSF(UIApplication app, UIDocument doc) { FilteredElementCollector collector = new FilteredElementCollector(doc.Document); ICollection <Element> AllElements = collector.WhereElementIsNotElementType().ToElements(); //fr_status.StartProgressBar(AllElements.Count); ArrayList objs = new ArrayList(); Autodesk.Revit.DB.GeometryElement GeomElem = null; Autodesk.Revit.DB.GeometryElement CatElem = null; //Autodesk.Revit.DB.Options Opts= new Options(); Autodesk.Revit.DB.Options geomOp = app.Application.Create.NewGeometryOptions(); writeData.Init(ExportFileName); Autodesk.Revit.DB.GeometryInstance instance = null; Material materialElement = null; fr_Progress.StartProgressBar(AllElements.Count); int iElementCount = 0; foreach (Element element in AllElements) { fr_Progress.AddValueProgressBar(iElementCount++); instance = null; //fr_status.UpDateProgressBar(iCurrentElementCount++); Autodesk.Revit.DB.Phase phaseCreated = element.PhaseCreated; if (null != phaseCreated) { if (element is TopographySurface) { //materialElement = element.Category.Material; foreach (Parameter par in element.Parameters) { if ("Material" == par.Definition.Name) { ElementId Id = par.AsElementId(); if (-1 != Id.IntegerValue) { Element eleMat = doc.Document.get_Element(Id); materialElement = eleMat as Material; } else { materialElement = element.Category.Material; } //materialElement = materials.get_Item(Id); } } } GeomElem = element.get_Geometry(geomOp); if (null == GeomElem) { TopographySurface TyPo = element as TopographySurface; if (null == TyPo) { HostObject HostOb = element as HostObject; if (null == HostOb) { }//if (null == HostOb) else { GeomElem = HostOb.get_Geometry(geomOp); } }//if (null == TyPo) else { GeomElem = TyPo.get_Geometry(geomOp); } }//if (null == GeomElem) if (null != GeomElem) { HandleGeometryElement(GeomElem, ref instance, doc, materialElement); }//if (null != GeomElem) if (null != GeomElem || null != CatElem) { SendData(element, instance); //objs.Add(element); Lid_Vertices.Clear(); Lid_Normals.Clear(); Lid_TextureCoords.Clear(); Lid_FeatureMaterial.Clear(); Liu_Indices.Clear(); Liu_FeatureIndex.Clear(); } //if (null != GeomElem) } //if (null != phaseCreated) } // foreach (Element element in AllElements) //System.Diagnostics.Trace.WriteLine(AllElements.Count.ToString()); //CF_WriterForm form = new CF_WriterForm(objs); //form.ShowDialog(); //using (MaterialsForm dlg = new MaterialsForm(materialsManager,commandData)) //{ }