<?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: Inserting an object into BlockTableRecord.Paperspace in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/inserting-an-object-into-blocktablerecord-paperspace/m-p/12516056#M5823</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A quick test would have shown you that, when called from a layout tab, PaperSpace refers to the active layout; when called from the model space, PaperSpace refers to the last closed layout, or the first layout tab if none has yet been opened.&lt;/P&gt;
&lt;P&gt;In my opinion, unless the active space is a known layout, this property isn't very reliable, in which case I prefer CurrentSpaceId.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jan 2024 18:39:11 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2024-01-23T18:39:11Z</dc:date>
    <item>
      <title>Inserting an object into BlockTableRecord.Paperspace</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserting-an-object-into-blocktablerecord-paperspace/m-p/12516026#M5822</link>
      <description>&lt;P&gt;I have this piece of legacy code I'm trying to understand. When I want to insert something into a paperspace &lt;STRONG&gt;Layout&lt;/STRONG&gt; I usually use &lt;STRONG&gt;Database.CurrentSpaceId&lt;/STRONG&gt; or some other means of finding the &lt;STRONG&gt;Layout&lt;/STRONG&gt; object. Then I open the &lt;STRONG&gt;Layout.BlockTableRecord&lt;/STRONG&gt; and append the &lt;STRONG&gt;Entity&lt;/STRONG&gt;.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;But this code is using &lt;STRONG&gt;BlockTableRecord.Paperspace&lt;/STRONG&gt;. I'm familiar with &lt;STRONG&gt;BlockTableRecord.Model&lt;/STRONG&gt;, but how does the former work if there are multiple paperspace &lt;STRONG&gt;Layouts&lt;/STRONG&gt;?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;

using (Transaction transaction = db.TransactionManager.StartOpenCloseTransaction())
using(BlockTable bt = transaction.GetObject(db.BlockTableId, OpenMode.ForRead, false, true) as BlockTable)
{
    try
    {
        if (!(db.CurrentSpaceId == bt[BlockTableRecord.PaperSpace]))
        {
            doc.Editor.WriteMessage("\n You must be in paperspace to insert the Loop Schedule.");
            transaction.Abort();
            return;
        }

        Point3d insertPoint = GetInsertPoint();

        Table tb = MakeTableObj(insertPoint);

        using (BlockTableRecord btr =
               transaction.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite, false, true) as
                   BlockTableRecord)
        {
            btr.AppendEntity(tb);
            transaction.AddNewlyCreatedDBObject(tb, true);
        }

        transaction.Commit();
    }
    catch (Exception ex)
    {
        transaction.Abort();
        doc.Editor.WriteMessage($"Error in {nameof(MethodName)}: {ex.Message}");
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 17:17:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserting-an-object-into-blocktablerecord-paperspace/m-p/12516026#M5822</guid>
      <dc:creator>nshupeFMPE3</dc:creator>
      <dc:date>2024-01-23T17:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting an object into BlockTableRecord.Paperspace</title>
      <link>https://forums.autodesk.com/t5/net-forum/inserting-an-object-into-blocktablerecord-paperspace/m-p/12516056#M5823</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A quick test would have shown you that, when called from a layout tab, PaperSpace refers to the active layout; when called from the model space, PaperSpace refers to the last closed layout, or the first layout tab if none has yet been opened.&lt;/P&gt;
&lt;P&gt;In my opinion, unless the active space is a known layout, this property isn't very reliable, in which case I prefer CurrentSpaceId.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 18:39:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/inserting-an-object-into-blocktablerecord-paperspace/m-p/12516056#M5823</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-01-23T18:39:11Z</dc:date>
    </item>
  </channel>
</rss>

