Beispiel #1
0
        public void SetTextProperties(Document doc, TextNote txt, TextFormattingContainer format)
        {
            FormattedText tFormatted = txt.GetFormattedText();

            TextNoteType type = doc.GetElement(new ElementId(format.textNoteTypeID)) as TextNoteType;

            txt.TextNoteType = type;

            Debug("textNoteAllCaps Paint " + format.textNoteAllCapsStatus.ToString());

            if (format.textNoteAllCapsStatus)
            {
                string currentPlainText = tFormatted.GetPlainText();
                Debug("text formatted Plain Text Paint " + currentPlainText);
                string upperCase = currentPlainText.ToUpper();
                tFormatted.SetPlainText(upperCase);
                Debug("text formatted Plain Text Updates Paint " + tFormatted.GetPlainText().ToString());
            }

            tFormatted.SetBoldStatus(format.textNoteBoldStatus != FormatStatus.None);
            Debug("textNoteBoldStatus Paint " + format.textNoteBoldStatus.ToString());
            Debug("get textNoteBoldStatus Paint " + tFormatted.GetBoldStatus().ToString());

            tFormatted.SetItalicStatus(format.textNoteItalicsStatus != FormatStatus.None);
            Debug("textNoteItalicsStatus Paint " + format.textNoteItalicsStatus.ToString());
            Debug("get textNoteItalicsStatus Paint " + tFormatted.GetItalicStatus().ToString());

            tFormatted.SetUnderlineStatus(format.textNoteUnderlineStatus != FormatStatus.None);
            Debug("textNoteUnderlineStatus Paint " + format.textNoteUnderlineStatus.ToString());
            Debug("get textNoteUnderlineStatus Paint " + tFormatted.GetUnderlineStatus().ToString());

            txt.SetFormattedText(tFormatted);
        }
Beispiel #2
0
        public void SaveTextProperties(TextNote t)
        {
            FormattedText tFormatted = t.GetFormattedText();
            TextRange     tr         = new TextRange(0, 1);

            int textNoteTypeID = t.TextNoteType.Id.IntegerValue;

            string lowercaseAlph = "abcdefghijklmnopqrstuvwxyz";

            string plaintext = tFormatted.GetPlainText();
            bool   isUpper   = true;

            foreach (char c in plaintext)
            {
                if (lowercaseAlph.Contains(c))
                {
                    isUpper = false;
                    break;
                }
            }

            bool textNoteAllCapsStatus = isUpper;

            Debug("textNoteAllCapsStatus" + textNoteAllCapsStatus.ToString());

            FormatStatus textNoteBoldStatus = tFormatted.GetBoldStatus(tr);

            Debug("textNoteBoldStatuss" + textNoteBoldStatus.ToString());
            FormatStatus textNoteItalicsStatus = tFormatted.GetItalicStatus(tr);

            Debug("textNoteItalicsStatus" + textNoteItalicsStatus.ToString());
            FormatStatus textNoteUnderlineStatus = tFormatted.GetUnderlineStatus(tr);

            Debug("textNoteUnderlineStatus" + textNoteUnderlineStatus.ToString());

            TextFormattingContainer container = new TextFormattingContainer();

            container.textNoteAllCapsStatus   = textNoteAllCapsStatus;
            container.textNoteTypeID          = textNoteTypeID;
            container.textNoteBoldStatus      = textNoteBoldStatus;
            container.textNoteItalicsStatus   = textNoteItalicsStatus;
            container.textNoteUnderlineStatus = textNoteUnderlineStatus;

            byte[] containerBytes;

            BinaryFormatter bf = new BinaryFormatter();

            using (var ms = new MemoryStream())
            {
                bf.Serialize(ms, container);
                containerBytes = ms.ToArray();
            }
            var assembly    = Assembly.GetCallingAssembly();
            var assemblyDir = new FileInfo(assembly.Location).Directory.FullName;

            File.WriteAllBytes(assemblyDir + @"\LM2FormatSelectorSave.bin", containerBytes);
        }
Beispiel #3
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument UIdoc      = commandData.Application.ActiveUIDocument;
            Document   doc        = UIdoc.Document;
            string     pluginName = "TextFormatPainter";

            this.application = commandData.Application.Application;

            pluginConfig = Utility.ReadConfig();

            IList <TextNote> userSelectedTextNote = SelectText(UIdoc);

            if (userSelectedTextNote == null)
            {
                return(Result.Cancelled);
            }

            String slackMessage = ">Started";

            Utility.SendTelemetryData(doc, pluginConfig.telemetryURL, pluginName, slackMessage);

            int textboxes = userSelectedTextNote.Count;

            TextFormattingContainer format = GetTextProperties();

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Text Case Change");

                foreach (TextNote txt in userSelectedTextNote)
                {
                    SetTextProperties(doc, txt, format);
                }

                tx.Commit();
            }

            int    ROI = 2 * textboxes;
            string ROIString;

            ROIString = string.Format("{0:0.00} hours", ROI / 60f);


            String slackMessage2 = $">Completed\n>Number of TextNotes: {textboxes}\n>ROI for run: {ROI} minutes ({ROIString}) saved\nData\t{ROI}";

            Utility.SendTelemetryData(doc, pluginConfig.telemetryURL, pluginName, slackMessage2);


            return(Result.Succeeded);
        }
Beispiel #4
0
        public TextFormattingContainer GetTextProperties()
        {
            var assembly    = Assembly.GetCallingAssembly();
            var assemblyDir = new FileInfo(assembly.Location).Directory.FullName;

            byte[] containerBytes = File.ReadAllBytes(assemblyDir + @"\LM2FormatSelectorSave.bin");

            TextFormattingContainer container = null;

            using (var memStream = new MemoryStream())
            {
                var binForm = new BinaryFormatter();
                memStream.Write(containerBytes, 0, containerBytes.Length);
                memStream.Seek(0, SeekOrigin.Begin);
                container = binForm.Deserialize(memStream) as TextFormattingContainer;
            }

            return(container);
        }