예제 #1
0
        public void Cutting(Document doc, List <FamilyInstance> listcut, List <FamilyInstance> listconn)
        {
            ProgressBarform progressBarform = new ProgressBarform(listconn.Count, "Cutting");

            progressBarform.Show();
            foreach (var conn in listconn)
            {
                progressBarform.giatri();
                if (progressBarform.iscontinue == false)
                {
                    break;
                }
                using (Transaction tran = new Transaction(doc, "Cut Void"))
                {
                    tran.Start();
                    foreach (var framming in listcut)
                    {
                        try
                        {
                            if (InstanceVoidCutUtils.CanBeCutWithVoid(framming))
                            {
                                InstanceVoidCutUtils.AddInstanceVoidCut(doc, framming, conn);
                            }
                        }
                        catch
                        {
                        }
                    }
                    tran.Commit();
                }
            }
            progressBarform.Close();
        }
예제 #2
0
        private void Doding(Document doc, List <FamilyInstance> listinstance)
        {
            ProgressBarform progressBarform = new ProgressBarform(listinstance.Count, "Loading...");

            progressBarform.Show();
            foreach (var instance in listinstance)
            {
                progressBarform.giatri();
                if (progressBarform.iscontinue == false)
                {
                    break;
                }
                var Workplane = instance.get_Parameter(BuiltInParameter.SKETCH_PLANE_PARAM);
                if (Workplane != null)
                {
                    var value = Workplane.AsString();
                    if (!value.StartsWith("Grid") && !value.StartsWith("Reference Plane") && !value.StartsWith("Level"))
                    {
                        listsource.Add(new GroupInstanceInfo(instance));
                    }
                }
            }
            progressBarform.Close();
            this._exEvent = ExternalEvent.Create((IExternalEventHandler) new CheckWorkPlaneEvent(this, doc));
            var form = new FrmCheckReference(this, doc);

            form.Show();
            form.ExEvent = this._exEvent;
        }
예제 #3
0
        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();
        }
예제 #4
0
        public Dictionary <string, string> Doing(Document doc, List <ElementId> elementIds)
        {
            Dictionary <string, List <string> > dic  = new Dictionary <string, List <string> >();
            Dictionary <string, List <string> > dic2 = new Dictionary <string, List <string> >();
            Dictionary <string, string>         dic3 = new Dictionary <string, string>();
            List <ElementId> listids         = elementIds.ToList();
            ProgressBarform  progressBarform = new ProgressBarform(listids.Count, "Loading...");

            progressBarform.Show();
            for (int i = 0; i < listids.Count; i++)
            {
                var item = (FamilyInstance)doc.GetElement(listids[i]);
                progressBarform.giatri();
                if (progressBarform.iscontinue == false)
                {
                    break;
                }
                ElementId faid      = item.GetTypeId();
                Element   elemtype  = doc.GetElement(faid);
                Parameter pa        = elemtype.LookupParameter("IDENTITY_DESCRIPTION");
                Transform transform = item.GetTransform();
                if (pa != null)
                {
                    string pa1 = pa.AsString();
                    if (pa1.Contains("STRAND"))
                    {
                        IList <Solid> solids1 = lbr_.CreateSolid(doc, item, transform);
                        if (solids1 != null)
                        {
                            foreach (Solid it in solids1)
                            {
                                IList <FamilyInstance> a1 = Checkstrand(doc, it, listids);
                                var sup = GetSuperInstances(new List <FamilyInstance> {
                                    item
                                });
                                List <FamilyInstance> checksup = GetSuperInstances(a1.ToList());
                                foreach (var i1 in checksup)
                                {
                                    if (dic.ContainsKey(sup.First().Name))
                                    {
                                        dic[sup.First().Name].Add(Unionstring(sup.First(), i1));
                                    }
                                    else
                                    {
                                        dic.Add(sup.First().Name, new List <string> {
                                            Unionstring(sup.First(), i1)
                                        });
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        List <Solid> solids = AllSolids(item);
                        if (solids != null)
                        {
                            foreach (Solid it in solids)
                            {
                                if (it != null && it.Faces.Size < 50)
                                {
                                    IList <FamilyInstance> a1 = Checkintersect(doc, it, listids, item);
                                    var sup = GetSuperInstances(new List <FamilyInstance> {
                                        item
                                    });
                                    List <FamilyInstance> checksup = GetSuperInstances(a1.ToList());
                                    foreach (var i1 in checksup)
                                    {
                                        if (dic.ContainsKey(sup.First().Name))
                                        {
                                            dic[sup.First().Name].Add(Unionstring(sup.First(), i1));
                                        }
                                        else
                                        {
                                            dic.Add(sup.First().Name, new List <string> {
                                                Unionstring(sup.First(), i1)
                                            });
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                listids.RemoveAt(i);
                i--;
            }
            foreach (var item in dic.Keys)
            {
                dic2.Add(item, RemoveContankey(dic[item]));
            }
            foreach (var item2 in dic2.Keys)
            {
                var fg = SpilitS(dic2[item2]);
                foreach (var item in fg.Keys)
                {
                    dic3.Add(item, fg[item]);
                }
            }
            progressBarform.Close();
            return(dic3);
        }
예제 #5
0
        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();
        }