Exemple #1
0
        /// <summary>
        /// Converts text note align to box align.
        /// </summary>
        /// <param name="textNote">
        /// The text note element.
        /// </param>
        /// <param name="xFactor">
        /// The X factor.
        /// </param>
        /// <param name="yFactor">
        /// The Y factor.
        /// </param>
        static string ConvertTextNoteAlignToBoxAlign(TextNote textNote, out double xFactor, out double yFactor)
        {
            TextAlignFlags align = textNote.Align;

            int alignCase = 0;

            if ((align & TextAlignFlags.TEF_ALIGN_LEFT) != 0)
            {
                if ((align & TextAlignFlags.TEF_ALIGN_TOP) != 0)
                {
                    alignCase = 0;
                }
                else if ((align & TextAlignFlags.TEF_ALIGN_BOTTOM) != 0)
                {
                    alignCase = 1;
                }
                else
                {
                    alignCase = 2;
                }
            }
            else if ((align & TextAlignFlags.TEF_ALIGN_RIGHT) != 0)
            {
                if ((align & TextAlignFlags.TEF_ALIGN_TOP) != 0)
                {
                    alignCase = 7;
                }
                else if ((align & TextAlignFlags.TEF_ALIGN_BOTTOM) != 0)
                {
                    alignCase = 8;
                }
                else
                {
                    alignCase = 6;
                }
            }
            else
            {
                if ((align & TextAlignFlags.TEF_ALIGN_TOP) != 0)
                {
                    alignCase = 3;
                }
                else if ((align & TextAlignFlags.TEF_ALIGN_BOTTOM) != 0)
                {
                    alignCase = 5;
                }
                else
                {
                    alignCase = 4;
                }
            }

            xFactor = 0.0;
            yFactor = 0.0;
            string boxAlignmeng = null;

            switch (alignCase)
            {
            case 0:
                boxAlignmeng = "top-left";
                xFactor      = -1.0;
                yFactor      = 1.0;
                break;

            case 1:
                boxAlignmeng = "bottom-left";
                xFactor      = -1.0;
                yFactor      = -1.0;
                break;

            case 2:
                boxAlignmeng = "middle-left";
                xFactor      = -1.0;
                break;

            case 3:
                boxAlignmeng = "top-middle";
                yFactor      = 1.0;
                break;

            case 4:
                boxAlignmeng = "center";
                break;

            case 5:
                boxAlignmeng = "bottom-middle";
                yFactor      = -1.0;
                break;

            case 6:
                boxAlignmeng = "middle-right";
                xFactor      = 1.0;
                break;

            case 7:
                boxAlignmeng = "top-right";
                xFactor      = 1.0;
                yFactor      = 1.0;
                break;

            case 8:
                boxAlignmeng = "bottom-right";
                xFactor      = 1.0;
                yFactor      = -1.0;
                break;
            }

            return(boxAlignmeng);
        }
Exemple #2
0
        RoomArea()
        {
            Revit.Creation.Document doc         = m_revitApp.ActiveUIDocument.Document.Create;
            SketchPlane             sketchPlane = Utils.Geometry.GetWorldPlane(m_revitApp);

            RevitLookup.Test.Forms.Levels lev = new RevitLookup.Test.Forms.Levels(m_revitApp);
            if (lev.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Level curLevel = lev.LevelSelected;

            if (curLevel == null)
            {
                MessageBox.Show("No Level was selected.");
                return;
            }

            // Get the plan topology of the active doc first
            PlanTopology            planTopo = m_revitApp.ActiveUIDocument.Document.get_PlanTopology(curLevel);
            ICollection <ElementId> roomIds  = planTopo.GetRoomIds();

            if (roomIds.Count > 0)
            {
                IEnumerator <ElementId> setIter = roomIds.GetEnumerator();
                while (setIter.MoveNext())
                {
                    Room room = m_revitApp.ActiveUIDocument.Document.GetElement(setIter.Current) as Room;
                    if (null != room)
                    {
                        Autodesk.Revit.DB.View view          = m_revitApp.ActiveUIDocument.Document.ActiveView;
                        LocationPoint          locationPoint = room.Location as LocationPoint;

                        Double area = room.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble();

                        Double roundedArea = Math.Round(area, 2);

                        // providing an offset so that the Room Tag and the Area Tag dont overlap. Overlapping leads to an
                        // alignment related assert.

                        XYZ offset = new XYZ(5.0, 0, 0);

                        /// align text middle and center
                        TextAlignFlags align   = TextAlignFlags.TEF_ALIGN_MIDDLE ^ TextAlignFlags.TEF_ALIGN_CENTER;
                        TextNote       txtNote = m_revitApp.ActiveUIDocument.Document.Create.NewTextNote(view, offset + locationPoint.Point, GeomUtils.kXAxis,
                                                                                                         view.ViewDirection, .25,
                                                                                                         align, roundedArea.ToString());
                    }
                }
            }
            else
            {
                MessageBox.Show("No rooms found in the Active Document", "RevitLookup", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }


            // TBD: Tried to play around with PlanCircuits and there seems to be a problem with the IsRoomLocated property.
            // arj 1/23/07

            //Revit.PlanCircuitSet circSet = planTopo.Circuits;
            //Revit.PlanCircuitSetIterator setIters = circSet.ForwardIterator();

            //while (setIters.MoveNext())
            //{
            //    Revit.PlanCircuit planCircuit = setIters.Current as Revit.PlanCircuit;

            //    if (null != planCircuit)
            //    {
            //
            //        if (planCircuit.IsRoomLocated) // throws an exception always "Attempted to read or write protected memory.
            // This is often an indication that other memory is corrupt."
            //        {
            //        }
            //    }
            //}
        }
Exemple #3
0
 public void DrawTransparentText(string str, IntPtr LogFont, Color color, Point point, Size size, TextAlignFlags flags)
 {
     DrawTransparentText(LogFont, str, color, point, size, flags, false);
 }
Exemple #4
0
 public void DrawMultilineTransparentText(string str, Font font, Color color, Point point, Size size, TextAlignFlags flags)
 {
     DrawTransparentText(GetCachedHFont(font), str, color, point, size, flags, true);
 }
Exemple #5
0
    private void DrawTransparentText(IntPtr fontHandle, string str, Color color, Point point, Size size, TextAlignFlags flags, bool multilineSupport)
    {
        // Create a memory DC so we can work off-screen
        IntPtr memoryHdc = CreateCompatibleDC(_hdc);

        SetBkMode(memoryHdc, 1);

        // Create a device-independent bitmap and select it into our DC
        var info = new BitMapInfo();

        info.biSize        = Marshal.SizeOf(info);
        info.biWidth       = size.Width;
        info.biHeight      = -size.Height;
        info.biPlanes      = 1;
        info.biBitCount    = 32;
        info.biCompression = 0; // BI_RGB
        IntPtr ppvBits;
        IntPtr dib = CreateDIBSection(_hdc, ref info, 0, out ppvBits, IntPtr.Zero, 0);

        SelectObject(memoryHdc, dib);

        try
        {
            // copy target background to memory HDC so when copied back it will have the proper background
            BitBlt(memoryHdc, 0, 0, size.Width, size.Height, _hdc, point.X, point.Y, 0x00CC0020);

            // Create and select font
            SelectObject(memoryHdc, fontHandle);
            SetTextColor(memoryHdc, (color.B & 0xFF) << 16 | (color.G & 0xFF) << 8 | color.R);

            Size  strSize = new Size();
            Point pos     = new Point();

            if (multilineSupport)
            {
                TextFormatFlags fmtFlags = TextFormatFlags.WordBreak;
                // Aligment
                if (flags.HasFlag(TextAlignFlags.Center))
                {
                    fmtFlags |= TextFormatFlags.Center;
                }
                if (flags.HasFlag(TextAlignFlags.Right))
                {
                    fmtFlags |= TextFormatFlags.Right;
                }

                // Calculate the string size
                Rect strRect = new Rect(new Rectangle(point, size));
                DrawText(memoryHdc, str, str.Length, ref strRect, TextFormatFlags.CalcRect | fmtFlags);

                if (flags.HasFlag(TextAlignFlags.Middle))
                {
                    pos.Y = ((size.Height) >> 1) - (strRect.Height >> 1);
                }
                if (flags.HasFlag(TextAlignFlags.Bottom))
                {
                    pos.Y = (size.Height) - (strRect.Height);
                }

                // Draw Text for multiline format
                Rect region = new Rect(new Rectangle(pos, size));
                DrawText(memoryHdc, str, str.Length, ref region, fmtFlags);
            }
            else
            {
                // Calculate the string size
                GetTextExtentPoint32(memoryHdc, str, str.Length, ref strSize);
                // Aligment
                if (flags.HasFlag(TextAlignFlags.Center))
                {
                    pos.X = ((size.Width) >> 1) - (strSize.Width >> 1);
                }
                if (flags.HasFlag(TextAlignFlags.Right))
                {
                    pos.X = (size.Width) - (strSize.Width);
                }

                if (flags.HasFlag(TextAlignFlags.Middle))
                {
                    pos.Y = ((size.Height) >> 1) - (strSize.Height >> 1);
                }
                if (flags.HasFlag(TextAlignFlags.Bottom))
                {
                    pos.Y = (size.Height) - (strSize.Height);
                }

                // Draw text to memory HDC
                TextOut(memoryHdc, pos.X, pos.Y, str, str.Length);
            }

            // copy from memory HDC to normal HDC with alpha blend so achieve the transparent text
            AlphaBlend(_hdc, point.X, point.Y, size.Width, size.Height, memoryHdc, 0, 0, size.Width, size.Height, new BlendFunction(color.A));
        }
        finally
        {
            DeleteObject(dib);
            DeleteDC(memoryHdc);
        }
    }