public void CopyText(Document doc, List <ElementId> ids, View source, List <View> Taggets)
        {
            ProgressbarWPF progressbarWPF = new ProgressbarWPF(Taggets.Count, "Copy Text");

            progressbarWPF.Show();
            foreach (var Tagget in Taggets)
            {
                if (progressbarWPF.iscontinue == false)
                {
                    break;
                }
                using (Transaction t = new Transaction(doc, "Copy Text"))
                {
                    t.Start();
                    FailureHandlingOptions options       = t.GetFailureHandlingOptions();
                    MyPreProcessor         ignoreProcess = new MyPreProcessor();
                    options.SetClearAfterRollback(true);
                    options.SetFailuresPreprocessor(ignoreProcess);
                    t.SetFailureHandlingOptions(options);
                    try
                    {
                        ElementTransformUtils.CopyElements(source, ids, Tagget, Transform.Identity, new CopyPasteOptions());
                    }
                    catch
                    {
                    }
                    t.Commit();
                }
            }
            progressbarWPF.Close();
        }
Ejemplo n.º 2
0
 public void Copyelement(Document Source, Document Target, ICollection <ElementId> elementIds)
 {
     using (Transaction t = new Transaction(Target, "Copy Model"))
     {
         t.Start();
         FailureHandlingOptions options       = t.GetFailureHandlingOptions();
         MyPreProcessor         ignoreProcess = new MyPreProcessor();
         options.SetClearAfterRollback(true);
         options.SetFailuresPreprocessor(ignoreProcess);
         t.SetFailureHandlingOptions(options);
         try
         {
             ElementTransformUtils.CopyElements(Source, elementIds, Target, Transform.Identity, new CopyPasteOptions());
         }
         catch
         {
         }
         t.Commit();
     }
 }
Ejemplo n.º 3
0
        public void Dimwall(Document doc, Selection sel, DimensionType dimensionType)
        {
            List <FamilyInstance> listwall      = new List <FamilyInstance>();
            FamilyInstance        wall1         = (FamilyInstance)doc.GetElement(sel.PickObject(ObjectType.Element, new InstanceFilter(), "Select Element First"));
            FamilyInstance        wall2         = (FamilyInstance)doc.GetElement(sel.PickObject(ObjectType.Element, new InstanceFilter(), "Select Element Second"));
            LocationPoint         locationPoint = (LocationPoint)wall1.Location;
            XYZ           xyz            = (locationPoint != null) ? locationPoint.Point : null;
            LocationPoint locationPoint2 = (LocationPoint)wall2.Location;
            XYZ           xyz2           = (locationPoint2 != null) ? locationPoint2.Point : null;
            //XYZ npoint = tranlatorxyz1(doc.ActiveView, xyz2, xyz);
            //XYZ direction = (xyz - npoint).Normalize();
            XYZ direction = (xyz - xyz2).Normalize();

            listwall = Getwallinrow(doc, wall1, wall2, direction);
            ReferenceArray referenceArray = new ReferenceArray();

            if (listwall.Count == 1)
            {
                listwall.Clear();
                XYZ npoint2    = tranlatorxyz2(doc.ActiveView, xyz2, xyz);
                XYZ direction2 = (xyz - npoint2).Normalize().Negate();
                listwall = Getwallinrow(doc, wall1, wall2, direction2);
                foreach (var item in listwall)
                {
                    PlanarFace rigthface = null;
                    PlanarFace leftface  = null;
                    GetReferenceWall2(doc, item, direction2, ref rigthface, ref leftface);
                    referenceArray.Append(rigthface.Reference);
                    referenceArray.Append(leftface.Reference);
                }
                using (Transaction tran = new Transaction(doc, "Create dimension"))
                {
                    tran.Start();
                    XYZ  p1   = sel.PickPoint();
                    XYZ  p2   = FindTaghead(p1, direction2, 10);
                    Line line = Line.CreateBound(p1, p2);
                    var  dim  = doc.Create.NewDimension(doc.ActiveView, line, referenceArray, dimensionType);
                    tran.Commit();
                }
            }
            else
            {
                foreach (var item in listwall)
                {
                    PlanarFace rigthface = null;
                    PlanarFace leftface  = null;
                    GetReferenceWall2(doc, item, direction, ref rigthface, ref leftface);
                    referenceArray.Append(rigthface.Reference);
                    referenceArray.Append(leftface.Reference);
                }


                using (Transaction tran = new Transaction(doc, "Create dimension"))
                {
                    tran.Start();
                    FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                    MyPreProcessor         preproccessor = new MyPreProcessor();
                    options.SetClearAfterRollback(false);
                    options.SetFailuresPreprocessor(preproccessor);
                    tran.SetFailureHandlingOptions(options);
                    Plane       plane = Plane.CreateByNormalAndOrigin(doc.ActiveView.ViewDirection, doc.ActiveView.Origin);
                    SketchPlane skt   = SketchPlane.Create(doc, plane);
                    doc.ActiveView.SketchPlane = skt;
                    XYZ  p1   = sel.PickPoint();
                    XYZ  p2   = FindTaghead(p1, direction, 10);
                    Line line = Line.CreateBound(p1, p2);
                    var  dim  = doc.Create.NewDimension(doc.ActiveView, line, referenceArray, dimensionType);
                    tran.Commit(options);
                }
            }
        }
Ejemplo n.º 4
0
        public void Changefamily(Document doc, FamilySymbol familySymbol, List <FamilyInstance> listinstance)
        {
            ProgressbarWPF progressbarWPF = new ProgressbarWPF(listinstance.Count, "Loading...");

            progressbarWPF.Show();
            foreach (FamilyInstance familyInstance in listinstance)
            {
                progressbarWPF.Giatri();
                if (progressbarWPF.iscontinue == false)
                {
                    break;
                }
                Dictionary <string, string> dicparameter  = new Dictionary <string, string>();
                Dictionary <string, double> dicparameter1 = new Dictionary <string, double>();
                using (Transaction tran = new Transaction(doc, "sss"))
                {
                    tran.Start();
                    FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                    MyPreProcessor         preproccessor = new MyPreProcessor();
                    options.SetClearAfterRollback(true);
                    options.SetFailuresPreprocessor(preproccessor);
                    List <Parameter> list1 = ParameterofDt.Getpameteryesno(doc, familyInstance);
                    List <Parameter> list2 = ParameterofDt.Getpameterdouble(doc, familyInstance);
                    foreach (var item in list1)
                    {
                        if (item != null)
                        {
                            dicparameter.Add(item.Definition.Name, item.AsValueString());
                        }
                    }
                    foreach (var item in list2)
                    {
                        if (item != null)
                        {
                            dicparameter1.Add(item.Definition.Name, item.AsDouble());
                        }
                    }
                    familyInstance.Symbol = familySymbol;
                    List <Parameter> list3 = ParameterofDt.Getpameteryesno(doc, familyInstance);
                    List <Parameter> list4 = ParameterofDt.Getpameterdouble(doc, familyInstance);
                    for (int i = 0; i < list3.Count; i++)
                    {
                        var g1 = list3[i];
                        if (g1 != null)
                        {
                            var giatri1 = g1.AsString();
                            foreach (var o in dicparameter)
                            {
                                if (o.Key == g1.Definition.Name)
                                {
                                    g1.Set(o.Value);
                                }
                            }
                        }
                    }
                    for (int i = 0; i < list4.Count; i++)
                    {
                        var g1 = list4[i];
                        if (g1 != null)
                        {
                            var giatri1 = g1.AsDouble();
                            foreach (var o in dicparameter1)
                            {
                                if (o.Key == g1.Definition.Name)
                                {
                                    g1.Set(o.Value);
                                }
                            }
                        }
                    }
                    tran.Commit(options);
                }
            }
            progressbarWPF.Close();
        }
Ejemplo n.º 5
0
        public void SetNewHost(FamilyInstance familyInstance, Document doc)
        {
            using (Transaction tran = new Transaction(doc, "Unpin"))
            {
                tran.Start();
                if (familyInstance.Pinned == true)
                {
                    familyInstance.Pinned = false;
                }
                tran.Commit();
            }
            LocationPoint  locationPoint   = familyInstance.Location as LocationPoint;
            XYZ            poi             = locationPoint.Point;
            XYZ            locsau          = XYZ.Zero;
            XYZ            dri2            = familyInstance.HandOrientation;
            XYZ            lk              = familyInstance.FacingOrientation;
            var            H               = familyInstance.GetReferences(FamilyInstanceReferenceType.StrongReference);
            Transform      transformsource = familyInstance.GetTransform();
            FamilyInstance a               = null;
            var            levelnear       = GetLevelnearly(doc, familyInstance);
            var            Girdnear        = GetGridnearly(doc, familyInstance);
            var            referenealy     = GetReferencenearly(doc, familyInstance);

            if (levelnear.Count != 0)
            {
                if (referenealy.Count != 0)
                {
                    if (levelnear.Keys.First() < referenealy.Keys.First())
                    {
                        using (Transaction tran = new Transaction(doc, "cres"))
                        {
                            tran.Start();
                            FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                            MyPreProcessor         preproccessor = new MyPreProcessor();
                            options.SetClearAfterRollback(true);
                            options.SetFailuresPreprocessor(preproccessor);
                            tran.SetFailureHandlingOptions(options);
                            FamilySymbol symbol = familyInstance.Symbol;
                            var          LV     = levelnear.Values.First().GetPlaneReference();
                            a = doc.Create.NewFamilyInstance(LV, poi, dri2, symbol);
                            Mathparameter(doc, familyInstance, a);
                            tran.Commit(options);
                        }
                    }
                    else
                    {
                        using (Transaction tran = new Transaction(doc, "cres"))
                        {
                            tran.Start();
                            FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                            MyPreProcessor         preproccessor = new MyPreProcessor();
                            options.SetClearAfterRollback(true);
                            options.SetFailuresPreprocessor(preproccessor);
                            tran.SetFailureHandlingOptions(options);
                            FamilySymbol symbol = familyInstance.Symbol;
                            a = doc.Create.NewFamilyInstance(GetReferencenearly(doc, familyInstance).Values.First().GetReference(), poi, dri2, symbol);
                            Mathparameter(doc, familyInstance, a);
                            tran.Commit(options);
                        }
                    }
                }
                else
                {
                    using (Transaction tran = new Transaction(doc, "cres"))
                    {
                        tran.Start();
                        FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                        MyPreProcessor         preproccessor = new MyPreProcessor();
                        options.SetClearAfterRollback(true);
                        options.SetFailuresPreprocessor(preproccessor);
                        tran.SetFailureHandlingOptions(options);
                        FamilySymbol symbol = familyInstance.Symbol;
                        var          LV     = levelnear.Values.First().GetPlaneReference();
                        a = doc.Create.NewFamilyInstance(LV, poi, dri2, symbol);
                        Mathparameter(doc, familyInstance, a);
                        tran.Commit(options);
                    }
                }
            }
            else
            {
                if (referenealy.Count != 0)
                {
                    if (Girdnear.Count != 0)
                    {
                        if (Girdnear.Keys.First() < referenealy.Keys.First())
                        {
                            using (Transaction tran = new Transaction(doc, "cres"))
                            {
                                tran.Start();
                                FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                                MyPreProcessor         preproccessor = new MyPreProcessor();
                                options.SetClearAfterRollback(true);
                                options.SetFailuresPreprocessor(preproccessor);
                                tran.SetFailureHandlingOptions(options);
                                FamilySymbol symbol = familyInstance.Symbol;
                                var          LV     = Girdnear.Values.First().Curve.Reference;
                                a = doc.Create.NewFamilyInstance(LV, poi, dri2, symbol);
                                Mathparameter(doc, familyInstance, a);
                                tran.Commit(options);
                            }
                        }
                        else
                        {
                            using (Transaction tran = new Transaction(doc, "cres"))
                            {
                                tran.Start();
                                FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                                MyPreProcessor         preproccessor = new MyPreProcessor();
                                options.SetClearAfterRollback(true);
                                options.SetFailuresPreprocessor(preproccessor);
                                tran.SetFailureHandlingOptions(options);
                                FamilySymbol symbol = familyInstance.Symbol;
                                a = doc.Create.NewFamilyInstance(referenealy.First().Value.GetReference(), poi, dri2, symbol);
                                Mathparameter(doc, familyInstance, a);
                                tran.Commit(options);
                            }
                        }
                    }
                    else
                    {
                        using (Transaction tran = new Transaction(doc, "cres"))
                        {
                            tran.Start();
                            FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                            MyPreProcessor         preproccessor = new MyPreProcessor();
                            options.SetClearAfterRollback(true);
                            options.SetFailuresPreprocessor(preproccessor);
                            tran.SetFailureHandlingOptions(options);
                            FamilySymbol symbol = familyInstance.Symbol;
                            a = doc.Create.NewFamilyInstance(GetReferencenearly(doc, familyInstance).Values.First().GetReference(), poi, dri2, symbol);
                            Mathparameter(doc, familyInstance, a);
                            tran.Commit(options);
                        }
                    }
                }
                else
                {
                    using (Transaction tran = new Transaction(doc, "cres"))
                    {
                        tran.Start();
                        FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                        MyPreProcessor         preproccessor = new MyPreProcessor();
                        options.SetClearAfterRollback(true);
                        options.SetFailuresPreprocessor(preproccessor);
                        tran.SetFailureHandlingOptions(options);
                        FamilySymbol symbol = familyInstance.Symbol;
                        var          LV     = Girdnear.Values.First().Curve.Reference;
                        a = doc.Create.NewFamilyInstance(LV, poi, dri2, symbol);
                        Mathparameter(doc, familyInstance, a);
                        tran.Commit(options);
                    }
                }
            }
            #region Modifyelement
            Transform transformtarget = a.GetTransform();
            if (transformsource != transformtarget)
            {
                using (Transaction tr = new Transaction(doc, "flip workplane"))
                {
                    tr.Start();
                    XYZ facing = a.FacingOrientation;
                    if (facing.Equalpoint(familyInstance.FacingOrientation) == false)
                    {
                        a.FlipWorkPlane();
                    }
                    tr.Commit();
                }
            }
            using (Transaction t = new Transaction(doc, "Move element"))
            {
                t.Start();
                FailureHandlingOptions options       = t.GetFailureHandlingOptions();
                MyPreProcessor         preproccessor = new MyPreProcessor();
                options.SetClearAfterRollback(true);
                options.SetFailuresPreprocessor(preproccessor);
                t.SetFailureHandlingOptions(options);
                doc.Delete(familyInstance.Id);
                LocationPoint locp = a.Location as LocationPoint;
                XYZ           poik = locp.Point;
                if (poik.Equalpoint(poi) == false)
                {
                    XYZ vectorx = new XYZ(poik.X - poi.X, 0, 0);
                    if (vectorx.Equalpoint(XYZ.Zero) == false)
                    {
                        ElementTransformUtils.MoveElement(doc, a.Id, -vectorx);
                        XYZ    pom = (a.Location as LocationPoint).Point;
                        double kc  = Math.Round(poi.DistanceTo(pom), 0);
                        if (kc != 0)
                        {
                            ElementTransformUtils.MoveElement(doc, a.Id, vectorx * 2);
                        }
                    }
                    XYZ vectory = new XYZ(0, poik.Y - poi.Y, 0);
                    if (vectory.Equalpoint(XYZ.Zero) == false)
                    {
                        ElementTransformUtils.MoveElement(doc, a.Id, -vectory);
                        XYZ    pom = (a.Location as LocationPoint).Point;
                        double kc  = Math.Round(poi.DistanceTo(pom), 0);
                        if (kc != 0)
                        {
                            ElementTransformUtils.MoveElement(doc, a.Id, vectory * 2);
                        }
                    }
                    XYZ vectorz = new XYZ(0, 0, poik.Z - poi.Z);
                    if (vectorz.Equalpoint(XYZ.Zero) == false)
                    {
                        ElementTransformUtils.MoveElement(doc, a.Id, -vectorz);
                        XYZ    pom = (a.Location as LocationPoint).Point;
                        double kc  = Math.Round(poi.DistanceTo(pom), 0);
                        if (kc != 0)
                        {
                            ElementTransformUtils.MoveElement(doc, a.Id, vectorz * 2);
                        }
                    }
                }
                t.Commit(options);
            }
            #endregion
        }