コード例 #1
0
 // convert dữ liệu trên datagrid về dơn vị trong revit
 private void Convertdata()
 {
     foreach (var item in DataAxisX)
     {
         var    space = item.space;
         string bmn;
         var    t = UnitConvert.StringToFeetAndInches(space, out bmn);
         item.space = t.ToString();
     }
     foreach (var item in DataAxisY)
     {
         var    space = item.space;
         string bmn;
         var    t = UnitConvert.StringToFeetAndInches(space, out bmn);
         item.space = t.ToString();
     }
 }
コード例 #2
0
        public void SetValue(Document doc, Autodesk.Revit.DB.Line targetx, FamilyInstance familyInstance, string space)
        {
            PLane3D pLane3D = new PLane3D(doc.ActiveView.Origin, doc.ActiveView.ViewDirection);
            string  val1    = string.Empty;

            double    kspace         = UnitConvert.StringToFeetAndInches(space, out val1);
            Transform transform      = familyInstance.GetTransform();
            Line      target         = Line.CreateBound(pLane3D.ProjectPointOnPlane(targetx.GetStartPoint()), pLane3D.ProjectPointOnPlane(targetx.GetLastPoint()));
            var       list           = familyInstance.LinesGeometry(doc);
            Line      maxp           = list.Linemax();
            Line      max            = Line.CreateBound(transform.OfPoint(maxp.GetStartPoint()), transform.OfPoint(maxp.GetLastPoint()));
            Line      lineonplane    = Line.CreateBound(pLane3D.ProjectPointOnPlane(max.GetStartPoint()), pLane3D.ProjectPointOnPlane(max.GetLastPoint()));
            XYZ       pointintersect = FindIntersectwoline(target, lineonplane);
            Parameter dim_length     = familyInstance.LookupParameter("DIM_LENGTH");
            double    value          = dim_length.AsDouble();
            //XYZ start = pLane3D.ProjectPointOnPlane(max.GetStartPoint());
            //XYZ end = pLane3D.ProjectPointOnPlane(max.GetLastPoint());
            XYZ    start = lineonplane.GetStartPoint();
            XYZ    end   = lineonplane.GetLastPoint();
            double kc1   = target.Distance(pLane3D.ProjectPointOnPlane(start));
            double kc2   = target.Distance(pLane3D.ProjectPointOnPlane(end));

            //Line hg = Line.CreateBound(pointintersect, end);
            //SketchPlane skt = SketchPlane.Create(doc, pLane3D.GetPlane);
            //var ty = doc.Create.NewModelCurve(lineonplane, skt);
            //doc.Create.NewModelCurve(target, skt);
            //doc.Create.NewModelCurve(hg, skt);
            //doc.ActiveView.SketchPlane = skt;
            Line targetXX = Line.CreateBound(target.Origin + 10000.0 * target.Direction, target.Origin - 10000.0 * target.Direction);

            if (kc1 > kc2)
            {
                double length1 = (pointintersect - start).GetLength();
                if (value / 2 < length1)
                {
                    if (length1 < value)
                    {
                        double kc = targetXX.Distance(end);
                        //dim_length.Set(value - kc - kspace);
                        double setk = (value - kc - kspace);
                        string sou1 = setk.DoubleRoundFraction(8);
                        string k;
                        double h = UnitConvert.StringToFeetAndInches(sou1, out k);
                        dim_length.Set(h);
                        XYZ direction = (end - start).Normalize() * (kc + kspace);
                        ElementTransformUtils.MoveElement(doc, familyInstance.Id, -direction);
                    }
                    else
                    {
                        double kc = targetXX.Distance(end);
                        //dim_length.Set(value + kc - kspace);
                        double setk = (value + kc - kspace);
                        string sou1 = setk.DoubleRoundFraction(8);
                        string k;
                        double h = UnitConvert.StringToFeetAndInches(sou1, out k);
                        dim_length.Set(h);
                        XYZ direction = (end - start).Normalize() * (kc - kspace);
                        ElementTransformUtils.MoveElement(doc, familyInstance.Id, direction);
                    }
                }
                else
                {
                    if (length1 < value)
                    {
                        double kc = targetXX.Distance(end);
                        //dim_length.Set(value - (kspace - kc));
                        double setk = (value - (kspace - kc));
                        string sou1 = setk.DoubleRoundFraction(8);
                        string k;
                        double h = UnitConvert.StringToFeetAndInches(sou1, out k);
                        dim_length.Set(h);
                        XYZ direction = (end - start).Normalize() * (kc - kspace);
                        ElementTransformUtils.MoveElement(doc, familyInstance.Id, direction);
                    }
                    else
                    {
                        double kc = targetXX.Distance(end);
                        dim_length.Set(value - (kspace - kc));
                        XYZ direction = (end - start).Normalize() * (kc + kspace);
                        ElementTransformUtils.MoveElement(doc, familyInstance.Id, -direction);
                    }
                }
            }
            else
            {
                double lengthk = (pointintersect - end).GetLength();
                if (lengthk < value)
                {
                    double kc = targetXX.Distance(pLane3D.ProjectPointOnPlane(start));
                    //dim_length.Set(value - kc - kspace);
                    double setk = (value - kc - kspace);
                    string sou1 = setk.DoubleRoundFraction(8);
                    string k;
                    double h = UnitConvert.StringToFeetAndInches(sou1, out k);
                    dim_length.Set(h);
                }
                else
                {
                    //double kc = targetXX.Distance(pLane3D.ProjectPointOnPlane(start));
                    //dim_length.Set(value + kc - kspace);
                    double kc   = targetXX.Distance(pLane3D.ProjectPointOnPlane(start));
                    var    setk = (value + kc - kspace);
                    string sou1 = setk.DoubleRoundFraction(8);
                    string k;
                    double h = UnitConvert.StringToFeetAndInches(sou1, out k);
                    dim_length.Set(h);
                }
            }
        }
コード例 #3
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;

            uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;

            doc           = uidoc.Document;
            sel           = uidoc.Selection;
            Setting       = SettingTopDT.Instance.GetSetting();
            listTextnotes = Getmodelelement.GetTextNoteTypes(doc);
            using (var form = new FrmTopDT(this))
            {
                if (form.ShowDialog() != true && form.check)
                {
                    while (iscontinue)
                    {
                        Transaction tran = new Transaction(doc, "Callout dimension");
                        tran.Start();
                        try
                        {
                            Reference reference = sel.PickObject(ObjectType.Element, new FilterSpotElevation(), "Select Spot Elevation");
                            var       element   = doc.GetElement(reference);
                            var       top       = element.LookupParameter("Single/Upper Value").AsValueString();
                            string    val1      = string.Empty;
                            string    n         = string.Empty;
                            double    val2      = double.MinValue;
                            if (!string.IsNullOrEmpty(form.val) && form.tru == "")
                            {
                                val2 = UnitConvert.StringToFeetAndInches(top, out val1) + UnitConvert.StringToFeetAndInches(form.val, out n);
                            }
                            if (!string.IsNullOrEmpty(form.tru) && form.val == "")
                            {
                                val2 = UnitConvert.StringToFeetAndInches(top, out val1) - UnitConvert.StringToFeetAndInches(form.tru, out n);
                            }
                            var    val3  = UnitConvert.DoubleToImperial(val2);
                            string empty = UnitConvert.StringToFeetAndInchesformattext(val3);
                            if (!string.IsNullOrEmpty(form.Suffix) && string.IsNullOrEmpty(form.Prefix))
                            {
                                CreteaTextnode(doc, empty + " " + form.Suffix, form.TextNoteType);
                            }
                            if (string.IsNullOrEmpty(form.Suffix) && !string.IsNullOrEmpty(form.Prefix))
                            {
                                CreteaTextnode(doc, form.Prefix + " " + empty, form.TextNoteType);
                            }
                            if (!string.IsNullOrEmpty(form.Suffix) && !string.IsNullOrEmpty(form.Prefix))
                            {
                                CreteaTextnode(doc, form.Prefix + " " + empty + " " + form.Suffix, form.TextNoteType);
                            }
                        }
                        catch (Exception)
                        {
                            this.iscontinue = false;
                        }
                        tran.Commit();
                    }
                }
            }
            return(Result.Succeeded);
        }