public void CopyElements(Document doc, FamilyInstance familyInstance, List <FamilyInstance> listinstance, ICollection <ElementId> elementIds)
        {
            ICollection <ElementId> newlist         = new List <ElementId>();
            CopyPasteOptions        option          = new CopyPasteOptions();
            ProgressBarform         progressBarform = new ProgressBarform(listinstance.Count, "Loading...");

            progressBarform.Show();
            foreach (FamilyInstance source in listinstance)
            {
                progressBarform.giatri();
                if (progressBarform.iscontinue == false)
                {
                    break;
                }
                Transform transform = TransformToCopy(source, familyInstance);
                using (Transaction tran = new Transaction(doc, "copy"))
                {
                    tran.Start();
                    FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                    IgnoreProcess          ignoreProcess = new IgnoreProcess();
                    options.SetClearAfterRollback(true);
                    options.SetFailuresPreprocessor(ignoreProcess);
                    tran.SetFailureHandlingOptions(options);
                    try
                    {
                        newlist = ElementTransformUtils.CopyElements(doc, elementIds, doc, transform, option);
                        Remove_product(doc, newlist);
                    }
                    catch (Exception)
                    {
                    }
                    tran.Commit();
                }
            }
            progressBarform.Close();
        }
        public void CopyElementsConnFlangeDtee(Document doc, FamilyInstance familyInstance, List <FamilyInstance> listinstance, ICollection <ElementId> elementIds, bool valuekey)
        {
            ICollection <ElementId> newlist  = new List <ElementId>();
            Parameter        pa1             = familyInstance.LookupParameter("Flange_Edge_Offset_Right");
            double           Flange_Right1   = pa1.AsDouble();
            Parameter        pa2             = familyInstance.LookupParameter("Flange_Edge_Offset_Left");
            double           Flange_Left1    = pa2.AsDouble();
            Parameter        pal             = familyInstance.LookupParameter("DIM_LENGTH");
            double           dim_length      = pal.AsDouble();
            double           kl              = Nut(doc, familyInstance, elementIds.First());
            CopyPasteOptions option          = new CopyPasteOptions();
            ProgressBarform  progressBarform = new ProgressBarform(listinstance.Count, "Loading...");

            progressBarform.Show();
            foreach (FamilyInstance source in listinstance)
            {
                if (source.Id != familyInstance.Id)
                {
                    using (Transaction tran = new Transaction(doc, "Copy"))
                    {
                        tran.Start();
                        Transform transform1   = source.GetTransform();
                        Parameter pa3          = source.LookupParameter("Flange_Edge_Offset_Right");
                        double    Flange_Right = pa3.AsDouble();
                        ElementId sourceid     = source.GetTypeId();
                        Element   sourcetype   = doc.GetElement(sourceid);
                        Parameter sourcepa     = sourcetype.LookupParameter("DT_Stem_Spacing_Form");
                        Parameter pa4          = source.LookupParameter("Flange_Edge_Offset_Left");
                        double    Flange_Left  = pa4.AsDouble();
                        double    val1         = Flange_Right1 - Flange_Right;
                        double    val2         = Flange_Left1 - Flange_Left;
                        progressBarform.giatri();
                        if (progressBarform.iscontinue == false)
                        {
                            break;
                        }
                        Transform transform                  = TransformToCopy(source, familyInstance);
                        FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
                        IgnoreProcess          ignoreProcess = new IgnoreProcess();
                        options.SetClearAfterRollback(true);
                        options.SetFailuresPreprocessor(ignoreProcess);
                        tran.SetFailureHandlingOptions(options);
                        try
                        {
                            newlist = ElementTransformUtils.CopyElements(doc, elementIds, doc, transform, option);
                            Remove_product(doc, newlist);
                        }
                        catch (Exception)
                        {
                        }
                        if (valuekey == true)
                        {
                            if (sourcepa == null)
                            {
                                if (val1 != 0 || val2 != 0)
                                {
                                    FamilyInstance    flatsource        = GetFlat(doc, familyInstance);
                                    FamilyInstance    flattarget        = GetFlat(doc, source);
                                    List <PlanarFace> planarFacessource = FlFaces(flatsource);
                                    List <PlanarFace> planarFacetarget  = FlFaces(flattarget);
                                    Element           elesource         = doc.GetElement(elementIds.First());
                                    double            spatarget         = 0;
                                    foreach (ElementId i in newlist)
                                    {
                                        Element       eletarget      = doc.GetElement(i);
                                        LocationPoint locationPoint2 = eletarget.Location as LocationPoint;
                                        XYZ           pointtarget    = locationPoint2.Point;
                                        spatarget = DistanceToMin(doc, source, planarFacetarget, pointtarget, kl);
                                        if (spatarget != 0)
                                        {
                                            break;
                                        }
                                    }
                                    if (spatarget != 0)
                                    {
                                        foreach (ElementId i in newlist)
                                        {
                                            XYZ point1 = new XYZ(0, 0, 0);
                                            point1 = point1 + transform1.BasisX * -spatarget;
                                            ElementTransformUtils.MoveElement(doc, i, point1);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (val2 > 0)
                                {
                                    foreach (ElementId i in newlist)
                                    {
                                        XYZ point1 = new XYZ(0, 0, 0);
                                        point1 = point1 + transform1.BasisX * -val2;
                                        ElementTransformUtils.MoveElement(doc, i, point1);
                                    }
                                }
                                else
                                {
                                    foreach (ElementId i in newlist)
                                    {
                                        XYZ point1 = new XYZ(0, 0, 0);
                                        point1 = point1 + transform1.BasisX * -val2;
                                        ElementTransformUtils.MoveElement(doc, i, point1);
                                    }
                                }
                            }
                        }
                        if (valuekey == false)
                        {
                            if (sourcepa == null)
                            {
                                if (val1 != 0 || val2 != 0)
                                {
                                    FamilyInstance    flatsource        = GetFlat(doc, familyInstance);
                                    FamilyInstance    flattarget        = GetFlat(doc, source);
                                    List <PlanarFace> planarFacessource = FlFaces(flatsource);
                                    List <PlanarFace> planarFacetarget  = FlFaces(flattarget);
                                    Element           elesource         = doc.GetElement(elementIds.First());
                                    double            spatarget         = 0;
                                    foreach (ElementId i in newlist)
                                    {
                                        Element       eletarget      = doc.GetElement(i);
                                        LocationPoint locationPoint2 = eletarget.Location as LocationPoint;
                                        XYZ           pointtarget    = locationPoint2.Point;
                                        spatarget = DistanceToMin(doc, source, planarFacetarget, pointtarget, kl);
                                        if (spatarget != 0)
                                        {
                                            break;
                                        }
                                    }
                                    if (spatarget != 0)
                                    {
                                        foreach (ElementId i in newlist)
                                        {
                                            XYZ point1 = new XYZ(0, 0, 0);
                                            point1 = point1 + transform1.BasisX * spatarget;
                                            ElementTransformUtils.MoveElement(doc, i, point1);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (val1 > 0)
                                {
                                    foreach (ElementId i in newlist)
                                    {
                                        XYZ point1 = new XYZ(0, 0, 0);
                                        point1 = point1 + transform1.BasisX * (val1);
                                        ElementTransformUtils.MoveElement(doc, i, point1);
                                    }
                                }
                                else
                                {
                                    foreach (ElementId i in newlist)
                                    {
                                        XYZ point1 = new XYZ(0, 0, 0);
                                        point1 = point1 + transform1.BasisX * (-val1);
                                        ElementTransformUtils.MoveElement(doc, i, point1);
                                    }
                                }
                            }
                        }
                        tran.Commit();
                    }
                }
            }
            progressBarform.Close();
        }