public void Transferviewtemplate(Document source, Document target, List <ElementId> elementIds)
 {
     using (Transaction tran = new Transaction(target, "Ivention EXT: Transfer view template"))
     {
         tran.Start();
         FailureHandlingOptions options       = tran.GetFailureHandlingOptions();
         IgnoreProcess          ignoreProcess = new IgnoreProcess();
         options.SetClearAfterRollback(true);
         options.SetFailuresPreprocessor(ignoreProcess);
         tran.SetFailureHandlingOptions(options);
         CopyPasteOptions coptions = new CopyPasteOptions();
         coptions.SetDuplicateTypeNamesHandler(new CopyHandler());
         ICollection <ElementId> litstrans = ElementTransformUtils.CopyElements(source, elementIds, target, null, coptions);
         tran.Commit(options);
     }
 }
        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);
                Transform transform1 = Transform.CreateTranslation(transform.Origin);
                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 CopyElementsFlatToWarped(Document doc, FamilyInstance familyInstance, ICollection <ElementId> elementIds, Selection sel)
        {
            ICollection <ElementId> newlist = new List <ElementId>();
            CopyPasteOptions        option  = new CopyPasteOptions();
            ElementtransformToCopy  tr      = new ElementtransformToCopy();
            FamilyInstance          flat    = tr.GetFlat(doc, familyInstance);
            List <PlanarFace>       list1   = FlFaces(flat);
            FamilyInstance          warped  = tr.GetWarped(doc, familyInstance);
            PlanarFace    face1             = Facemax(list1);
            Element       element1          = doc.GetElement(elementIds.First());
            LocationPoint loc      = element1.Location as LocationPoint;
            XYZ           pointorg = loc.Point;
            //double minspace = MinSpacePlanarFace(doc, familyInstance, face1, pointorg);
            Transform transform = TransformFlatWapred(doc, flat, warped);

            //Solid solid1 = Solidhelper.AllSolids(flat).First();
            //Solid solid2 = Solidhelper.AllSolids(warped).First();
            //Transform transform1 = solid1.GetBoundingBox().Transform;
            //Transform transform2 = solid2.GetBoundingBox().Transform;
            //Transform transform = transform1.Inverse.Multiply(transform2);
            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)
                {
                }
                foreach (ElementId eleid in newlist)
                {
                    Element            ele      = doc.GetElement(eleid);
                    LocationPoint      locele   = ele.Location as LocationPoint;
                    XYZ                pointcon = locele.Point;
                    List <HermiteFace> list2    = WarpedFace(warped);
                    if (list2.Count != 0)
                    {
                        HermiteFace face2 = FacemaxWraped(list2);
                        //double distanceloc = kcpointtoHemiteFace(face2, pointcon);

                        double distanceloc = MinSpaceHermiteFace(doc, familyInstance, face2, pointcon);
                        var    xv1         = FIndpointonwraped(pointcon, new XYZ(0, 0, 1), distanceloc);
                        XYZ    point1      = pointcon - xv1;
                        ElementTransformUtils.MoveElement(doc, eleid, point1);
                    }
                    else
                    {
                        List <RevolvedFace> revolvedFaces = WarpedFaceRevolFace(warped);
                        RevolvedFace        face2         = FacemaxWrapedRevolFace(revolvedFaces);
                        //double distanceloc = kcpointtoHemiteFace(face2, pointcon);

                        double distanceloc = MinSpaceRevolFace(doc, familyInstance, face2, pointcon);
                        var    xv1         = FIndpointonwraped(pointcon, new XYZ(0, 0, 1), distanceloc);
                        XYZ    point1      = pointcon - xv1;
                        ElementTransformUtils.MoveElement(doc, eleid, point1);
                    }
                    //if (minspace > 0)
                    //{
                    //    var xv1 = FIndpointonwraped(pointcon,doc.ActiveView.UpDirection, distanceloc);
                    //    XYZ point1 = pointcon - xv1;
                    //    ElementTransformUtils.MoveElement(doc, eleid, point1);
                    //}
                    //else
                    //{
                    //    var xv1 = FIndpointonwraped(pointcon, doc.ActiveView.UpDirection, distanceloc);
                    //    XYZ point1 = xv1 - pointcon;
                    //    ElementTransformUtils.MoveElement(doc, eleid, point1);
                    //}
                }
                tran.Commit();
            }
        }
        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();
            var              f1              = elementIds.First();
            double           kl              = Nut(doc, familyInstance, f1);
            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();
        }
示例#5
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;

            doc = uidoc.Document;
            Selection               sel    = uidoc.Selection;
            IList <Reference>       rfs    = sel.PickObjects(ObjectType.Element, new FilterSpecialEquipment(), "Selection");
            ICollection <ElementId> idcopy = new List <ElementId>();

            foreach (Reference v in rfs)
            {
                Element ele = doc.GetElement(v);
                idcopy.Add(ele.Id);
            }
            CopyPasteOptions copyPasteOptions = new CopyPasteOptions();

            copyPasteOptions.SetDuplicateTypeNamesHandler(new CopyHandlerRemoveWorplane());
            ICollection <ElementId> newid = new List <ElementId>();

            using (Transaction tran = new Transaction(doc, "ss"))
            {
                tran.Start();
                foreach (ElementId i in idcopy)
                {
                    Element                 ele            = doc.GetElement(i);
                    LocationPoint           point          = ele.Location as LocationPoint;
                    XYZ                     tu             = point.Point;
                    FamilyInstance          familyInstance = ele as FamilyInstance;
                    ICollection <ElementId> listlp         = familyInstance.GetSubComponentIds();
                    Transform               transform      = familyInstance.GetTransform();
                    Transform               transform1     = Transform.CreateTranslation(-transform.BasisZ);
                    FailureHandlingOptions  options        = tran.GetFailureHandlingOptions();
                    IgnoreProcess           ignoreProcess  = new IgnoreProcess();
                    options.SetClearAfterRollback(true);
                    options.SetFailuresPreprocessor(ignoreProcess);
                    tran.SetFailureHandlingOptions(options);
                    ICollection <ElementId> Listcopy = new List <ElementId>();
                    foreach (ElementId j in listlp)
                    {
                        Listcopy.Add(j);
                    }
                    newid = ElementTransformUtils.CopyElements(doc, Listcopy, doc, transform1, copyPasteOptions);
                    foreach (var gh in newid)
                    {
                        Element       eleoop   = doc.GetElement(gh);
                        LocationPoint pointyu  = eleoop.Location as LocationPoint;
                        XYZ           pointg   = pointyu.Point;
                        XYZ           pointnew = new XYZ(tu.X - pointg.X, tu.Y - pointg.Y, tu.Z - pointg.Z);
                        ElementTransformUtils.MoveElement(doc, gh, pointnew);
                        Element        Newele      = doc.GetElement(gh);
                        FamilyInstance newinstance = Newele as FamilyInstance;
                    }
                    Listcopy.Remove(i);
                    doc.Delete(ele.Id);
                }
                tran.Commit();
            }
            return(Result.Succeeded);
        }