private List <XYZ> CreateTagPositionPoints(View activeView, List <TagLeader> tagLeaders, ViewSides side)
        {
            List <XYZ>     xyzList = new List <XYZ>();
            BoundingBoxXYZ cropBox = activeView.get_CropBox();

            if ((uint)tagLeaders.Count > 0U)
            {
                double num1 = tagLeaders.Max <TagLeader>((Func <TagLeader, double>)(x => x.TagHeight));
                tagLeaders.Max <TagLeader>((Func <TagLeader, double>)(x => x.TagWidth));
                double num2 = num1 * 1.2;
                int    num3 = (int)Math.Round((cropBox.get_Max().get_Y() - cropBox.get_Min().get_Y()) / num2);
                XYZ    xyz1 = new XYZ(cropBox.get_Max().get_X(), cropBox.get_Min().get_Y(), 0.0);
                XYZ    xyz2 = new XYZ(cropBox.get_Min().get_X(), cropBox.get_Min().get_Y(), 0.0);
                for (int index = num3 * 2; index > 0; --index)
                {
                    if (side == ViewSides.Left)
                    {
                        xyzList.Add(XYZ.op_Addition(xyz2, new XYZ(0.0, num2 * (double)index, 0.0)));
                    }
                    else
                    {
                        xyzList.Add(XYZ.op_Addition(xyz1, new XYZ(0.0, num2 * (double)index, 0.0)));
                    }
                }
            }
            return(xyzList);
        }
Example #2
0
        private void GetTagDimension()
        {
            BoundingBoxXYZ boundingBox = ((Element)this._tag).get_BoundingBox(this._currentView);
            BoundingBoxXYZ cropBox     = this._currentView.get_CropBox();

            this._tagHeight  = cropBox.get_Transform().get_Inverse().OfPoint(boundingBox.get_Max()).get_Y() - cropBox.get_Transform().get_Inverse().OfPoint(boundingBox.get_Min()).get_Y();
            this._tagWidth   = cropBox.get_Transform().get_Inverse().OfPoint(boundingBox.get_Max()).get_X() - cropBox.get_Transform().get_Inverse().OfPoint(boundingBox.get_Min()).get_X();
            this._tagCenter  = XYZ.op_Division(XYZ.op_Addition(cropBox.get_Transform().get_Inverse().OfPoint(boundingBox.get_Max()), cropBox.get_Transform().get_Inverse().OfPoint(boundingBox.get_Min())), 2.0);
            this._tagCenter  = new XYZ(this._tagCenter.get_X(), this._tagCenter.get_Y(), 0.0);
            this._headOffset = XYZ.op_Subtraction(this._tagHeadPosition, this._tagCenter);
        }
        public AnnotationElement(Element e)
        {
            this.Parent     = e;
            this._doc       = e.get_Document();
            this._ownerView = this._doc.GetElement(e.get_OwnerViewId()) == null?this._doc.get_ActiveView() : this._doc.GetElement(e.get_OwnerViewId()) as View;

            Plane          byNormalAndOrigin = Plane.CreateByNormalAndOrigin(this._ownerView.get_ViewDirection(), this._ownerView.get_Origin());
            BoundingBoxXYZ boundingBox       = e.get_BoundingBox(this._ownerView);
            XYZ            pointA1           = boundingBox.get_Max();
            XYZ            pointB1           = boundingBox.get_Min();
            double         num     = this.ProjectedDistance(byNormalAndOrigin, pointA1, pointB1);
            XYZ            pointA2 = new XYZ(pointA1.get_X(), pointB1.get_Y(), pointA1.get_Z());
            XYZ            pointB2 = new XYZ(pointB1.get_X(), pointA1.get_Y(), pointB1.get_Z());

            if (this.ProjectedDistance(byNormalAndOrigin, pointA2, pointB2) > num)
            {
                pointA1 = pointA2;
                pointB1 = pointB2;
            }
            Transform transform = this._ownerView.get_CropBox().get_Transform();
            XYZ       xyz1      = transform.get_Inverse().OfPoint(pointA1);
            XYZ       xyz2      = transform.get_Inverse().OfPoint(pointB1);

            this.UpLeft    = new XYZ(this.GetMin(xyz2.get_X(), xyz1.get_X()), this.GetMax(xyz1.get_Y(), xyz2.get_Y()), 0.0);
            this.UpRight   = new XYZ(this.GetMax(xyz2.get_X(), xyz1.get_X()), this.GetMax(xyz1.get_Y(), xyz2.get_Y()), 0.0);
            this.DownLeft  = new XYZ(this.GetMin(xyz2.get_X(), xyz1.get_X()), this.GetMin(xyz1.get_Y(), xyz2.get_Y()), 0.0);
            this.DownRight = new XYZ(this.GetMax(xyz2.get_X(), xyz1.get_X()), this.GetMin(xyz1.get_Y(), xyz2.get_Y()), 0.0);
            this.Center    = XYZ.op_Division(XYZ.op_Addition(this.UpRight, this.DownLeft), 2.0);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication  val   = commandData.get_Application();
            Document       val2  = val.get_ActiveUIDocument().get_Document();
            IList <View3D> views = new FilteredElementCollector(val2).WhereElementIsNotElementType().OfClass(typeof(View3D)).ToElements()
                                   .Cast <View3D>()
                                   .ToList();
            ViewsForZonesForm viewsForZonesForm = new ViewsForZonesForm(views, val2.get_ActiveView() as View3D);

            viewsForZonesForm.ShowDialog();
            if (viewsForZonesForm.DialogResult != DialogResult.OK)
            {
                return(1);
            }
            View3D selectedView = viewsForZonesForm.SelectedView;
            XYZ    val3         = new XYZ(0.0 - VIEW_CROP_OFFSETS[5], 0.0 - VIEW_CROP_OFFSETS[3], 0.0 - VIEW_CROP_OFFSETS[1]);
            XYZ    val4         = new XYZ(VIEW_CROP_OFFSETS[4], VIEW_CROP_OFFSETS[2], VIEW_CROP_OFFSETS[0]);
            IList <FamilyInstance> projectZones = ZoneData.GetProjectZones(val2);
            Transaction            val5         = new Transaction(val2, "Create Views for Project Zones");

            try
            {
                val5.Start();
                foreach (FamilyInstance item in projectZones)
                {
                    ElementId      val6 = selectedView.Duplicate(0);
                    View3D         val7 = val2.GetElement(val6) as View3D;
                    BoundingBoxXYZ val8 = item.get_BoundingBox(null);
                    BoundingBoxXYZ val9 = new BoundingBoxXYZ();
                    val9.set_Min(val8.get_Min() + val3);
                    val9.set_Max(val8.get_Max() + val4);
                    val7.set_Name("3D " + item.LookupParameter("Name").AsString());
                    val7.SetSectionBox(val9);
                }
                val5.Commit();
            }
            catch (OperationCanceledException)
            {
                return(1);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(-1);
            }
            return(0);
        }
Example #5
0
        protected static Line CreateDimensionLine(FamilyInstance projectZone, Directions side, double dimOffset)
        {
            BoundingBoxXYZ val = projectZone.get_BoundingBox(null);
            double         num;
            double         num2;

            switch (side)
            {
            case Directions.North:
                num  = val.get_Max().get_Y();
                num2 = 0.5 * (val.get_Min().get_X() + val.get_Max().get_X());
                break;

            case Directions.South:
                num  = val.get_Min().get_Y();
                num2 = 0.5 * (val.get_Min().get_X() + val.get_Max().get_X());
                break;

            case Directions.East:
                num  = val.get_Max().get_X();
                num2 = 0.5 * (val.get_Min().get_Y() + val.get_Max().get_Y());
                break;

            case Directions.West:
                num  = val.get_Min().get_X();
                num2 = 0.5 * (val.get_Min().get_Y() + val.get_Max().get_Y());
                break;

            default:
                throw new ArgumentException("Side must be north, south, east, or west");
            }
            XYZ val2;
            XYZ val3;

            if ((uint)side > 1u)
            {
                if ((uint)(side - 2) > 1u)
                {
                    throw new ArgumentException("Side must be north, south, east, or west");
                }
                val2 = new XYZ(num, num2, 0.0);
                val3 = new XYZ(num - dimOffset, num2, 0.0);
            }
            else
            {
                val2 = new XYZ(num2, num, 0.0);
                val3 = new XYZ(num2, num - dimOffset, 0.0);
            }
            return(Line.CreateBound(val2, val3));
        }
Example #6
0
        public static XYZ GetLeaderEnd(Element taggedElement, View currentView)
        {
            BoundingBoxXYZ boundingBox = taggedElement.get_BoundingBox(currentView);
            BoundingBoxXYZ cropBox     = currentView.get_CropBox();
            XYZ            xyz1        = new XYZ();
            XYZ            xyz2        = boundingBox == null?XYZ.op_Addition(XYZ.op_Division(XYZ.op_Addition(cropBox.get_Max(), cropBox.get_Min()), 2.0), new XYZ(0.001, 0.0, 0.0)) : XYZ.op_Division(XYZ.op_Addition(boundingBox.get_Max(), boundingBox.get_Min()), 2.0);

            XYZ xyz3 = cropBox.get_Transform().get_Inverse().OfPoint(xyz2);

            return(new XYZ(Math.Round(xyz3.get_X(), 4), Math.Round(xyz3.get_Y(), 4), 0.0));
        }
 private static Outline ToOutline(BoundingBoxXYZ bb)
 {
     return(new Outline(bb.get_Min(), bb.get_Max()));
 }
Example #8
0
        protected static Reference[] GetSideReferences(FamilyInstance projectZone, View view)
        {
            Reference[]    array = (Reference[])new Reference[4];
            BoundingBoxXYZ val   = projectZone.get_BoundingBox(null);
            double         c     = val.get_Max().get_X() - val.get_Min().get_X();
            double         c2    = val.get_Max().get_Y() - val.get_Min().get_Y();
            double         z     = val.get_Min().get_Z();
            Options        val2  = new Options();

            val2.set_ComputeReferences(true);
            val2.set_View(view);
            GeometryElement  source = projectZone.get_Geometry(val2);
            GeometryInstance val3   = ((IEnumerable <GeometryObject>)source).First((GeometryObject g) => g is GeometryInstance) as GeometryInstance;
            GeometryElement  val4   = val3.get_SymbolGeometry();
            int num = 0;

            foreach (GeometryObject item in val4)
            {
                if (item is Line)
                {
                    Line val5 = item as Line;
                    if (!(val5.GetEndPoint(0).get_Z() >= z + 0.01) && !(val5.GetEndPoint(1).get_Z() >= z + 0.01))
                    {
                        Directions?nullable = null;
                        if (val5.get_Direction().get_X() >= 0.99 || val5.get_Direction().get_X() <= -0.99)
                        {
                            double y = val5.GetEndPoint(0).get_Y();
                            if (NearlyIntersects(y, c2))
                            {
                                nullable = Directions.North;
                            }
                            else if (NearlyIntersects(y, 0.0))
                            {
                                nullable = Directions.South;
                            }
                        }
                        else if (val5.get_Direction().get_Y() >= 0.99 || val5.get_Direction().get_Y() <= -0.99)
                        {
                            double x = val5.GetEndPoint(0).get_X();
                            if (NearlyIntersects(x, c))
                            {
                                nullable = Directions.East;
                            }
                            else if (NearlyIntersects(x, 0.0))
                            {
                                nullable = Directions.West;
                            }
                        }
                        if (nullable.HasValue && array[(int)nullable.Value] == null)
                        {
                            array[(int)nullable.Value] = val5.get_Reference();
                            num++;
                            if (num == 4)
                            {
                                return(array);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Example #9
0
        public ZoneData(Element zone)
        {
            Document val = zone.get_Document();

            Name       = zone.LookupParameter("Name").AsString();
            UniqueId   = zone.get_UniqueId();
            TopLevel   = (val.GetElement(zone.LookupParameter("Top Level").AsElementId()) as Level);
            BaseLevel  = (val.GetElement(zone.LookupParameter("Base Level").AsElementId()) as Level);
            TopOffset  = zone.LookupParameter("Top Offset").AsDouble();
            BaseOffset = zone.LookupParameter("Base Offset").AsDouble();
            BoundingBoxXYZ    val2 = zone.get_BoundingBox(null);
            double            y    = val2.get_Max().get_Y();
            double            y2   = val2.get_Min().get_Y();
            double            x    = val2.get_Max().get_X();
            double            x2   = val2.get_Min().get_X();
            IList <Dimension> list = LookupAssociatedDimensions(zone);

            foreach (Dimension item in list)
            {
                Grid val3 = null;
                foreach (Reference reference in item.get_References())
                {
                    Reference val4 = reference;
                    Element   val5 = val.GetElement(val4);
                    if (val5 is Grid)
                    {
                        val3 = (val5 as Grid);
                    }
                }
                double num = item.get_Value() ?? 0.0;
                if (num == 0.0)
                {
                    if (NearlyIntersects(item.get_Origin().get_Y(), y))
                    {
                        NorthGrid   = val3;
                        NorthOffset = 0.0;
                        m_AssociatedDimensions[0] = item;
                    }
                    else if (NearlyIntersects(item.get_Origin().get_Y(), y2))
                    {
                        SouthGrid   = val3;
                        SouthOffset = 0.0;
                        m_AssociatedDimensions[1] = item;
                    }
                    else if (NearlyIntersects(item.get_Origin().get_X(), x))
                    {
                        EastGrid   = val3;
                        EastOffset = 0.0;
                        m_AssociatedDimensions[2] = item;
                    }
                    else if (NearlyIntersects(item.get_Origin().get_X(), x2))
                    {
                        WestGrid   = val3;
                        WestOffset = 0.0;
                        m_AssociatedDimensions[3] = item;
                    }
                }
                else
                {
                    Line val6  = item.get_Curve() as Line;
                    bool flag  = val6.get_Direction().get_Y() >= 0.99 || val6.get_Direction().get_Y() <= -0.99;
                    bool flag2 = val6.get_Direction().get_X() >= 0.99 || val6.get_Direction().get_X() <= -0.99;
                    if (flag)
                    {
                        double[] array = new double[2]
                        {
                            item.get_Origin().get_Y() - num / 2.0,
                                 item.get_Origin().get_Y() + num / 2.0
                        };
                        for (int i = 0; i <= 1; i++)
                        {
                            if (NearlyIntersects(array[i], y))
                            {
                                NorthGrid   = val3;
                                NorthOffset = ((i == 1) ? num : (0.0 - num));
                                m_AssociatedDimensions[0] = item;
                                break;
                            }
                            if (NearlyIntersects(array[i], y2))
                            {
                                SouthGrid   = val3;
                                SouthOffset = ((i == 1) ? num : (0.0 - num));
                                m_AssociatedDimensions[1] = item;
                                break;
                            }
                        }
                    }
                    else if (flag2)
                    {
                        double[] array2 = new double[2]
                        {
                            item.get_Origin().get_X() - num / 2.0,
                                 item.get_Origin().get_X() + num / 2.0
                        };
                        for (int j = 0; j <= 1; j++)
                        {
                            if (NearlyIntersects(array2[j], x))
                            {
                                EastGrid   = val3;
                                EastOffset = ((j == 1) ? num : (0.0 - num));
                                m_AssociatedDimensions[2] = item;
                                break;
                            }
                            if (NearlyIntersects(array2[j], x2))
                            {
                                WestGrid   = val3;
                                WestOffset = ((j == 1) ? num : (0.0 - num));
                                m_AssociatedDimensions[3] = item;
                                break;
                            }
                        }
                    }
                }
            }
            if ((object)NorthGrid == null)
            {
                NorthOffset = y;
            }
            if ((object)SouthGrid == null)
            {
                SouthOffset = y2;
            }
            if ((object)EastGrid == null)
            {
                EastOffset = x;
            }
            if ((object)WestGrid == null)
            {
                WestOffset = x2;
            }
        }