<?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: Embed Data Linked Table in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8605774#M23476</link>
    <description>&lt;P&gt;It seems to me that you might not fully understand that every entity (Table included) is owned by a BlockTableRecord (either ModelSpace block, or one of the PaperSpace blocks, corresponding to each layout).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Firstly, there is nothing wrong by using Editor.SelectAll([filter]) to select ALL Table entities in a drawing: unless the filter has LayoutName filter in it, all tables in all layouts (including ModelSpace) should be selected for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can write code to loop through drawing database. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. go through each BlockTableRecord in BlockTable, and find blocktablerecord that is Layout block (IsLayout property)&lt;/P&gt;
&lt;P&gt;2. With each Layout blocktablerecord (including ModelSpace block, of course), loop through the ObjectIds in it to identify each Table.&lt;/P&gt;
&lt;P&gt;3. For each table entity, do whatever you wantto do (if the table has embedded link is not an issue here, right?).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The advantage of looping through drawing database over Editor.SelectAll() is that if the target drawing is not currently opened in AutoCAD, you can open the drawing as side database and run your code against it. This will save AutoCAD from opening the drawing visibly. If the drawing is already opened in AutoCAD and is currently active, there is nothing wrong with using Editor.SelectAll() with filter for Table entity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, your code problem is for each selected table in the selectionset, you need to identify which Layout it belongs to. and then you only APPEND the entities generated by Explode() method to that layout block, rather than CurrentSpace (this is why unexpected entities in current space: you explode tables in different layouts, then added the new entities to current space, which is likely modelspace,&amp;nbsp;thus different scale of that layout related tocurrent space).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is, after using SelectAll() to get all tables, for each table, you need to identify which layout it belong to (you can simply use property OwnerId to get its layout block without the need to actually knowing what the layout is). Then make sure you only append the exploded entities to this owner BlockTableRecord.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you may want to actually delete the original table after calling Explode() method and adding all resulting entities into its owner blocktablerecord.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, I'd not go the route as the other reply suggested: this would make a fairly simple issue rather complicated and hard to understand/follow.&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;</description>
    <pubDate>Tue, 19 Feb 2019 15:24:42 GMT</pubDate>
    <dc:creator>norman.yuan</dc:creator>
    <dc:date>2019-02-19T15:24:42Z</dc:date>
    <item>
      <title>Embed Data Linked Table</title>
      <link>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8599612#M23474</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As part of a drawing clean up routine I need to remove any data linked table references but maintain the information and table in the drawing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Knowing that you can explode a table and then be able to delete that data link; my idea was to select all acad_tables, explode them, and then figure out how to remove the data link. I am finding it hard to select all tables in every layout tab and explode them without really weird things happening like the table tripling in size. I have tried accessing the tables via the current database but I can not seem to get that either.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would prefer not do a selection set and would like to access them via the current database directly if that is possible. I believe this will solve my issue of the selection set not selected from all layout tabs. (My attempt below does use a selection set, but only because I could not figure another way to do it.) And if a selection set is the only way I am OK with that, just need to know how to select them on every layout.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question is this: What is the best way to do this? I want to select all autocad tables, explode them while maintaining information, size, and style, and then remove the datalink from the drawing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you all in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    &amp;lt;CommandMethod("test1")&amp;gt;
    Public Sub ExplodeTables()

        Dim acCurDoc As Document = Active.Document
        Dim acCurEd As Editor = Active.Editor
        Dim acCurDb As Database = Active.Database

        Try

            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                Dim acPmtSelRes As PromptSelectionResult
                ''Dim acSelSet As SelectionSet

                Dim tableFilter(0) As TypedValue
                tableFilter(0) = New TypedValue(DxfCode.Start, "ACAD_TABLE")

                Dim selectionFilter As New SelectionFilter(tableFilter)

                acPmtSelRes = acCurEd.SelectAll(selectionFilter)

                ''acSelSet = acPmtSelRes.Value

                Dim tableCollection As DBObjectCollection = New DBObjectCollection()

                For Each selectedTable As SelectedObject In acPmtSelRes.Value

                    Dim tableEntity As Entity = CType(acTrans.GetObject(selectedTable.ObjectId, OpenMode.ForRead), Entity)

                    tableEntity.Explode(tableCollection)

                Next

                Dim acBlkTblRec As BlockTableRecord = CType(acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

                For Each explodedTable As DBObject In tableCollection

                    Dim explodedTableEntity As Entity = CType(explodedTable, Entity)

                    acBlkTblRec.AppendEntity(explodedTableEntity)
                    acTrans.AddNewlyCreatedDBObject(explodedTableEntity, True)

                Next

                acTrans.Commit()

            End Using

        Catch ex As Exception

            Application.ShowAlertDialog("Error Exploding Tables:" &amp;amp; vbLf &amp;amp; ex.Message)

        End Try

    End Sub&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Feb 2019 21:57:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8599612#M23474</guid>
      <dc:creator>David_Prontnicki</dc:creator>
      <dc:date>2019-02-15T21:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Data Linked Table</title>
      <link>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8604573#M23475</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if going through the table style helps. Like, go through table styles in named object dictionary (&lt;A href="https://adndevblog.typepad.com/autocad/2012/06/listing-all-the-table-styles-in-a-drawing.html" target="_blank"&gt;https://adndevblog.typepad.com/autocad/2012/06/listing-all-the-table-styles-in-a-drawing.html&lt;/A&gt; - to get through all table styles).&lt;/P&gt;
&lt;P&gt;For each table style try to get the persistent reactors. Using API DbObject::GetPersistentReactorIds(). This is because, each table will be stored as persistent reactor in the table style it uses. By this way you can get all tables in the DWG.&lt;/P&gt;
&lt;P&gt;Note, GetPersistentReactorIds will return different type of persistent reactors. So, you need to filter and access only the table entity.&lt;/P&gt;
&lt;P&gt;Refer blog &lt;A href="https://adndevblog.typepad.com/autocad/2012/04/how-to-detect-whether-entity-is-belong-to-any-group-or-not.html" target="_blank"&gt;https://adndevblog.typepad.com/autocad/2012/04/how-to-detect-whether-entity-is-belong-to-any-group-or-not.html&lt;/A&gt; which uses similar technique .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 06:43:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8604573#M23475</guid>
      <dc:creator>Virupaksha_aithal</dc:creator>
      <dc:date>2019-02-19T06:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Data Linked Table</title>
      <link>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8605774#M23476</link>
      <description>&lt;P&gt;It seems to me that you might not fully understand that every entity (Table included) is owned by a BlockTableRecord (either ModelSpace block, or one of the PaperSpace blocks, corresponding to each layout).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Firstly, there is nothing wrong by using Editor.SelectAll([filter]) to select ALL Table entities in a drawing: unless the filter has LayoutName filter in it, all tables in all layouts (including ModelSpace) should be selected for you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can write code to loop through drawing database. Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. go through each BlockTableRecord in BlockTable, and find blocktablerecord that is Layout block (IsLayout property)&lt;/P&gt;
&lt;P&gt;2. With each Layout blocktablerecord (including ModelSpace block, of course), loop through the ObjectIds in it to identify each Table.&lt;/P&gt;
&lt;P&gt;3. For each table entity, do whatever you wantto do (if the table has embedded link is not an issue here, right?).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The advantage of looping through drawing database over Editor.SelectAll() is that if the target drawing is not currently opened in AutoCAD, you can open the drawing as side database and run your code against it. This will save AutoCAD from opening the drawing visibly. If the drawing is already opened in AutoCAD and is currently active, there is nothing wrong with using Editor.SelectAll() with filter for Table entity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, your code problem is for each selected table in the selectionset, you need to identify which Layout it belongs to. and then you only APPEND the entities generated by Explode() method to that layout block, rather than CurrentSpace (this is why unexpected entities in current space: you explode tables in different layouts, then added the new entities to current space, which is likely modelspace,&amp;nbsp;thus different scale of that layout related tocurrent space).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is, after using SelectAll() to get all tables, for each table, you need to identify which layout it belong to (you can simply use property OwnerId to get its layout block without the need to actually knowing what the layout is). Then make sure you only append the exploded entities to this owner BlockTableRecord.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you may want to actually delete the original table after calling Explode() method and adding all resulting entities into its owner blocktablerecord.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, I'd not go the route as the other reply suggested: this would make a fairly simple issue rather complicated and hard to understand/follow.&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;</description>
      <pubDate>Tue, 19 Feb 2019 15:24:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8605774#M23476</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2019-02-19T15:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Embed Data Linked Table</title>
      <link>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8609554#M23477</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@norman.yuan&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much. I will try this soon and let you know how it goes. (I am working on another aspect right now, and will get back to that sub in a bit.) I appreciate the reply.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 20:15:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/embed-data-linked-table/m-p/8609554#M23477</guid>
      <dc:creator>David_Prontnicki</dc:creator>
      <dc:date>2019-02-20T20:15:47Z</dc:date>
    </item>
  </channel>
</rss>

