public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Application app = uiapp.Application;
            Document    doc = uidoc.Document;

            // 'Autodesk.Revit.DB.Document.Mirror(ElementSet, Line)' is obsolete:
            // Use one of the replace methods in ElementTransformUtils.
            //
            //Line line = app.Create.NewLine(
            //  XYZ.Zero, XYZ.BasisX, true ); // 2011
            //
            //ElementSet els = uidoc.Selection.Elements; // 2011
            //
            //doc.Mirror( els, line ); // 2011

            Plane plane = new Plane(XYZ.BasisY, XYZ.Zero); // 2012

            ICollection <ElementId> elementIds
                = uidoc.Selection.GetElementIds(); // 2012

            ElementTransformUtils.MirrorElements(
                doc, elementIds, plane); // 2012

            return(Result.Succeeded);
        }
Ejemplo n.º 2
0
        public void BuildARoom(List <Room> roomsMade, Element selectedElement)
        {
            List <ElementId> wallsToMirror    = new List <ElementId>(); //Ids to use in mirroring arguement
            List <Wall>      wallsToAdd       = new List <Wall>();      //Walls to add to TAKEN
            List <Wall>      wallsToAddToRoom = new List <Wall>();
            Plane            mirrorPlane      = null;                   //try to replace with "out" later

            foreach (Room r in roomsMade)
            {
                if (r.GetWallId().Contains(selectedElement.Id))
                {
                    mirrorPlane = ExtractPlane(selectedElement); //gets plane for mirroring

                    foreach (ElementId w in r.GetWallId())
                    {
                        if (!w.Equals(selectedElement.Id))
                        {
                            wallsToMirror.Add(w);
                        }
                    }
                    break;
                }
            }
            using (Transaction transaction = new Transaction(doc))//mirrors walls
            {
                transaction.Start("Mirroring");
                ElementTransformUtils.MirrorElements(doc, wallsToMirror, ExtractPlane(selectedElement), true);//checked: fine
                // FailuresAccessor a = new FailuresAccessor(0);
                //   a.DeleteAllWarnings();
                transaction.Commit();
            }
            foreach (Wall w in getAllWalls())//BAD code, PLEASE learn filters later!
            {
                Boolean wallAllower = true;
                foreach (Wall takenWall in takenWalls)
                {
                    if (w.Id.IntegerValue == takenWall.Id.IntegerValue)
                    {
                        wallAllower = false;
                    }
                }
                if (wallAllower)
                {
                    wallsToAdd.Add(w);
                }
            }
            wallsToAddToRoom.AddRange(wallsToAdd);
            wallsToAddToRoom.Add(selectedElement as Wall);
            Debug.WriteLine("TAKEN WALLS SIZE" + takenWalls.Count);
            roomsMade.Add(new Room(wallsToAddToRoom));
            takenWalls.AddRange(wallsToAdd);
        }
Ejemplo n.º 3
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            IList <Reference> viewRefList = uidoc.Selection.PickObjects(ObjectType.Element, "Select Section");

            List <Autodesk.Revit.DB.View> views = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.View)).Cast <Autodesk.Revit.DB.View>().ToList();

            int flipped = 0;
            int errors  = 0;

            using (Transaction t = new Transaction(doc, "MirrorSection"))
            {
                t.Start();

                foreach (Reference viewRef in viewRefList)
                {
                    try
                    {
                        Element section = doc.GetElement(viewRef);

                        View vs = Helpers.SectionElementToView(views, section);

                        Plane _plane = Plane.CreateByNormalAndOrigin(vs.ViewDirection, vs.Origin);

                        ElementTransformUtils.MirrorElements(doc, new List <ElementId> {
                            section.Id
                        }, _plane, false);

                        flipped++;
                    }
                    catch
                    {
                        errors++;
                    }
                }

                t.Commit();
            }

            TaskDialog.Show("Result", $"{flipped} sections flipped\n{errors} sections not flipped");

            return(Result.Succeeded);
        }//close Execute
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            Application app = uiapp.Application;
            Document    doc = uidoc.Document;

            // 'Document.Mirror(ElementSet, Line)' is obsolete:
            // Use one of the replace methods in ElementTransformUtils.
            //
            //Line line = app.Create.NewLine(
            //  XYZ.Zero, XYZ.BasisX, true ); // 2011
            //
            //ElementSet els = uidoc.Selection.Elements; // 2011
            //
            //doc.Mirror( els, line ); // 2011

            //Plane plane = new Plane( XYZ.BasisY, XYZ.Zero ); // added in 2012, used until 2016
            Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisY, XYZ.Zero); // 2017

            ICollection <ElementId> elementIds
                = uidoc.Selection.GetElementIds(); // 2012

            //ElementTransformUtils.MirrorElements(
            //  doc, elementIds, plane ); // 2012-2015

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Mirror Elements");

                ElementTransformUtils.MirrorElements(
                    doc, elementIds, plane, true); // 2016

                t.Commit();
            }
            return(Result.Succeeded);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Flips a section
        /// </summary>
        /// <param name="section">The section to flip</param>
        /// <param name="copy">As a copy</param>
        /// <returns></returns>
        public static Revit.Elements.Views.SectionView Flip(Revit.Elements.Views.SectionView section, bool copy = false)
        {
            // Prelim stuff
            var doc            = DocumentManager.Instance.CurrentDBDocument;
            var iView          = section.InternalElement as Autodesk.Revit.DB.ViewSection;
            var sectionElement = Regnstrom.Views.View.GetCropElement(section).InternalElement;

            // Construct flip plane
            var flipPlane = Autodesk.Revit.DB.Plane.CreateByNormalAndOrigin(iView.ViewDirection, iView.Origin);

            //var flipPlane = new Autodesk.Revit.DB.Plane(iView.ViewDirection, iView.Origin);

            // Flip view
            TransactionManager.Instance.EnsureInTransaction(doc);
            // (yes, MirrorElements, because MirrorElement forces you to copy the element)
            ElementTransformUtils.MirrorElements(doc, new[] { sectionElement.Id }, flipPlane, copy);
            TransactionManager.Instance.TransactionTaskDone();

            // Return the view
            return(iView.ToDSType(true) as Revit.Elements.Views.SectionView);
        }
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Mirror and List Added");
                //Line line = app.Create.NewLine(
                //  XYZ.Zero, XYZ.BasisX, true ); // 2011

                //ElementSet els = uidoc.Selection.Elements; // 2011

                //Plane plane = new Plane( XYZ.BasisY, XYZ.Zero ); // added in 2012, used until 2016

                Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisY, XYZ.Zero); // 2017

                ICollection <ElementId> elementIds
                    = uidoc.Selection.GetElementIds(); // 2012

                using (SubTransaction t = new SubTransaction(doc))
                {
                    // determine newly added elements relying on the
                    // element sequence as returned by the filtered collector.
                    // this approach works in both Revit 2010 and 2011:

                    t.Start();

                    int n = GetElementCount(doc);

                    //doc.Mirror( els, line ); // 2011

                    //ElementTransformUtils.MirrorElements(
                    //  doc, elementIds, plane ); // 2012-2015

                    ElementTransformUtils.MirrorElements(
                        doc, elementIds, plane, true); // 2016

                    List <Element> a = GetElementsAfter(n, doc);

                    t.RollBack();
                }

                using (SubTransaction t = new SubTransaction(doc))
                {
                    // here is an idea for a new approach in 2011:
                    // determine newly added elements relying on
                    // monotonously increasing element id values:

                    t.Start();

                    FilteredElementCollector a = GetElements(doc);
                    int       i     = a.Max <Element>(e => e.Id.IntegerValue);
                    ElementId maxId = new ElementId(i);

                    // doc.Mirror( els, line ); // 2011

                    //ElementTransformUtils.MirrorElements(
                    //  doc, elementIds, plane ); // 2012-2015

                    ElementTransformUtils.MirrorElements(
                        doc, elementIds, plane, true); // 2016

                    // get all elements in document with an
                    // element id greater than maxId:

                    a = GetElementsAfter(doc, maxId);

                    Report(a);

                    t.RollBack();
                }

                using (SubTransaction t = new SubTransaction(doc))
                {
                    // similar to the above approach relying on
                    // monotonously increasing element id values,
                    // but apply a quick filter first:

                    t.Start();

                    FilteredElementCollector a = GetElements(doc);
                    int       i     = a.Max <Element>(e => e.Id.IntegerValue);
                    ElementId maxId = new ElementId(i);

                    //doc.Mirror( els, line ); // 2011

                    //ElementTransformUtils.MirrorElements(
                    //  doc, elementIds, plane ); // 2012-2015

                    ElementTransformUtils.MirrorElements(
                        doc, elementIds, plane, true); // 2016

                    // only look at non-ElementType elements
                    // instead of all document elements:

                    a = GetElements(doc);
                    a = GetElementsAfter(a, maxId);

                    Report(a);

                    t.RollBack();
                }

                using (SubTransaction t = new SubTransaction(doc))
                {
                    // use a local and temporary DocumentChanged event
                    // handler to directly obtain a list of all newly
                    // created elements.
                    // unfortunately, this canot be tested in this isolated form,
                    // since the DocumentChanged event is only triggered when the
                    // real outermost Revit transaction is committed, i.e. our
                    // local sub-transaction makes no difference. since we abort
                    // the sub-transaction before the command terminates and no
                    // elements are really added to the database, our event
                    // handler is never called:

                    t.Start();

                    app.DocumentChanged
                        += new EventHandler <DocumentChangedEventArgs>(
                               app_DocumentChanged);

                    //doc.Mirror( els, line ); // 2011

                    //ElementTransformUtils.MirrorElements(
                    //  doc, elementIds, plane ); // 2012-2015

                    ElementTransformUtils.MirrorElements(
                        doc, elementIds, plane, true); // 2016

                    app.DocumentChanged
                        -= new EventHandler <DocumentChangedEventArgs>(
                               app_DocumentChanged);

                    Debug.Assert(null == _addedElementIds,
                                 "never expected the event handler to be called");

                    if (null != _addedElementIds)
                    {
                        int n = _addedElementIds.Count;

                        string s = string.Format(_msg, n,
                                                 Util.PluralSuffix(n));

                        foreach (ElementId id in _addedElementIds)
                        {
                            Element e = doc.GetElement(id);

                            s += string.Format("\r\n  {0}",
                                               Util.ElementDescription(e));
                        }
                        Util.InfoMsg(s);
                    }

                    t.RollBack();
                }
                tx.RollBack();
            }
            return(Result.Succeeded);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            if (doc.IsFamilyDocument)
            {
                TaskDialog.Show("ОТМЕНЕНО", "Данная команда предназначена для запуска в документе проекта");
                return(Result.Cancelled);
            }

            try
            {
                Transform projectTransform = Utils.GetProjectCoordinatesTransform(doc);

                //выбрать несколько xml с расположением водосбросов
                string[] filenames = null;
                WinForms.OpenFileDialog openFileDialog1 = new WinForms.OpenFileDialog();


                string curDocPath = doc.PathName;
                if (!String.IsNullOrEmpty(curDocPath))
                {
                    openFileDialog1.InitialDirectory = Path.GetDirectoryName(curDocPath);
                }
                openFileDialog1.Filter           = "xml files (*.xml)|*.xml";
                openFileDialog1.FilterIndex      = 1;
                openFileDialog1.RestoreDirectory = true;
                openFileDialog1.Multiselect      = true;
                openFileDialog1.Title            = "Выберите таблицы CSV с координатами 3d-полилиний";

                if (openFileDialog1.ShowDialog() == WinForms.DialogResult.OK)
                {
                    Creation.Document crDoc = doc.Create;


                    filenames = openFileDialog1.FileNames;
                    using (TransactionGroup trGr = new TransactionGroup(doc))
                    {
                        trGr.Start("CreateSpillways");


                        foreach (string filename in filenames)
                        {
                            //распаристь xml
                            PositionData positionData = null;
                            using (StreamReader sr = new StreamReader(filename))
                            {
                                string serializedData = sr.ReadToEnd();
                                var    xmlSerializer  = new XmlSerializer(typeof(PositionData));
                                var    stringReader   = new StringReader(serializedData);
                                positionData = (PositionData)xmlSerializer.Deserialize(stringReader);
                            }
                            if (positionData != null)
                            {
                                foreach (SpillwayPosition sp in positionData.SpillwayPositions)
                                {
                                    //Загрузка семейства водосброса если еще нет
                                    Family spillwayFamily = null;
                                    if (sp.Slopes.Count == 2)
                                    {
                                        spillwayFamily = Utils.GetFamily(doc, "Водосброс2Укл");
                                    }
                                    else if (sp.Slopes.Count == 3)
                                    {
                                        spillwayFamily = Utils.GetFamily(doc, "Водосброс3Укл");
                                    }

                                    if (spillwayFamily != null)
                                    {
                                        ElementId    symId        = spillwayFamily.GetFamilySymbolIds().First();
                                        FamilySymbol familySymbol = (FamilySymbol)doc.GetElement(symId);


                                        using (Transaction tr = new Transaction(doc))
                                        {
                                            tr.Start("CreateSpillway");

                                            //активировать типоразмер
                                            if (!familySymbol.IsActive)
                                            {
                                                familySymbol.Activate();
                                                doc.Regenerate();
                                            }
                                            //Вставка водосбросов в заданные координаты
                                            //Поворот на заданный угол
                                            //Если водосброс направлен направо, то использовать отражение (с поворотом в противоположную сторону)
                                            XYZ            location      = projectTransform.OfPoint(Utils.PointByMeters(sp.X, sp.Y, sp.Z));
                                            FamilyInstance fi            = crDoc.NewFamilyInstance(location, familySymbol, StructuralType.NonStructural);
                                            Line           rotationAxis  = Line.CreateBound(location, location + XYZ.BasisZ);
                                            double         rotationAngle = sp.Z_Rotation / (180 / Math.PI);
                                            if (sp.ToTheRight)
                                            {
                                                rotationAngle = rotationAngle + Math.PI;
                                            }
                                            fi.Location.Rotate(rotationAxis, rotationAngle);
                                            if (sp.ToTheRight)
                                            {
                                                XYZ   spillwayDir = Transform.CreateRotation(XYZ.BasisZ, rotationAngle).OfVector(XYZ.BasisY);
                                                Plane mirrorPlane = Plane.CreateByNormalAndOrigin(spillwayDir, location);
                                                ElementTransformUtils.MirrorElements(doc, new List <ElementId>()
                                                {
                                                    fi.Id
                                                }, mirrorPlane, false);
                                                //doc.Delete(fi.Id);
                                            }


                                            //Назначение параметров уклонов водосброса
                                            for (int i = 0; i < sp.Slopes.Count; i++)
                                            {
                                                string lengthParamName = "Длина" + (i + 1);
                                                string slopeParamName  = "Уклон" + (i + 1);

                                                Parameter lengthParam = fi.LookupParameter(lengthParamName);
                                                Parameter slopeParam  = fi.LookupParameter(slopeParamName);
                                                if (lengthParam != null && slopeParam != null)
                                                {
                                                    Slope s = sp.Slopes[i];
                                                    lengthParam.Set(UnitUtils.Convert(s.Len, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_DECIMAL_FEET));
                                                    slopeParam.Set(s.S);
                                                }
                                            }

                                            tr.Commit();
                                        }
                                    }
                                }
                            }
                        }

                        trGr.Assimilate();
                    }
                }
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                CommonException(ex, "Ошибка при расстановке водосбросов в Revit");
                return(Result.Succeeded);
            }



            return(Result.Succeeded);
        }
Ejemplo n.º 8
0
        private void Setsymbol(Document doc, Dimension ele1, Dimension ele2, string family, string type, string family1, string type1, Plane plane)
        {
            Line curve1 = ele1.Curve as Line;

            curve1.MakeBound(0, 1);
            Line line1  = Support.ProjectLineOnPlane(plane, curve1);
            Line curve2 = ele2.Curve as Line;

            curve2.MakeBound(0, 1);
            Line         line2   = Support.ProjectLineOnPlane(plane, curve2);
            FamilySymbol symbol  = Support.GetSymbol(doc, family, type);
            FamilySymbol symbol1 = Support.GetSymbol(doc, family1, type1);

            //SUPPORT.PARAMETER.PARAMETER para = new SUPPORT.PARAMETER.PARAMETER();

            if (ele1.Id != ele2.Id)
            {
                //giao diem:
                XYZ giaodiem = Support.ExtendLineIntersection(line1, line2);

                ////Getendpoint:
                List <XYZ> listendpoint1  = Support.GetStartEndDimensio(ele1);
                List <XYZ> listendpoint2  = Support.GetStartEndDimensio(ele2);
                List <XYZ> TwoPointEndDim = Support.GetDimensionPointsEnd(doc, ele1);

                XYZ test1 = TwoPointEndDim[0];
                test1 = Support.ProjectOnto(plane, test1);
                XYZ test2 = TwoPointEndDim[1];
                test2 = Support.ProjectOnto(plane, test2);
                XYZ tp = new XYZ(2, 0, 0);

                Plane plane1 = Plane.CreateByNormalAndOrigin(line1.Direction.Normalize(), test2 - tp);
                #region Create line:
                var min1   = double.MaxValue;
                XYZ Point1 = XYZ.Zero;
                XYZ Point2 = XYZ.Zero;

                foreach (var point in listendpoint1)
                {
                    var distance = giaodiem.DistanceTo(point);
                    if (distance < min1)
                    {
                        Point1 = point;
                        min1   = distance;
                    }
                }
                var min2 = double.MaxValue;
                foreach (var point in listendpoint2)
                {
                    var distance = giaodiem.DistanceTo(point);
                    if (distance < min2)
                    {
                        Point2 = point;
                        min2   = distance;
                    }
                }
                Point1 = Support.ProjectOnto(plane, Point1);
                Point2 = Support.ProjectOnto(plane, Point2);

                XYZ ep21  = Support.ProjectOnto(plane, listendpoint2[0]);
                XYZ ep222 = Support.ProjectOnto(plane, listendpoint2[1]);

                DetailCurve cur1 = Support.createdetailcurve(doc, Point1, giaodiem, plane);
                DetailCurve cur3 = Support.createdetailcurve(doc, Point2, giaodiem, plane);
                #endregion

                #region : Create text
                List <Element> list1 = new List <Element>();
                List <Element> list2 = new List <Element>();

                for (int aa = 1; aa < ele1.Segments.Size; aa++)
                {
                    Reference ref1     = ele1.References.get_Item(aa);
                    Element   element1 = doc.GetElement(ref1);
                    if (element1.Name != null && element1.Category.Name == "Specialty Equipment")
                    {
                        list1.Add(element1);
                    }
                }

                for (int bb = 1; bb < ele2.Segments.Size; bb++)
                {
                    Reference ref2     = ele2.References.get_Item(bb);
                    Element   element2 = doc.GetElement(ref2);
                    if (element2.Name != null && element2.Category.Name == "Specialty Equipment")
                    {
                        list2.Add(element2);
                    }
                }

                XYZ             kc  = new XYZ(0, 0, 0);
                XYZ             pos = new XYZ(0, 0, 0);
                ElementId       defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
                TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId);
                opts.HorizontalAlignment = HorizontalTextAlignment.Left;
                string s1 = list1.First().Name;

                #region : Create location
                FilteredElementCollector filter  = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_MultiCategoryTags);
                List <Element>           listtag = filter.OfCategory(BuiltInCategory.OST_MultiCategoryTags).WhereElementIsNotElementType().ToElements().ToList();
                List <Element>           sametag = new List <Element>();

                foreach (var item in listtag)
                {
                    IndependentTag el   = doc.GetElement(item.Id) as IndependentTag;
                    Element        tag1 = el.GetTaggedLocalElement();
                    string         tag  = tag1.Name;
                    if (tag == list1.First().Name)
                    {
                        sametag.Add(item);
                    }
                }

                string lastname = "";
                if (sametag.Count > 0)
                {
                    Element elem1     = doc.GetElement(sametag.First().Id) as Element;
                    string  samename  = elem1.Name;
                    int     gachngang = samename.LastIndexOf("-");
                    lastname = samename.Substring(gachngang + 1);
                    string s11 = s1 + "\n" + "(" + lastname + ")";
                }
                if (sametag.Count == 0)
                {
                    lastname = " ";
                }

                #endregion

                if (giaodiem.DistanceTo(test1) < giaodiem.DistanceTo(test2))
                {
                    FamilyInstance newinstance = null;;
                    XYZ            kt          = new XYZ(0, 0, 0);
                    if (line1.Direction.DotProduct(XYZ.BasisX) == -1)
                    {
                        kt = new XYZ(-3.3, 0, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisX) == 1)
                    {
                        kt = new XYZ(3.3, 0, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisZ) == -1)
                    {
                        kt = new XYZ(0, 0, -3.3);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisZ) == 1)
                    {
                        kt = new XYZ(0, 0, 3.3);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisY) == 1)
                    {
                        kt = new XYZ(0, 4, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisY) == -1)
                    {
                        kt = new XYZ(0, -4, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1)
                    {
                        kt = new XYZ(0, 0, 0);
                    }
                    newinstance = doc.Create.NewFamilyInstance(test1 - kt, symbol, doc.ActiveView);
                    #region : Create symbol
                    newinstance.LookupParameter("Part No.").Set(s1);
                    newinstance.LookupParameter("TEXT 3").Set("CL" + " (" + list1.Count * list2.Count + ")");
                    newinstance.LookupParameter("TEXT 2").Set(lastname);
                    #endregion
                }

                else
                {
                    FamilyInstance newinstance = null;
                    #region : Create symbol
                    if (line1.Direction.DotProduct(XYZ.BasisX) == -1)
                    {
                        XYZ kt = new XYZ(0.7, 0, 0);
                        newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisX) == 1)
                    {
                        XYZ kt = new XYZ(0, 0, 0);
                        newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisZ) == 1)
                    {
                        XYZ kt = new XYZ(0, 0, 0);
                        newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisY) == 1)
                    {
                        XYZ kt = new XYZ(0, 3.2, 0);
                        newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisY) == -1)
                    {
                        XYZ kt = new XYZ(0, 0, 0);
                        newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1)
                    {
                        XYZ kt = new XYZ(0, 0, 0);
                        newinstance = doc.Create.NewFamilyInstance(test2 - kt, symbol, doc.ActiveView);
                    }

                    ICollection <ElementId> result    = new List <ElementId>();
                    ICollection <ElementId> newresult = new List <ElementId>();
                    result.Add(newinstance.Id);
                    ElementTransformUtils.RotateElement(doc, newinstance.Id, line2, Math.PI * 0.5);
                    newresult = ElementTransformUtils.MirrorElements(doc, result, plane1, true);
                    doc.Delete(newinstance.Id);
                    FamilyInstance famiin = doc.GetElement(newresult.First()) as FamilyInstance;
                    famiin.LookupParameter("Part No.").Set(s1);
                    famiin.LookupParameter("TEXT 3").Set("CL" + " (" + list1.Count * list2.Count + ")");
                    famiin.LookupParameter("TEXT 2").Set(lastname);
                    #endregion
                }
                #endregion
            }

            else
            {
                List <XYZ> listendpoint1 = Support.GetStartEndDimensio(ele1);

                List <XYZ> TwoPointEndDim = Support.GetDimensionPointsEnd(doc, ele1);

                XYZ test1 = TwoPointEndDim[0];
                test1 = Support.ProjectOnto(plane, test1);
                XYZ test2 = TwoPointEndDim[1];
                test2 = Support.ProjectOnto(plane, test2);
                XYZ Point2 = XYZ.Zero;
                #region
                //if (line1.Direction.DotProduct(XYZ.BasisY) == -1)
                //{
                //    Point2 = test1 + kc1;
                //    Point2 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point2);
                //    DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test1, Point2, plane);
                //}

                //if (Math.Round(line1.Direction.DotProduct(XYZ.BasisY), 2) == 1)
                //{
                //    Point2 = test1 + kc11;
                //    Point2 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point2);

                //    DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test1, Point2, plane);
                //}

                //if (line1.Direction.DotProduct(XYZ.BasisZ) == 1)
                //{
                //    Point2 = test2 + kc2;
                //    Point2 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point2);
                //    test1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, test1);
                //    DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test2, Point2, plane);
                //}

                //if (line1.Direction.DotProduct(XYZ.BasisZ) == -1)
                //{
                //    Point2 = test1 + kc22;
                //    Point2 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point2);
                //    test1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, test1);
                //    DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test1, Point2, plane);
                //}

                //if (line1.Direction.DotProduct(XYZ.BasisX) == 1)
                //{
                //    Point1 = test2 - kc23;
                //    Point1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point1);
                //    test1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, test1);
                //    DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test2, Point1, plane);
                //}

                //if (line1.Direction.DotProduct(XYZ.BasisX) == -1)
                //{
                //    Point1 = test1 + kc23;
                //    Point1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, Point1);
                //    test1 = SUPPORT.PLANE.PlaneHelper.ProjectOnto(plane, test1);
                //    DetailCurve cur1 = SUPPORT.LINE.LINE.createdetailcurve(doc, test1, Point1, plane);
                //}
                ////if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisY) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != 1)
                ////{
                ////    CreateExtenline(doc, plane, ele1, 3.5);
                ////}

                //foreach (var point in listendpoint1)
                //{
                //    var distance = kc1.DistanceTo(point);
                //    if (distance < min1)
                //    {
                //        Point1 = point;
                //        min1 = distance;
                //    }
                //}
                #endregion

                #region : Create text
                List <Element> list1 = new List <Element>();

                for (int aa = 1; aa < ele1.Segments.Size; aa++)
                {
                    Reference ref1     = ele1.References.get_Item(aa);
                    Element   element1 = doc.GetElement(ref1);
                    if (element1.Name != null && element1.Category.Name == "Specialty Equipment")
                    {
                        list1.Add(element1);
                    }
                }

                //XYZ pos = null;
                ElementId       defaultTextTypeId = doc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType);
                TextNoteOptions opts = new TextNoteOptions(defaultTextTypeId);
                string          s1   = list1.First().Name;

                XYZ    vector = test1 - test2;
                Double x      = vector.DotProduct(XYZ.BasisX);
                Double y      = vector.DotProduct(XYZ.BasisY);
                Double z      = vector.DotProduct(XYZ.BasisZ);

                FamilyInstance newinstance = null;

                if (Support.IsHorizontal(vector, doc.ActiveView) == true)
                {
                    XYZ kt = new XYZ(0, 0, 0);
                    if (line1.Direction.DotProduct(XYZ.BasisX) == -1)
                    {
                        kt = new XYZ(-3.2, 0, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisX) == 1)
                    {
                        kt = new XYZ(3.2, 0, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisZ) == -1)
                    {
                        kt = new XYZ(0, 0, -3.2);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisZ) == 1)
                    {
                        kt = new XYZ(0, 0, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisY) == 1)
                    {
                        kt = new XYZ(0, 3.2, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisY) == -1)
                    {
                        kt = new XYZ(0, (3.2 + Support.Totaldim(ele1)), 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1)
                    {
                        kt = new XYZ(0, (3.2 + Support.Totaldim(ele1)), 0);
                    }
                    newinstance = doc.Create.NewFamilyInstance(test1, symbol, doc.ActiveView);
                }

                if (Support.IsVertical(vector, doc.ActiveView) == true)
                {
                    XYZ kt = new XYZ(0, 0, 0);
                    if (line1.Direction.DotProduct(XYZ.BasisX) == 1)
                    {
                        kt = new XYZ(-(Support.Totaldim(ele1) + 3.2), 0, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisX) == -1)
                    {
                        kt = new XYZ(-3.2, 0, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisZ) == 1)
                    {
                        kt = new XYZ(0, 0, -(Support.Totaldim(ele1) + 3.2));
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisZ) == -1)
                    {
                        kt = new XYZ(0, 0, -3.2);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisY) == -1)
                    {
                        kt = new XYZ(0, 3.2, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisY) == 1)
                    {
                        kt = new XYZ(0, 3.2, 0);
                    }
                    if (line1.Direction.DotProduct(XYZ.BasisX) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisY) != -1 && line1.Direction.DotProduct(XYZ.BasisX) != 1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1 && line1.Direction.DotProduct(XYZ.BasisZ) != -1)
                    {
                        kt = new XYZ(0, 0, 0);
                    }
                    newinstance = doc.Create.NewFamilyInstance(test1, symbol1, doc.ActiveView);
                }

                if (Support.IsHorizontal(vector, doc.ActiveView) == false && Support.IsVertical(vector, doc.ActiveView) == false)
                {
                    newinstance = doc.Create.NewFamilyInstance(test1, symbol, doc.ActiveView);
                }
                #endregion
                #region : Create location
                FilteredElementCollector filter  = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_MultiCategoryTags);
                List <Element>           listtag = filter.OfCategory(BuiltInCategory.OST_MultiCategoryTags).WhereElementIsNotElementType().ToElements().ToList();
                List <Element>           sametag = new List <Element>();
                foreach (var item in listtag)
                {
                    IndependentTag el   = doc.GetElement(item.Id) as IndependentTag;
                    Element        tag1 = el.GetTaggedLocalElement();
                    string         tag  = tag1.Name;

                    if (tag == list1.First().Name)
                    {
                        sametag.Add(item);
                    }
                }
                try
                {
                    if (sametag.Count > 0)
                    {
                        Element elem1     = doc.GetElement(sametag.First().Id) as Element;
                        string  samename  = elem1.Name;
                        int     gachngang = samename.LastIndexOf("-");
                        string  lastname  = samename.Substring(gachngang + 1);
                        string  s11       = s1 + "\n" + "(" + lastname + ")";
                        #region : Create symbol
                        newinstance.LookupParameter("Part No.").Set(s1);
                        newinstance.LookupParameter("TEXT 3").Set("CL" + " (" + list1.Count + ")");
                        newinstance.LookupParameter("TEXT 2").Set(lastname);
                        #endregion
                    }
                    else
                    {
                        newinstance.LookupParameter("Part No.").Set(s1);
                        newinstance.LookupParameter("TEXT 3").Set("CL" + " (" + list1.Count + ")");
                        newinstance.LookupParameter("TEXT 2").Set(" ");
                    }
                }
                catch { };

                #endregion
            }
        }