예제 #1
0
        //*****************************doorTypeByUnits()*****************************
        public string doorTypeByUnits(Document doc, double height, double width)
        {
            LibraryConvertUnits lib = new LibraryConvertUnits();
            string doorType         = "";
            double h = 12 * height;
            double w = 12 * width;

            doorType = h.ToString() + " x " + w.ToString();

            return(doorType);
        }
예제 #2
0
        //*****************************MoveInstance()*****************************
        public void MoveInstance(Document doc, Element element, IsoObj Isolator, string levelName)
        {
            // get the column current location
            LocationPoint       InstanceLocation = element.Location as LocationPoint;
            LibraryConvertUnits lib = new LibraryConvertUnits();

            XYZ    oldPlace     = InstanceLocation.Point;
            double Old_Rotation = InstanceLocation.Rotation;

            //Get Level
            Level level = GetLevel(doc, levelName);

            // XY
            string xCoord = Isolator.X;
            string yCoord = Isolator.Y;
            // Rotation
            string rotation = Isolator.R;

            double New_x        = double.Parse(xCoord) / 12;
            double New_y        = double.Parse(yCoord) / 12;
            double New_Rotation = double.Parse(rotation);

            XYZ  New_xyz   = new XYZ(New_x, New_y, level.Elevation);
            XYZ  New_xyz_A = new XYZ(New_x, New_y, level.Elevation + 2);
            Line New_Axis  = Line.CreateBound(New_xyz, New_xyz_A);

            double Move_X = New_x - oldPlace.X;
            double Move_Y = New_y - oldPlace.Y;
            double Rotate = 0;

            if (New_Rotation != null)
            {
                Rotate = New_Rotation - Old_Rotation;
            }

            // Move the element to new location.
            XYZ new_xyz = new XYZ(Move_X, Move_Y, level.Elevation);

            //Start move using a transaction.
            Transaction t = new Transaction(doc);

            t.Start("Move Element");

            ElementTransformUtils.MoveElement(doc, element.Id, new_xyz);
            ElementTransformUtils.RotateElement(doc, element.Id, New_Axis, Rotate);

            t.Commit();
        }
예제 #3
0
        //*****************************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);
        }
예제 #4
0
        //*****************************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);
        }