<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: creating text using .net in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/creating-text-using-net/m-p/7830514#M27021</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use Editor.GetString() to prompt the user for a text style but you'll also have to check if this text style already exists in the drawing text style table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("Test")]
        public void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // prompt for insertion point
            var ptResult = ed.GetPoint("\nInsertion point: ");
            if (ptResult.Status != PromptStatus.OK)
                return;
            var point = ptResult.Value;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var styles = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);

                // prompt for text style
                var strOptions = new PromptStringOptions("\nEnter the text style name: ");
                PromptResult strResult;
                while (true)
                {
                    strResult = ed.GetString(strOptions);
                    if (strResult.Status != PromptStatus.OK)
                        return;
                    if (styles.Has(strResult.StringResult))
                        break;
                    ed.WriteMessage("\nText style not found: {0}", strResult.StringResult);
                }
                var styleId = styles[strResult.StringResult];

                // prompt for text contents
                strOptions.Message = "\nEnter the text: ";
                strOptions.AllowSpaces = true;
                strResult = ed.GetString(strOptions);
                if (strResult.Status != PromptStatus.OK)
                    return;
                var textString = strResult.StringResult;

                // add the text to the current space
                var text = new DBText();
                text.Position = point;
                text.TextStyleId = styleId;
                text.TextString = textString;
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                curSpace.AppendEntity(text);
                tr.AddNewlyCreatedDBObject(text, true);

                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Mar 2018 10:16:17 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2018-03-06T10:16:17Z</dc:date>
    <item>
      <title>creating text using .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-text-using-net/m-p/7830401#M27020</link>
      <description>&lt;P&gt;there are a lot of examples how to create text in autocad but this text already in code. question is how to INPUT text and it's properties such as point where text should be and style(for example "times new roman, size 12"). should i use PromptStringResult for transfering it to my string variable?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 09:40:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-text-using-net/m-p/7830401#M27020</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-06T09:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: creating text using .net</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-text-using-net/m-p/7830514#M27021</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use Editor.GetString() to prompt the user for a text style but you'll also have to check if this text style already exists in the drawing text style table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("Test")]
        public void Test()
        {
            var doc = AcAp.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;

            // prompt for insertion point
            var ptResult = ed.GetPoint("\nInsertion point: ");
            if (ptResult.Status != PromptStatus.OK)
                return;
            var point = ptResult.Value;

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var styles = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);

                // prompt for text style
                var strOptions = new PromptStringOptions("\nEnter the text style name: ");
                PromptResult strResult;
                while (true)
                {
                    strResult = ed.GetString(strOptions);
                    if (strResult.Status != PromptStatus.OK)
                        return;
                    if (styles.Has(strResult.StringResult))
                        break;
                    ed.WriteMessage("\nText style not found: {0}", strResult.StringResult);
                }
                var styleId = styles[strResult.StringResult];

                // prompt for text contents
                strOptions.Message = "\nEnter the text: ";
                strOptions.AllowSpaces = true;
                strResult = ed.GetString(strOptions);
                if (strResult.Status != PromptStatus.OK)
                    return;
                var textString = strResult.StringResult;

                // add the text to the current space
                var text = new DBText();
                text.Position = point;
                text.TextStyleId = styleId;
                text.TextString = textString;
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                curSpace.AppendEntity(text);
                tr.AddNewlyCreatedDBObject(text, true);

                tr.Commit();
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 10:16:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-text-using-net/m-p/7830514#M27021</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-03-06T10:16:17Z</dc:date>
    </item>
  </channel>
</rss>

