//*****************************Get_ElementAndParamValues()***************************** public Dictionary <string, Element> Get_ElementAndParamValues(Document doc) { LibraryGetItems library = new LibraryGetItems(); // Get Structural foundation elements FilteredElementCollector dcs = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_StructuralFoundation); //Build a Dictonary of elements and Keys of ID. int n = dcs.GetElementCount(); Dictionary <string, Element> d = new Dictionary <string, Element>(n); foreach (Element dc in dcs) { try { // Get SOM ID parameter. var SOMIDParam = dc.LookupParameter("SOM ID"); string parameterVaule = library.GetParameterValue(SOMIDParam); //Only add elements with id values. if (parameterVaule != null) { d.Add(parameterVaule, dc); } } catch { } } return(d); }
public void SortSheets(Document doc) { LibraryGetItems lib = new LibraryGetItems(); FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)); List <ViewSheet> sheets = new List <ViewSheet>(); foreach (ViewSheet vs in collector) { sheets.Add(vs); } sheets.RemoveAll(x => x.SheetNumber.StartsWith("Z") && x.SheetNumber.StartsWith("Q")); sheets.RemoveAll(x => x.get_Parameter(BuiltInParameter.RBS_PANEL_SCHEDULE_SHEET_APPEARANCE_PARAM).AsValueString() == "No"); var RegexPatt = @"([0-9]|[^-.S])"; int sortNumber = 0; foreach (ViewSheet s in sheets) { var sheetNumRegx = Regex.Match(s.SheetNumber, RegexPatt, RegexOptions.None); string sheetNumber = sheetNumRegx.ToString(); char[] c = sheetNumber.ToCharArray(); int Value = 1000; while (Value > 0) { for (int i = 0; i <= c.Length; i++) { string st = c[i].ToString(); bool check = checkNumber(st); if (check == true) { int intergerValue = Convert.ToInt32(c[i]); sortNumber = sortNumber + (intergerValue * Value); } if (check == false) { int x = letterValue(st, Value); sortNumber = sortNumber + (x * Value); } Value = Value - 100; } } } }
public List <ObjDoors> CurrentModelDoors(Document doc) { List <ObjDoors> currentModelDoors = new List <ObjDoors>(); { LibraryGetItems library = new LibraryGetItems(); List <Element> doors = library.GetFamilyElement(doc, BuiltInCategory.OST_Doors); foreach (Element door in doors) { LocationPoint location = door.Location as LocationPoint; // Get level id parameter Parameter levelId = door.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM); // Get level value of id parameter string parmLevel_Id = library.GetParameterValue(levelId); // get all levels in current model List <Level> levels = library.GetLevels(doc); // find and match of door level and current model level to get level Level levelName = levels.Find(x => Convert.ToString(x.Id.IntegerValue) == parmLevel_Id); FamilySymbol familySymbol = library.GetFamilySymbol(doc, door.Name, BuiltInCategory.OST_Doors); // find unique identification of door //1bb68248-4b34-4821-9be3-8ddf47852209 = SOM ID var SOMIDParam = door.LookupParameter("SOM ID"); string doorId = library.GetParameterValue(SOMIDParam); ObjDoors ObjectDoor = new ObjDoors(); ObjectDoor.doorElement = door; ObjectDoor.doorName = door.Name; ObjectDoor.doorId = doorId; ObjectDoor.doorWidth = familySymbol.get_Parameter(BuiltInParameter.FAMILY_ROUGH_WIDTH_PARAM).AsDouble(); ObjectDoor.doorHeight = familySymbol.get_Parameter(BuiltInParameter.FAMILY_ROUGH_HEIGHT_PARAM).AsDouble(); ObjectDoor.X = location.Point.X; ObjectDoor.Y = location.Point.Y; ObjectDoor.Z = location.Point.Z; ObjectDoor.level = levelName; currentModelDoors.Add(ObjectDoor); } } return(currentModelDoors); }
//*****************************DoorProgram()***************************** public List <ObjDoors> DoorProgram(Document doc, UIDocument uidoc, List <ObjDoors> List_DoorsLinkedModel, List <ObjDoors> List_DoorsCurrentModel) { List <ObjDoors> ListObjDoors = new List <ObjDoors>(); // logger object. Logger logger = LogManager.GetLogger("program"); ExportExcel exportExcel = new ExportExcel(); // Get all levels and add to field. LibraryGetItems libGetItems = new LibraryGetItems(); _ListLevels = libGetItems.GetLevels(doc); foreach (ObjDoors linkedDoor in List_DoorsLinkedModel) { // check to see if door exist ObjDoors DoorFound = List_DoorsCurrentModel.Find(x => x.doorId == linkedDoor.doorId); // if it doesn't exist it will create a new door. if (DoorFound == null) { try { ObjDoors door = CreateDoors(uidoc, doc, linkedDoor); ListObjDoors.Add(door); } catch (Exception e) { string ErrMessage = e.Message; } } // if door exist the check to see if the location is the same and type. if (DoorFound != null) { try { MoveDoors(doc, linkedDoor, DoorFound); } catch (Exception e) { string ErrMessage = e.Message; } // Get all the levels from current project. Level level = findLevel(doc, linkedDoor); // Level offset from architecture. LibraryGetItems Library = new LibraryGetItems(); LibraryConvertUnits library_Units = new LibraryConvertUnits(); double offset = 0; Level CurrentLevel = _ListLevels.Find(x => x.Name == level.Name); try { Parameter parameter_LevelOffsetFF = CurrentLevel.LookupParameter("LEVEL OFFSET FF"); offset = library_Units.InchesToFeet(Convert.ToDouble(Library.GetParameterValue(parameter_LevelOffsetFF))); } catch { } // Check to see if door size match. double height = Math.Round(linkedDoor.doorHeight + offset, 3); double width = Math.Round(linkedDoor.doorWidth, 3); String doorType = doorTypeByUnits(doc, height, width); if (doorType != "0 x 0") { if (DoorFound.doorName != doorType) { //FamilySymbol familySymbol = findSymbol(doc, DoorFound, doorType); FamilySymbol familySymbol = FindElementByName(doc, typeof(FamilySymbol), doorType) as FamilySymbol; if (familySymbol == null) { FamilySymbol oldType = findSymbol(doc, DoorFound); FamilySymbol ChangeFamilySymbol = CreateNewType(doc, oldType, linkedDoor, offset); //FamilySymbol ChangeFamilySymbol = BKK_CreateNewType(doc, oldType, linkedDoor); changeType(doc, DoorFound, ChangeFamilySymbol); } if (familySymbol != null) { changeType(doc, DoorFound, familySymbol); } } } } } //REMOVE UNSUED DOORS. RemoveUnused(doc, List_DoorsLinkedModel, List_DoorsCurrentModel); return(ListObjDoors); }
//*****************************CreateDoors()***************************** public ObjDoors CreateDoors(UIDocument uidoc, Document doc, ObjDoors linkedDoor) { LibraryGetItems Library = new LibraryGetItems(); LibraryConvertUnits library_Units = new LibraryConvertUnits(); // Get all the levels from current project. Level level = findLevel(doc, linkedDoor); // Level offset from architecture. double offset = 0; Level CurrentLevel = _ListLevels.Find(x => x.Name == level.Name); try { Parameter parameter_LevelOffsetFF = CurrentLevel.LookupParameter("LEVEL OFFSET FF"); offset = library_Units.InchesToFeet(Convert.ToDouble(Library.GetParameterValue(parameter_LevelOffsetFF))); } catch { } // CREATE : door type height x width double height = Math.Round(linkedDoor.doorHeight + offset, 3); double width = Math.Round(linkedDoor.doorWidth, 3); String doorType = doorTypeByUnits(doc, height, width); if (doorType != "0 x 0") { FamilySymbol currentDoorType = null; try { currentDoorType = FindElementByName(doc, typeof(FamilySymbol), doorType) as FamilySymbol; } catch { } if (currentDoorType == null) { FamilySymbol familySymbol_OldType = FindElementByName(doc, typeof(FamilySymbol), "10 x 10") as FamilySymbol; currentDoorType = CreateNewType(doc, familySymbol_OldType, linkedDoor, offset); } // Convert coordinates to double and create XYZ point. Use offset level from current model. XYZ xyz = new XYZ(linkedDoor.X, linkedDoor.Y, CurrentLevel.Elevation + linkedDoor.doorSillHeight); //Find the hosting Wall (nearst wall to the insertion point) List <Wall> walls = Library.GetWalls(doc); Wall wall = null; double distance = double.MaxValue; foreach (Element e in walls) { Wall w = e as Wall; LocationCurve lc = w.Location as LocationCurve; Curve curve = lc.Curve; XYZ z = curve.GetEndPoint(0); if (linkedDoor.level.Elevation <= z.Z + 3 && linkedDoor.level.Elevation >= z.Z - 3) { int i = w.Id.IntegerValue; } //int i = w.Id.IntegerValue; double proximity = (w.Location as LocationCurve).Curve.Distance(xyz); if (proximity < distance) { distance = proximity; var SOMIDParam = e.LookupParameter("SOM ID"); string wallSOMId = Library.GetParameterValue(SOMIDParam); if (linkedDoor.HostObj.ToString() == wallSOMId) { wall = w; } } } try { if (wall != null) { // Create door. using (Transaction t = new Transaction(doc, "Create door")) { t.Start(); if (!currentDoorType.IsActive) { // Ensure the family symbol is activated. currentDoorType.Activate(); doc.Regenerate(); } // Create window // unless you specified a host, Revit will create the family instance as orphabt object. FamilyInstance fm = doc.Create.NewFamilyInstance(xyz, currentDoorType, wall, level, StructuralType.NonStructural); // Set new local door id to match linked model element id. Parameter SOMIDParam = fm.LookupParameter("SOM ID"); SOMIDParam.Set(linkedDoor.doorId); linkedDoor.wall = wall; t.Commit(); return(linkedDoor); } } } catch { } } return(null); }
/// <summary> /// Get linked model and select all the doors. /// </summary> /// <param name="doc"></param> /// <param name="uiApp"></param> /// <returns>Object of doors</returns> public List <ObjDoors> LinkedModelDoors(Document doc, UIApplication uiApp) { FilteredElementCollector collector = new FilteredElementCollector(doc); IList <Element> elems = collector .OfCategory(BuiltInCategory.OST_RvtLinks) .OfClass(typeof(RevitLinkType)) .ToElements(); List <ObjDoors> LinkedModelDoors = new List <ObjDoors>(); foreach (Element e in elems) { RevitLinkType linkType = e as RevitLinkType; String s = String.Empty; foreach (Document linkedDoc in uiApp.Application.Documents) { if (linkedDoc.Title.Equals(linkType.Name)) { LibraryGetItems library = new LibraryGetItems(); List <Element> doors = library.GetFamilyElement(linkedDoc, BuiltInCategory.OST_Doors); foreach (Element door in doors) { try { LocationPoint location = door.Location as LocationPoint; // Get level id parameter Parameter levelId = door.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM); // Get level value of id parameter string parmLevel_Id = library.GetParameterValue(levelId); // get all levels in linked model List <Level> levels = library.GetLevels(linkedDoc); // find and match of door level and linked model level to get level Level levelName = levels.Find(x => Convert.ToString(x.Id.IntegerValue) == parmLevel_Id); FamilySymbol familySymbol = library.GetFamilySymbol(linkedDoc, door.Name, BuiltInCategory.OST_Doors); // find unique identification of door\ ObjDoors ObjectDoor = new ObjDoors(); ObjectDoor.doorElement = door; ObjectDoor.doorName = door.Name; ObjectDoor.doorId = door.Id.ToString(); ObjectDoor.doorWidth = door.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble(); try { if (ObjectDoor.doorWidth == 0.0) { ObjectDoor.doorWidth = familySymbol.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble(); } } catch { } ObjectDoor.doorHeight = door.get_Parameter(BuiltInParameter.DOOR_HEIGHT).AsDouble(); try { if (ObjectDoor.doorHeight == 0.0) { ObjectDoor.doorHeight = familySymbol.get_Parameter(BuiltInParameter.DOOR_HEIGHT).AsDouble(); } } catch { } ObjectDoor.doorSillHeight = door.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM).AsDouble(); ObjectDoor.X = location.Point.X; ObjectDoor.Y = location.Point.Y; ObjectDoor.Z = location.Point.Z; ObjectDoor.level = levelName; FamilyInstance familyInstance = door as FamilyInstance; ObjectDoor.HostObj = familyInstance.Host.Id.IntegerValue; ObjectDoor.wall = linkedDoc.GetElement(familyInstance.Host.Id) as Wall; LinkedModelDoors.Add(ObjectDoor); } catch (Exception er) { string error = er.Message; } } } } } return(LinkedModelDoors); }
//*****************************RejustSectionView()***************************** public void RejustSectionView(Document doc, UIDocument uidoc) { //My library LibraryGetItems lib = new LibraryGetItems(); LibraryGeometry libGeo = new LibraryGeometry(); // Select wall or object. Element wallElement = lib.SelectElement(uidoc, doc); // collect all ViewSections FilteredElementCollector SectionCollector = new FilteredElementCollector(doc); SectionCollector.OfClass(typeof(ViewSection)).WhereElementIsNotElementType(); List <ViewSection> sections = SectionCollector.Cast <ViewSection>().Where(sh => sh.ViewType == ViewType.Section).ToList(); // Select section from active view. Element sectionelem = lib.SelectElement(uidoc, doc); // Compare element by name to find the SectionView. ViewSection section = sections.Find(t => t.ViewName == sectionelem.Name); // OFFSET // element to wall. Wall wall = wallElement as Wall; LocationCurve locationCurve = wall.Location as LocationCurve; // Move the section element Line origWallLine = locationCurve.Curve as Line; Curve offsetWallLine = origWallLine.CreateOffset(3, XYZ.BasisZ); // Midpoint of the offset wall line. XYZ offsetWallMid = libGeo.Midpoint(offsetWallLine as Line); // selected section orign point. XYZ sectionOrigin = new XYZ(section.Origin.X, section.Origin.Y, 0); // Move distance between selected and offset. XYZ transaction = offsetWallMid - sectionOrigin; //ANGLE XYZ s = origWallLine.GetEndPoint(0); XYZ e = origWallLine.GetEndPoint(1); XYZ v = e - s; int compare = libGeo.Compare(s, e); if (e.X > s.X && compare < 1) { if (e.Y < s.Y) { v = s - e; offsetWallLine = origWallLine.CreateOffset(-3, XYZ.BasisZ); // Midpoint of the offset wall line. offsetWallMid = libGeo.Midpoint(offsetWallLine as Line); // selected section orign point. sectionOrigin = new XYZ(section.Origin.X, section.Origin.Y, 0); // Move distance between selected and offset. transaction = offsetWallMid - sectionOrigin; } } if (e.Y < s.Y && compare == 1) { if (e.X < s.X) { v = s - e; offsetWallLine = origWallLine.CreateOffset(-3, XYZ.BasisZ); // Midpoint of the offset wall line. offsetWallMid = libGeo.Midpoint(offsetWallLine as Line); // selected section orign point. sectionOrigin = new XYZ(section.Origin.X, section.Origin.Y, 0); // Move distance between selected and offset. transaction = offsetWallMid - sectionOrigin; } } double radians = XYZ.BasisX.AngleTo(v); // Angle is using radians. double Angle = radians * (180 / Math.PI); // Convert Radians to degrees. // ROTATE SECTION FIRST using (Transaction tr = new Transaction(doc, "Rotate")) { tr.Start("rotate"); try { if (Angle > 0) { Line axis = Line.CreateBound(sectionOrigin, sectionOrigin + XYZ.BasisZ); doc.Regenerate(); // Document regenerate to refresh document. ElementTransformUtils.RotateElement(doc, sectionelem.Id, axis, radians); } } catch { } tr.Commit(); } // MOVE SECTION using (Transaction t = new Transaction(doc, "Update Section")) { t.Start("Update Section"); try { ElementTransformUtils.MoveElement(doc, sectionelem.Id, transaction); } catch { } t.Commit(); } }
//*****************************CreateSectionPerpendicular()***************************** public void CreateSectionPerpendicular(Document doc, UIDocument uidoc) { // My library LibraryGetItems libGet = new LibraryGetItems(); Element e = libGet.SelectElement(uidoc, doc); Wall wall = null; if (e != null) { wall = e as Wall; } LocationCurve lc = wall.Location as LocationCurve; Transform curveTransform = lc.Curve.ComputeDerivatives(0.5, true); // The transform contains the location curve // mid-point and tangent, and we can obtain // its normal in the XY plane: XYZ origin = curveTransform.Origin; XYZ viewdir = curveTransform.BasisX.Normalize(); XYZ up = XYZ.BasisZ; XYZ right = up.CrossProduct(viewdir); // Set up view transform, assuming wall's "up" // is vertical. For a non-vertical situation // such as section through a sloped floor, the // surface normal would be needed Transform transform = Transform.Identity; transform.Origin = origin; transform.BasisX = right; transform.BasisY = up; transform.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = transform; // Min & Max X values define the section // line length on each side of the wall. // Max Y is the height of the section box. // Max Z (5) is the far clip offset. double d = wall.WallType.Width; BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; double h = maxZ - minZ; // Z value offset from the current level in view. Level level = doc.ActiveView.GenLevel; double top = 90 - level.Elevation; double bottom = -(level.Elevation + 25); sectionBox.Min = new XYZ(-2 * d, bottom, 0); sectionBox.Max = new XYZ(2 * d, top, 5); ViewFamilyType vft = viewFamilyType(doc); View viewTemplate = libGet.GetViewTemplate(doc, "Z-ELEV ARCH OFF"); ViewSection vs = null; //Create wall section view using (Transaction tx = new Transaction(doc)) { try { tx.Start("Create Section"); vs = ViewSection.CreateSection(doc, vft.Id, sectionBox); doc.Regenerate(); tx.Commit(); } catch { } } using (Transaction t = new Transaction(doc)) { try { t.Start("Apply Structural View Template"); vs.ViewTemplateId = viewTemplate.Id; vs.Scale = 24; t.Commit(); } catch { } } }
//*****************************CreateSectionStart()***************************** public void CreateSectionStart(Document doc, UIDocument uidoc) { // My library LibraryGetItems libGet = new LibraryGetItems(); Element e = libGet.SelectElement(uidoc, doc); Wall wall = null; if (e != null) { wall = e as Wall; } // Create a BoundingBoxXYZ instance centered on wall BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z; double maxZ = bb.Max.Z; double h = maxZ - minZ; Level level = doc.ActiveView.GenLevel; double top = 90 - level.Elevation; double bottom = -(level.Elevation + 25); LocationCurve lc = wall.Location as LocationCurve; Line line = lc.Curve as Line; XYZ p = line.GetEndPoint(0); XYZ q = line.GetEndPoint(1); XYZ v = p - q; // p point 0 - q point 1 - view direction up. double halfLength = v.GetLength() / 2; double offset = 3; // offset by 3 feet. //Max/Min X = Section line Length, Max/Min Y is the height of the section box, Max/Min Z far clip XYZ min = new XYZ(-halfLength, bottom, -offset); XYZ max = new XYZ(halfLength, top, offset); XYZ midpoint = q + 0.5 * v; // q get lower midpoint. XYZ walldir = v.Normalize(); XYZ up = XYZ.BasisZ; XYZ viewdir = walldir.CrossProduct(up); Transform t = Transform.Identity; t.Origin = midpoint; t.BasisX = walldir; t.BasisY = up; t.BasisZ = viewdir; BoundingBoxXYZ sectionBox = new BoundingBoxXYZ(); sectionBox.Transform = t; sectionBox.Min = min; // scope box start sectionBox.Max = max; // scope box end ViewFamilyType vft = viewFamilyType(doc); View viewTemplate = libGet.GetViewTemplate(doc, "Z-ELEV ARCH OFF"); ViewSection vs = null; //Create wall section view using (Transaction tx = new Transaction(doc)) { try { tx.Start("Create Section"); vs = ViewSection.CreateSection(doc, vft.Id, sectionBox); tx.Commit(); } catch { } } using (Transaction tr = new Transaction(doc)) { try { tr.Start("Apply Structural View Template"); vs.ViewTemplateId = viewTemplate.Id; vs.Scale = 24; tr.Commit(); } catch { } } }