Example #1
0
        public void GetWallTypeProperties(WallType wallType, out bool isStructural, out string wallMat, out double wallThickness)
        {
            CompoundStructureLayer strLayer =
                (from CompoundStructureLayer layer in wallType.GetCompoundStructure().GetLayers()
                 where layer.Function == MaterialFunctionAssignment.Structure
                 select layer)
                .FirstOrDefault();

            if (strLayer != null)
            {
                isStructural = true;

                if (strLayer.MaterialId != ElementId.InvalidElementId)
                {
                    wallMat = _doc.GetElement(strLayer.MaterialId).Name;
                }
                else
                {
                    wallMat = String.Empty;
                }

                wallThickness = UnitUtils.Convert(
                    strLayer.Width,
                    DisplayUnitType.DUT_DECIMAL_FEET,
                    DisplayUnitType.DUT_CENTIMETERS);
            }
            else
            {
                isStructural  = false;
                wallMat       = String.Empty;
                wallThickness = 0;
            }
        }
Example #2
0
        private void CreateWalls(List <Geometry> closedCurves, WallType Wall_type, Level targetLevel, string Height_Wall)
        {
            CurveArray curveArray = new CurveArray();
            Curve      Cr         = null;

            foreach (Geometry item in closedCurves)
            {
                if (item.Type == "Line")
                {
                    curveArray.Append(Line.CreateBound(item.startPoint, item.endPoint));
                }
                else
                {
                    Cr = Arc.Create(item.startPoint, item.endPoint, item.ThirdPoint);
                    curveArray.Append(Cr);
                }
            }

            double Height_ = Convert.ToDouble(Height_Wall);
            double Height  = UnitUtils.Convert(Height_, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET);

            using (Transaction transaction = new Transaction(revitDoc))
            {
                transaction.Start("Start ");
                foreach (Curve item in curveArray)
                {
                    //Wall wall = Wall.Create(revitDoc, item, targetLevel.Id, false);
                    //wall.WallType = Wall_type;
                    Wall wall = Wall.Create(revitDoc, item, Wall_type.Id, targetLevel.Id, Height, 0, false, false);
                }
                transaction.Commit();
            }
        }
Example #3
0
        public static double GetConvertValue(this double value, Autodesk.Revit.DB.DisplayUnitType dut)
        {
            switch (dut)
            {
            case Autodesk.Revit.DB.DisplayUnitType.DUT_MILLIMETERS:
            case DisplayUnitType.DUT_METERS:
                return(UnitUtils.Convert(value, DisplayUnitType.DUT_DECIMAL_FEET, dut));

            case Autodesk.Revit.DB.DisplayUnitType.DUT_SQUARE_MILLIMETERS:
                return(UnitUtils.Convert(value, DisplayUnitType.DUT_SQUARE_FEET, dut));

            case Autodesk.Revit.DB.DisplayUnitType.DUT_CUBIC_MILLIMETERS:
                return(UnitUtils.Convert(value, DisplayUnitType.DUT_CUBIC_FEET, dut));

            case DisplayUnitType.DUT_SQUARE_METERS:
                return(UnitUtils.Convert(value, DisplayUnitType.DUT_SQUARE_FEET, dut));

            case DisplayUnitType.DUT_CUBIC_METERS:
                return(UnitUtils.Convert(value, DisplayUnitType.DUT_CUBIC_FEET, dut));

            case DisplayUnitType.DUT_DECIMAL_DEGREES:
                return(UnitUtils.Convert(value, DisplayUnitType.DUT_RADIANS, dut));

            default:
                throw new Exception("Trường hợp này chưa xét tới:");
            }
        }
Example #4
0
        public void AdjustBeamTypeProperties(FamilySymbol beamSymbol)
        {
            string actualTypeName = beamSymbol.Name;
            string targetSynthaxe = actualTypeName.Before("-");
            string targetBeamSign = BeamType.GetBeamSign(targetSynthaxe);

            string targetMatSign = actualTypeName.Between("-", "-");
            string targetBeamMat = RvtMaterial.GetMatName(targetMatSign);

            string dimensionString = actualTypeName.After("-");
            double targetWidth     = Convert.ToDouble(dimensionString.Before("x"));
            double targetHeight    = Convert.ToDouble(dimensionString.After("x"));

            double beamHeight, beamWidth;
            string beamSign, beamMat;

            GetBeamSymbolProperties(beamSymbol, out beamSign, out beamMat, out beamHeight, out beamWidth);

            if (!beamSign.Equals(targetBeamSign))
            {
                Transaction t = new Transaction(_doc);
                t.Start("Change beam type property");
                SetStringValueTo(beamSymbol,
                                 Default.PARA_NAME_BEAM_TYPE,
                                 targetBeamSign);
                t.Commit();
            }

            if (!beamMat.Equals(targetBeamMat))
            {
                Material targetMaterial = GetMaterialByName(_doc, targetBeamMat);

                Transaction t = new Transaction(_doc);
                t.Start("Change beam material property");
                SetElementIdValueTo(beamSymbol,
                                    Default.PARA_NAME_STR_MATERIAL,
                                    targetMaterial.Id);
                t.Commit();
            }

            if (beamHeight != targetHeight)
            {
                Transaction t = new Transaction(_doc);
                t.Start("Change beam height property");
                SetDoubleValueTo(beamSymbol,
                                 Default.PARA_NAME_DIM_HEIGHT,
                                 UnitUtils.Convert(targetHeight, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET));
                t.Commit();
            }

            if (beamWidth != targetWidth)
            {
                Transaction t = new Transaction(_doc);
                t.Start("Change beam width property");
                SetDoubleValueTo(beamSymbol,
                                 Default.PARA_NAME_DIM_WIDTH,
                                 UnitUtils.Convert(targetWidth, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET));
                t.Commit();
            }
        }
Example #5
0
        static public double ConvertToRevitUI(string valueName, double value, UnitsAssignment[] Assignments, DisplayUnit unitSystem)
        {
            foreach (UnitsAssignment ua in Assignments)
            {
                if (ua.ValueName.CompareTo(valueName) == 0)
                {
                    UnitsTypeAssignment currentAssignment;
                    switch (unitSystem)
                    {
                    case DisplayUnit.IMPERIAL:
                        if (!imperialSettings.TryGetValue(ua.unitType, out currentAssignment))
                        {
                            return(value);
                        }
                        break;

                    case DisplayUnit.METRIC:
                        if (!metricSettings.TryGetValue(ua.unitType, out currentAssignment))
                        {
                            return(value);
                        }
                        break;

                    default:
                        return(value);
                    }
                    value = UnitUtils.Convert(value, currentAssignment.DisplayType, RevitUnits.GetDisplayUnitType());
                    break;
                }
            }
            return(value);
        }
Example #6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var uidoc = commandData.Application.ActiveUIDocument;
            var doc   = uidoc.Document;

            //Get elements of Category
            var eles = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_StructuralColumns)
                       .WhereElementIsNotElementType()
                       .ToElements();
            var floors = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors)
                         .WhereElementIsNotElementType()
                         .ToElements();

            using (var tran = new Transaction(doc, "Join Columns and Floors"))
            {
                tran.Start();
                foreach (var ele in eles)
                {
                    if (ele.Name == "300 x 450mm")
                    {
                        var volume = ele.LookupParameter("Volume").AsDouble();
                        volume = UnitUtils.Convert(volume, DisplayUnitType.DUT_CUBIC_FEET, DisplayUnitType.DUT_CUBIC_METERS);
                        ele.LookupParameter("Mark").Set(volume.ToString());
                    }
                    else
                    {
                        doc.Delete(ele.Id);
                    }
                }
                tran.Commit();
            }
            return(Result.Succeeded);
        }
        public static FilteredElementCollector GetElementsByShareParamValue(Document doc, BuiltInCategory bic, string sParaName, double dValue)
        {
            SharedParameterElement para =
                (from p in new FilteredElementCollector(doc)
                 .OfClass(typeof(SharedParameterElement))
                 .Cast <SharedParameterElement>()
                 where p.Name.Equals(sParaName)
                 select p).First();

            ParameterValueProvider provider
                = new ParameterValueProvider(para.Id);

            FilterNumericRuleEvaluator evaluator
                = new FilterNumericEquals();

            double sLength_feet = UnitUtils.Convert(
                dValue,
                DisplayUnitType.DUT_METERS,
                DisplayUnitType.DUT_DECIMAL_FEET);
            double epsilon = 0.0001;

            FilterRule rule = new FilterDoubleRule(
                provider, evaluator, sLength_feet, epsilon);

            ElementParameterFilter filter
                = new ElementParameterFilter(rule);

            FilteredElementCollector collector
                = new FilteredElementCollector(doc)
                  .OfCategory(bic)
                  .WherePasses(filter);

            return(collector);
        }
Example #8
0
        void Btn_MoveClick(object sender, EventArgs e)
        {
            double x = 0;
            double y = 0;
            double z = 0;

            if (double.TryParse(txt_X2.Text, out x) && double.TryParse(txt_Y2.Text, out y) && double.TryParse(txt_Z2.Text, out z))
            {
                if (rdbtn_meter.Checked)
                {
                    x = UnitUtils.Convert(x, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES);
                    y = UnitUtils.Convert(y, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES);
                    z = UnitUtils.Convert(z, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES);
                }

                // Step 1 : Get the Project Base Point (PBP).
                Tuple <XYZ, double> basePoint = funct.GetProjectBasePoint(doc);

                //Step 2 : Determine the relative distance of the palcement point with respect to the PBP
                XYZ relativePoint = funct.GetRelativeDistanceTobasePoint(basePoint, new Autodesk.Revit.DB.XYZ(x, y, z));

                // Step 3 : Incase the True North is rotated, make the necessary correction.
                XYZ rotated = funct.RotatePointAntiClockwise(relativePoint.X, relativePoint.Y, relativePoint.Z, basePoint.Item2);

                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Move Adaptive Component");
                    funct.CreateOrMoveAdaptiveComponent(doc, rotated, null, selectedElement.ElementId);
                    tx.Commit();
                }
            }
        }
Example #9
0
        public void CreateWallByLine()
        {
            Document   doc   = this.ActiveUIDocument.Document;
            UIDocument uidoc = ActiveUIDocument;

            Level level = doc.GetElement(ViewLevelId()) as Level;

            try {
                while (true)
                {
                    Reference    hasPickOne = uidoc.Selection.PickObject(ObjectType.Element, "選取線:");
                    CurveElement ce         = doc.GetElement(hasPickOne) as CurveElement;
                    Curve        c          = ce.GeometryCurve;
                    Curve        d          = c.CreateOffset(UnitUtils.Convert(100, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET), new XYZ(0, 0, 1));
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Create Gable Wall");

                        //Wall wall = doc.Create.NewWall( // 2012
                        //  profile, wallType, level, true, normal );

                        //Wall wall = Wall.Create( // 2013
                        //  doc, profile, wallType.Id, level.Id, true, normal );

                        Wall wall = Wall.Create(doc, d, level.Id, true);

                        wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).Set(HigherLevelId(level.Id));                                 //牆頂部約束

                        tx.Commit();
                    }
                }
            } catch (Exception) {
                //	throw;
            }
        }
Example #10
0
        private void AddModelLineInfosToDataTable(DimensionEditingForm def)
        {
            def.DataTable.Rows.Clear();
            // Get all the model lines created by our plugin in the doc
            IList <CurveElement> lines =
                (from line in new FilteredElementCollector(_doc)
                 .OfClass(typeof(CurveElement))
                 .OfCategory(BuiltInCategory.OST_Lines)
                 .Cast <CurveElement>()
                 where (line as ModelLine) != null && line.GetEntitySchemaGuids().Count != 0
                 select line)
                .ToList();

            // Add infos to eht data table for each model line
            IList <object[]> linesParams = new List <object[]>();

            foreach (CurveElement line in lines)
            {
                ModelLine modelLine     = line as ModelLine;
                Schema    lineSchema    = Schema.Lookup(Utils.Guids.MODELLINE_SCHEMA_GUID);
                Entity    lineSchemaEnt = modelLine.GetEntity(lineSchema);

                // Get line Id
                int lineId = modelLine.Id.IntegerValue;

                // Get associated level of the line
                string lineLevel = modelLine.SketchPlane.Name;

                // Get line length
                double lineLength = Math.Round(
                    UnitUtils.Convert(modelLine.GeometryCurve.Length,
                                      DisplayUnitType.DUT_DECIMAL_FEET,
                                      DisplayUnitType.DUT_METERS),
                    2);

                // Get beam type
                string beamType = lineSchemaEnt.Get <string>(lineSchema.GetField("BeamType"));

                // Get beam section height
                double beamHeight = lineSchemaEnt.Get <double>(
                    lineSchema.GetField("SectionHeight"),
                    DisplayUnitType.DUT_CENTIMETERS);

                // Get beam section width
                double beamWidth = lineSchemaEnt.Get <double>(
                    lineSchema.GetField("SectionWidth"),
                    DisplayUnitType.DUT_CENTIMETERS);

                // Add infos to the datatable
                def.DataTable.Rows.Add(
                    lineId,
                    lineLevel,
                    lineLength,
                    beamType,
                    beamHeight,
                    beamWidth);
            }
            ;
        }
Example #11
0
        public FamilySymbol GetBeamFamilyTypeOrCreateNew(string beamSign, string beamMat, double beamHeight, double beamWidth)
        {
            string synthaxe = BeamType.GetSyntaxe(beamSign);
            string matSign  = RvtMaterial.GetMatSyntaxe(beamMat);

            string targetBeamTypeName = $"{synthaxe}-{matSign}-{beamWidth}x{beamHeight}";

            // find the family type for beam creation
            FamilySymbol beamSymbol = GetFamilySymbolByName(_doc, BuiltInCategory.OST_StructuralFraming, targetBeamTypeName);

            // if family type exists, adjust its properties
            if (beamSymbol != null)
            {
                AdjustBeamTypeProperties(beamSymbol);
            }
            // if family type doesn't exist in the project, create a new one
            else
            {
                if (null != _family)
                {
                    System.Diagnostics.Debug.Print("Family name={0}", _family.Name);

                    FamilySymbol s = null;
                    foreach (ElementId id in _family.GetFamilySymbolIds())
                    {
                        s = _doc.GetElement(id) as FamilySymbol;
                        break;
                    }
                    System.Diagnostics.Debug.Assert(null != s,
                                                    "expected at least one symbol"
                                                    + " to be defined in family");
                    Transaction t = new Transaction(_doc);
                    t.Start("Create new family type");

                    beamSymbol = s.Duplicate("InitialName") as FamilySymbol;

                    SetDoubleValueTo(
                        beamSymbol, Default.PARA_NAME_DIM_HEIGHT,
                        UnitUtils.Convert(beamHeight, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET));

                    SetDoubleValueTo(
                        beamSymbol, Default.PARA_NAME_DIM_WIDTH,
                        UnitUtils.Convert(beamWidth, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET));

                    SetStringValueTo(beamSymbol, Default.PARA_NAME_BEAM_TYPE, beamSign);

                    Material targetMaterial = GetMaterialByName(_doc, beamMat);

                    SetElementIdValueTo(beamSymbol, Default.PARA_NAME_STR_MATERIAL, targetMaterial.Id);

                    beamSymbol.Name = targetBeamTypeName;
                    t.Commit();

                    BeamTypesList.Add(beamSymbol);
                }
            }

            return(beamSymbol);
        }
Example #12
0
 public SeatBatch(double length, double width, int totalNum, Color color)
 {
     Length       = UnitUtils.Convert(length, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET);
     Width        = UnitUtils.Convert(width, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET);
     TotalNumber  = totalNum;
     UsableNumber = totalNum;
     FillColor    = color;
 }
        public static void SetPipeDiameter(Pipe pipe, double diameter)
        {
            RevitLibrary.Parameter parameter = pipe.get_Parameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM);
            Console.Write(parameter.DisplayUnitType);
            double value = UnitUtils.Convert(diameter, DisplayUnitType.DUT_MILLIMETERS, parameter.DisplayUnitType);

            parameter.Set(value);
        }
Example #14
0
        public static XYZ ConvertCoordinateFromAPIUnitToMeterUnit(XYZ pointToConvert)
        {
            double x = UnitUtils.Convert(pointToConvert.X, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_METERS);
            double y = UnitUtils.Convert(pointToConvert.Y, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_METERS);
            double z = UnitUtils.Convert(pointToConvert.Z, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_METERS);

            return(new XYZ(x, y, z));
        }
        private void PrepareLevelElevationAndName(out double[] elevations, out string[] names)
        {
            _lvlsHghtFeets = UnitUtils.Convert(
                _form.LevelHeight_Meters,
                DisplayUnitType.DUT_METERS,
                DisplayUnitType.DUT_DECIMAL_FEET);
            _baseHghtFeets = UnitUtils.Convert(
                _form.BasementHeight_Meters,
                DisplayUnitType.DUT_METERS,
                DisplayUnitType.DUT_DECIMAL_FEET);

            double lowestLvlElv = -_numOfBasements * _baseHghtFeets;

            // totalNumOfLvls + 2 ---> foundation level and base level of lowest basement
            elevations = new double[_totalNumOfLvls + 2];
            names      = new string[_totalNumOfLvls + 2];
            int refNumOfF1Top = _numOfBasements + 2;       // 2 ---> the PH SS levels start at i==2

            for (int i = 0; i < elevations.Length; i++)
            {
                // Foundation level
                if (i == 0)
                {
                    elevations[i] = lowestLvlElv - _foundationHghtFeets;
                    names[i]      = Properties.Settings.Default.LEVEL_NAME_FOUDATION;
                }
                // Base level of the lowest basement or RDC
                else if (i == 1)
                {
                    elevations[i] = lowestLvlElv;
                    if (_numOfBasements == 0)
                    {
                        names[i] = Properties.Settings.Default.LEVEL_NAME_BOTTOM_L1;
                    }
                    else
                    {
                        names[i] = $"Bas SS-{_numOfBasements}";
                    }
                }
                else if (i < refNumOfF1Top)
                {
                    elevations[i] = elevations[i - 1] + _baseHghtFeets;
                    names[i]      = $"PH SS-{refNumOfF1Top - i}";
                }
                else
                {
                    elevations[i] = elevations[i - 1] + _lvlsHghtFeets;
                    if (elevations[i - 1] == 0.0)
                    {
                        names[i] = Properties.Settings.Default.LEVEL_NAME_TOP_L1;
                    }
                    else
                    {
                        names[i] = $"PH R+{i - refNumOfF1Top}";
                    }
                }
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var uiApp = commandData.Application;
            var uiDoc = uiApp.ActiveUIDocument;
            var app   = uiApp.Application;
            var doc   = uiDoc.Document;

            try
            {
                // Tạo ra một collector để lấy tập hợp các element trong dự án hiện hành.
                var collector = new FilteredElementCollector(doc);

                // Lấy ra level đầu tiên trong danh sách các Level có trong dự án hiện hành
                var level = collector.OfCategory(BuiltInCategory.OST_Levels)
                            .WhereElementIsNotElementType()
                            .Cast <Level>()
                            .First();
                // Bạn có thể lấy ra một level đặc biệt với tên của nó bằng cách sau nếu đã biết tên Level đó

                /*
                 * var level = collector.OfCategory(BuiltInCategory.OST_Levels)
                 *          .WhereElementIsNotElementType()
                 *          .Cast<Level>()
                 *          .First(x=>x.Name == "Level 1");
                 * Lưu ý, Phải kiểm tra xem level đó có tồn tại không trước khi thực hiện bước kế tiếp nếu không chương trình sẽ ném ra một ngoại lệ (Exception).
                 * if(level1=null)
                 * {
                 *  // Khối code bạn muốn thực hiện nếu level !=null
                 * }
                 */

                // tạo ra một bức tường có chiều dài 10000 mm
                // Bạn cần thực hiện convert qua đơn vị Feet trước khi thực hiện lệnh vì trong Revit API đa phần các đối tượng sử dụng chiều dài length đều là ở đơn vị feet
                // Ở đây sử dụng một phương thức được xây dựng sẵn trong Revit API nếu không, bạn có thể xây dựng phương thức Convert của riêng bạn.
                var wallLength     = UnitUtils.Convert(10000, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET);
                var startWallPoint = new XYZ(0, 0, 0);
                var endWallPoint   = new XYZ(wallLength, 0, 0);
                var wallLine       = Line.CreateBound(startWallPoint, endWallPoint);

                // Bắt đầu sử dụng transaction trước khi thực hiện tạo ra tường, nếu không chương trình sẽ nén ra một ngoại lệ (Exception)
                using (var transaction = new Transaction(doc, "Create Wall Demo"))
                {
                    transaction.Start();
                    //Tạo ra bức tường mới với các thông số đã được get ở phía trên và commit nó vào dự án.
                    //Do sử dụng phương thức tạo đơn giản nên tường được tạo sẽ là loại tường mặc định đang được active trong môi trường Revit.
                    var wall = Wall.Create(doc, wallLine, level.Id, false);

                    transaction.Commit();
                }
            }
            catch (Exception e)
            {
                message = e.Message;

                return(Result.Failed);
            }
            return(Result.Succeeded);
        }
Example #17
0
        private double ConvertMM2FeetInch(double millimeters)
        {
            double mmToFeetInch = UnitUtils.Convert(
                millimeters,
                DisplayUnitType.DUT_MILLIMETERS,
                DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES);

            return(mmToFeetInch);
        }
Example #18
0
        private double ConvertFeetInch2MM(double feetInch)
        {
            double feetInchToMM = UnitUtils.Convert(
                feetInch,
                DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES,
                DisplayUnitType.DUT_MILLIMETERS);

            return(feetInchToMM);
        }
Example #19
0
        public static void GetRondColumnSymbolProperties(FamilySymbol colSymbol, out string colMat, out double colDiameter)
        {
            colMat = GetFamilySymbolValueStringByPropertyName(colSymbol, Default.PARA_NAME_STR_MATERIAL);

            colDiameter = UnitUtils.Convert(
                GetFamilySymbolDoubleByPropertyName(colSymbol, Default.PARA_NAME_DIM_DIAMETER),
                DisplayUnitType.DUT_DECIMAL_FEET,
                DisplayUnitType.DUT_CENTIMETERS);
        }
Example #20
0
 void Rdbtn_feetCheckedChanged(object sender, EventArgs e)
 {
     if (null != oldPoint)
     {
         //Display the Existing Co-Ordinates to the user
         txt_X1.Text = UnitUtils.Convert((oldPoint.X), DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES).ToString("#.000");
         txt_Y1.Text = UnitUtils.Convert((oldPoint.Y), DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES).ToString("#.000");
         txt_Z1.Text = UnitUtils.Convert((oldPoint.Z), DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES).ToString("#.000");
     }
 }
Example #21
0
        /// <summary>
        ///     Sets the material's texture.
        /// </summary>
        /// <param name="material"></param>
        /// <param name="angle"></param>
        /// <param name="offset"></param>
        /// <param name="size"></param>
        public static void SetTextureBase(this Material material, double angle, double[] offset, double[] size)
        {
            var doc = material.Document;

            if (offset == null || offset.Length == 0)
            {
                return;
            }

            if (size == null || size.Length == 0)
            {
                return;
            }

            using var editScope = new AppearanceAssetEditScope(doc);
            var asset = editScope.Start(material.AppearanceAssetId);

            if (asset[TextureWAngle] is AssetPropertyDouble angleProp)
            {
                angleProp.Value = angle;
            }

            if (asset[TextureRealWorldOffsetX] is AssetPropertyDistance xOffsetProp)
            {
                xOffsetProp.Value = UnitUtils.Convert(offset[0], DUT_DECIMAL_FEET, xOffsetProp.DisplayUnitType);
            }

            if (asset[TextureRealWorldOffsetY] is AssetPropertyDistance yOffsetProp)
            {
                yOffsetProp.Value = UnitUtils.Convert(offset[1], DUT_DECIMAL_FEET, yOffsetProp.DisplayUnitType);
            }

            if (asset[TextureRealWorldScaleX] is AssetPropertyDistance xSizeProp)
            {
                var minXSize = UnitUtils.Convert(0.01, xSizeProp.DisplayUnitType, DUT_MILLIMETERS);

                if (size[0] > minXSize)
                {
                    xSizeProp.Value = UnitUtils.Convert(size[0], DUT_DECIMAL_FEET, xSizeProp.DisplayUnitType);
                }
            }

            if (asset[TextureRealWorldScaleY] is AssetPropertyDistance ySizeProp)
            {
                var minYSize = UnitUtils.Convert(0.01, ySizeProp.DisplayUnitType, DUT_MILLIMETERS);

                if (size[1] > minYSize)
                {
                    ySizeProp.Value = UnitUtils.Convert(size[1], DUT_DECIMAL_FEET, ySizeProp.DisplayUnitType);
                }
            }

            editScope.Commit(true);
        }
Example #22
0
        /// <summary>
        ///     Converts feet unit value to mm unit value.
        /// </summary>
        /// <param name="feetNum"></param>
        /// <returns></returns>
        public static double ConvertFeetToMm(object feetNum)
        {
            if (feetNum is null)
            {
                throw new ArgumentNullException(nameof(feetNum));
            }

            var num = Convert.ToDouble(feetNum);

            return(UnitUtils.Convert(num, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_MILLIMETERS));
        }
Example #23
0
        /// <summary>
        ///     Converts inch unit value to mm unit value.
        /// </summary>
        /// <param name="inchNum"></param>
        /// <returns></returns>
        public static double Inch2Mm(this object inchNum)
        {
            if (inchNum is null)
            {
                throw new ArgumentNullException(nameof(inchNum));
            }

            var num = Convert.ToDouble(inchNum);

            return(UnitUtils.Convert(num, DisplayUnitType.DUT_DECIMAL_INCHES, DisplayUnitType.DUT_MILLIMETERS));
        }
Example #24
0
        /// <summary>
        ///     Converts mm unit value to feet unit value.
        /// </summary>
        /// <param name="mmNum"></param>
        /// <returns></returns>
        public static double Mm2Feet(this object mmNum)
        {
            if (mmNum is null)
            {
                throw new ArgumentNullException(nameof(mmNum));
            }

            var num = Convert.ToDouble(mmNum);

            return(UnitUtils.Convert(num, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET));
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var uiApp = commandData.Application;
            var uiDoc = uiApp.ActiveUIDocument;
            var app   = uiApp.Application;
            var doc   = uiDoc.Document;

            try
            {
                // Sử dụng PickObject để chọn đối tượng trên giao diện Revit
                // các dòng sau hàm này sẽ chưa được thực thi cho đến khi người dùng chọn một đối tượng trên Revit

                var refObject = uiDoc.Selection.PickObject(ObjectType.Element);

                var element   = doc.GetElement(refObject.ElementId);
                var elementId = element.Id;

                using (var transaction = new Transaction(doc, "Change Location"))
                {
                    transaction.Start();
                    // trục tâm để đối tượng xoay quanh nó
                    var  location   = element.Location;
                    Line centerLine = null;
                    if (location is LocationPoint locationPoint)
                    {
                        var currentP = locationPoint.Point;
                        centerLine = Line.CreateBound(currentP, new XYZ(currentP.X, currentP.Y, currentP.Z + 10));
                    }
                    else if (location is LocationCurve locationCurve)
                    {
                        var currentCurve = locationCurve.Curve as Line;
                        var startP       = currentCurve.GetEndPoint(0);
                        var endP         = currentCurve.GetEndPoint(1);
                        var midPoint     = PointUtils.GetMidPoint(startP, endP);
                        centerLine = Line.CreateBound(midPoint, new XYZ(midPoint.X, midPoint.Y, midPoint.Z + 10));
                    }

                    // Góc xoay, lưu ý, góc phải được đổi từ độ sang Radial
                    var angle = UnitUtils.Convert(45, DisplayUnitType.DUT_DECIMAL_DEGREES, DisplayUnitType.DUT_RADIANS);

                    // Có thể sử dụng phương thức  ElementTransformUtils.RotateElement() hoặc phương thức rotate trong location của đối tượng đều được kết quả như nhau
                    //ElementTransformUtils.RotateElement(doc, elementId, centerLine,angle);
                    element.Location.Rotate(centerLine, angle);
                    transaction.Commit();
                }
            }
            catch (Exception e)
            {
                message = e.Message;

                return(Result.Failed);
            }
            return(Result.Succeeded);
        }
Example #26
0
        private bool LineHasRelativeBeam(ModelLine modelLine, string beamSign, double beamHeight, double beamWidth, ElementId beamId)
        {
            // There exists a beam associate with the model line
            if (beamId != ElementId.InvalidElementId)
            {
                FamilyInstance beam           = _doc.GetElement(beamId) as FamilyInstance;
                double         realBeamHeight =
                    UnitUtils.Convert(
                        (from Parameter pr in beam.Symbol.Parameters
                         where pr.Definition.Name.Equals("Hauteur")
                         select pr)
                        .First()
                        .AsDouble(),
                        DisplayUnitType.DUT_DECIMAL_FEET,
                        DisplayUnitType.DUT_CENTIMETERS);

                double realBeamWidth =
                    UnitUtils.Convert(
                        (from Parameter pr in beam.Symbol.Parameters
                         where pr.Definition.Name.Equals("Largeur")
                         select pr)
                        .First()
                        .AsDouble(),
                        DisplayUnitType.DUT_DECIMAL_FEET,
                        DisplayUnitType.DUT_CENTIMETERS);

                string realBeamSign =
                    (from Parameter pr in beam.Symbol.Parameters
                     where pr.Definition.Name.Equals("Poutre type")
                     select pr)
                    .First()
                    .AsString();

                double realBeamLength = (beam.Location as LocationCurve).Curve.Length;

                double modelLineLength = modelLine.GeometryCurve.Length;

                // The beam has exactly the same param with model line
                if (beamHeight == realBeamHeight &&
                    beamWidth == realBeamWidth &&
                    modelLineLength == realBeamLength &&
                    beamSign.Equals(realBeamSign))
                {
                    return(true);
                }
                else
                {
                    _doc.Delete(beamId);
                    return(false);
                }
            }
            return(false);
        }
Example #27
0
        public static void GetRectColumnSymbolProperties(FamilySymbol colSymbol, out string colMat, out double colHeight, out double colWidth)
        {
            colMat = GetFamilySymbolValueStringByPropertyName(colSymbol, Default.PARA_NAME_STR_MATERIAL);

            colHeight = UnitUtils.Convert(
                GetFamilySymbolDoubleByPropertyName(colSymbol, Default.PARA_NAME_DIM_HEIGHT),
                DisplayUnitType.DUT_DECIMAL_FEET,
                DisplayUnitType.DUT_CENTIMETERS);
            colWidth = UnitUtils.Convert(
                GetFamilySymbolDoubleByPropertyName(colSymbol, Default.PARA_NAME_DIM_WIDTH),
                DisplayUnitType.DUT_DECIMAL_FEET,
                DisplayUnitType.DUT_CENTIMETERS);
        }
Example #28
0
        public static void GetInfo()
        {
            DistanceF = UnitUtils.Convert(Distance / 1000,
                                          DisplayUnitType.DUT_METERS,
                                          DisplayUnitType.DUT_DECIMAL_FEET);
            DistanceInSteps = (int)Math.Ceiling(DistanceF / InputData.PointsStepF);

            FullDistanceF              = DistanceF + (ElementSize.ElemDiameterF / 2);
            FullDistanceInSteps        = (int)Math.Round((FullDistanceF) / InputData.PointsStepF);
            FullDistanceWithMarkPointF = FullDistanceF + ModelSpacePointsGenerator.PointsStepF;

            Points = new List <StepPoint>();
        }
Example #29
0
        private bool EqualWithTolerance(double a, double b, double delta)
        {
            double delta_feet = UnitUtils.Convert(delta, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_DECIMAL_FEET);

            if (Math.Abs(a - b) < delta_feet)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #30
0
        public void AdjustWallTypeProperties(WallType wallType)
        {
            string actualTypeName = wallType.Name;

            string targetMatSign = actualTypeName.Between("-", "-");
            string targetWallMat = RvtMaterial.GetMatName(targetMatSign);

            double targetThickness = Convert.ToDouble(actualTypeName.After("EP"));

            double wallThickness;
            string wallMat;
            bool   isStructural;

            GetWallTypeProperties(wallType, out isStructural, out wallMat, out wallThickness);

            if (isStructural)
            {
                if (!wallMat.Equals(targetWallMat))
                {
                    Material targetMaterial = GetMaterialByName(_doc, targetWallMat);

                    Transaction t = new Transaction(_doc);
                    t.Start("Change the material of the structural layer of the wall type");
                    foreach (CompoundStructureLayer layer in wallType.GetCompoundStructure().GetLayers())
                    {
                        if (layer.Function == MaterialFunctionAssignment.Structure)
                        {
                            layer.MaterialId = targetMaterial.Id;
                        }
                    }
                    t.Commit();
                }

                if (wallThickness != targetThickness)
                {
                    TaskDialog.Show("Revit", $"{isStructural}, {targetThickness}, {wallThickness}");
                    Transaction t = new Transaction(_doc);
                    t.Start("Change the structural layer thickness of the wall type property");
                    foreach (CompoundStructureLayer layer in wallType.GetCompoundStructure().GetLayers())
                    {
                        if (layer.Function == MaterialFunctionAssignment.Structure)
                        {
                            layer.Width = UnitUtils.Convert(targetThickness, DisplayUnitType.DUT_CENTIMETERS, DisplayUnitType.DUT_DECIMAL_FEET);
                        }
                    }
                    t.Commit();
                }
            }
        }