<?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: MText Unable to update in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742355#M27620</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;Note: Please advice me there is any way to debug command code .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should display the Exception.StackTrace to have more details on the exception&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; try
{
    // ...
}
catch (System.Exception e)
{
    ed.WriteMessage("\nError: {0}\n{1}", e.Message, e.StackTrace);
}&lt;/PRE&gt;
&lt;P&gt;You can also &lt;A href="https://docs.microsoft.com/en-us/visualstudio/debugger/using-breakpoints" target="_blank"&gt;use break points&lt;/A&gt; in you code, and run it step by step in debug mode.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 09:56:01 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2018-02-01T09:56:01Z</dc:date>
    <item>
      <title>MText Unable to update</title>
      <link>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742194#M27618</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unable to update Mtext please find below code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: Please advice me there is any way to debug command code .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;	[CommandMethod("MyTestCommands", "test", CommandFlags.Modal)]
        public void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;
            var res1 = ed.GetFileNameForOpen("Specify parameter file");
            if (res1.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
                return;

            var res2 = ed.GetString("Specify output sub-folder name");
            if (res2.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
                return;
            try
            {
                var db = doc.Database;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                    foreach (ObjectId id in btr)
                    {
                        Entity currentEntity = tr.GetObject(id, OpenMode.ForWrite, false) as Entity;
                        if (currentEntity == null)
                        {
                            continue;
                        }
                        if (currentEntity.GetType() == typeof(MText))
                        {
                            ((MText)currentEntity).Contents = "BlahBlah";
                        }
                        else
                        {
                            ((DBText)currentEntity).TextString = "BlahBlah";
                        }
                    }
                    tr.Commit();
                }

            }
            catch (System.Exception e)
            {
                using (var writer = File.CreateText(Path.Combine(res2.StringResult, "error.txt")))
                {
                    writer.WriteLine(e.ToString());
                }
                ed.WriteMessage("Error: {0}", e.ToString());
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 08:44:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742194#M27618</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-01T08:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: MText Unable to update</title>
      <link>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742282#M27619</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There're some mistakes in your code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.BlockTableId, OpenMode.ForRead);&lt;/PRE&gt;
&lt;P&gt;db.BlockTableId is the ID of the database block table which type is BlockTable, not a BlockTableRecord&lt;/P&gt;
&lt;P&gt;Assuming you want to get the model space block table record, you can do it this way:&lt;/P&gt;
&lt;PRE&gt;var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
var btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);&lt;/PRE&gt;
&lt;P&gt;or, using SymbolUtilityServices as in the above code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While iterating the model space entities you cast all entities which are not MText into DBText, this will throw an error with any entity which does not derive from DBText.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a little example on how to achieve what you're trying to do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        [CommandMethod("MyTestCommands", "test", CommandFlags.Modal)]
        public void Test()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed = doc.Editor;
            var res1 = ed.GetFileNameForOpen("Specify parameter file");
            if (res1.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
                return;

            var res2 = ed.GetString("Specify output sub-folder name");
            if (res2.Status != Autodesk.AutoCAD.EditorInput.PromptStatus.OK)
                return;
            try
            {
                var db = doc.Database;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    // open the model space block table record for read
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(
                        SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);

                    var textClass = RXObject.GetClass(typeof(DBText));
                    var mtextClass = RXObject.GetClass(typeof(MText));
                    foreach (ObjectId id in btr)
                    {
                        // if this is the ID of a DBText
                        if (id.ObjectClass.IsDerivedFrom(textClass))
                        {
                            var text = (DBText)tr.GetObject(id, OpenMode.ForWrite);
                            text.TextString = "BlahBlah";
                        }
                        // if this is the ID of a MText
                        else if (id.ObjectClass.IsDerivedFrom(mtextClass))
                        {
                            var mtext = (MText)tr.GetObject(id, OpenMode.ForWrite);
                            mtext.Contents = "BlahBlah";
                        }
                    }
                    tr.Commit();
                }

            }
            catch (System.Exception e)
            {
                using (var writer = File.CreateText(Path.Combine(res2.StringResult, "error.txt")))
                {
                    writer.WriteLine(e.ToString());
                }
                ed.WriteMessage("Error: {0}", e.ToString());
            }
        }&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Feb 2018 09:24:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742282#M27619</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-01T09:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: MText Unable to update</title>
      <link>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742355#M27620</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;Note: Please advice me there is any way to debug command code .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should display the Exception.StackTrace to have more details on the exception&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; try
{
    // ...
}
catch (System.Exception e)
{
    ed.WriteMessage("\nError: {0}\n{1}", e.Message, e.StackTrace);
}&lt;/PRE&gt;
&lt;P&gt;You can also &lt;A href="https://docs.microsoft.com/en-us/visualstudio/debugger/using-breakpoints" target="_blank"&gt;use break points&lt;/A&gt; in you code, and run it step by step in debug mode.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 09:56:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742355#M27620</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2018-02-01T09:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: MText Unable to update</title>
      <link>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742542#M27621</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;STRONG&gt;Gilles Chanteau,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Thank you for your replay. My source file text not changing.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;am doing below process.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Create command&amp;nbsp;dll as zip&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. upload zip and create new package in autodesk design automation API.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3.and creating Activity in&amp;nbsp;design automation API.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;4. submitting work item.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5. download the source&amp;nbsp;file from autodesk cloud&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;as given solution changes&amp;nbsp; not affecting the source file.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Regards,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Ragunath.s&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 11:09:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/mtext-unable-to-update/m-p/7742542#M27621</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-01T11:09:51Z</dc:date>
    </item>
  </channel>
</rss>

