<?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: Insert Block from external drawing to current drawing in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12724861#M4343</link>
    <description>&lt;P&gt;Have a look at&lt;A href="https://forums.autodesk.com/t5/forums/searchpage/tab/message?advanced=false&amp;amp;allow_punctuation=false&amp;amp;filter=location&amp;amp;location=forum-board%3A152&amp;amp;q=Wblockcloneobjects" target="_blank" rel="noopener"&gt; these posts&lt;/A&gt; for an example of how to copy box into another drawing&lt;/P&gt;</description>
    <pubDate>Mon, 22 Apr 2024 11:58:49 GMT</pubDate>
    <dc:creator>ActivistInvestor</dc:creator>
    <dc:date>2024-04-22T11:58:49Z</dc:date>
    <item>
      <title>Insert Block from external drawing to current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12724745#M4342</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I want to write a C# code&amp;nbsp;using&amp;nbsp;AutoCAD .NET API&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to copy blocks of external drawing into the current drawing but I am unable to find any API's for the same&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 10:59:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12724745#M4342</guid>
      <dc:creator>swapnil_lokam</dc:creator>
      <dc:date>2024-04-22T10:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Block from external drawing to current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12724861#M4343</link>
      <description>&lt;P&gt;Have a look at&lt;A href="https://forums.autodesk.com/t5/forums/searchpage/tab/message?advanced=false&amp;amp;allow_punctuation=false&amp;amp;filter=location&amp;amp;location=forum-board%3A152&amp;amp;q=Wblockcloneobjects" target="_blank" rel="noopener"&gt; these posts&lt;/A&gt; for an example of how to copy box into another drawing&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 11:58:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12724861#M4343</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-04-22T11:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Block from external drawing to current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12724931#M4344</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use or get inspiration from these extension methods.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;/// &amp;lt;summary&amp;gt;
/// Imports SymbolTableRecords whose names match the template supplied from the specified file.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;typeparam name="T"&amp;gt;Type of SymbolTable.&amp;lt;/typeparam&amp;gt;
/// &amp;lt;param name="targetDb"&amp;gt;Instance to which the method applies.&amp;lt;/param&amp;gt;
/// &amp;lt;param name="sourceFileName"&amp;gt;Complete path of the source file.&amp;lt;/param&amp;gt;
/// &amp;lt;param name="pattern"&amp;gt;WcMatch pattern.&amp;lt;/param&amp;gt;
/// &amp;lt;param name="cloning"&amp;gt;Input action for duplicate records.&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;A dictionary containing the names and ObjectIds of the imported records.&amp;lt;/returns&amp;gt;
/// &amp;lt;exception cref="ArgumentNullException"&amp;gt;&amp;lt;/exception&amp;gt;
public static Dictionary&amp;lt;string, ObjectId&amp;gt; ImportRecords&amp;lt;T&amp;gt;(
    this Database targetDb, string sourceFileName, string pattern, DuplicateRecordCloning cloning)
    where T : SymbolTable
{
    if (targetDb is null)
        throw new ArgumentNullException(nameof(targetDb));

    Dictionary&amp;lt;string, ObjectId&amp;gt; records;
    using (var sourceDb = new Database(false, true))
    {
        sourceDb.ReadDwgFile(sourceFileName, FileOpenMode.OpenForReadAndAllShare, false, null);
        using (Transaction tr = sourceDb.TransactionManager.StartOpenCloseTransaction())
        {
            var sourceTable = (T)tr.GetObject(sourceDb.GetTableId&amp;lt;T&amp;gt;(), OpenMode.ForRead);
            records = sourceTable
                .Cast&amp;lt;ObjectId&amp;gt;()
                .Select(id =&amp;gt; (SymbolTableRecord)tr.GetObject(id, OpenMode.ForRead))
                .Where(r =&amp;gt; Autodesk.AutoCAD.Internal.Utils.WcMatchEx(r.Name, pattern, true))
                .ToDictionary(r =&amp;gt; r.Name, r =&amp;gt; r.ObjectId);
            var ids = new ObjectIdCollection(records.Values.ToArray());
            var mapping = new IdMapping();
            sourceDb.WblockCloneObjects(ids, targetDb.GetTableId&amp;lt;T&amp;gt;(), mapping, cloning, false);
            tr.Commit();
        }
    }
    using (var tr = targetDb.TransactionManager.StartOpenCloseTransaction())
    {
        var table = (T)tr.GetObject(targetDb.GetTableId&amp;lt;T&amp;gt;(), OpenMode.ForRead);
        return records
            .Where(r =&amp;gt; table.Has(r.Key))
            .ToDictionary(r =&amp;gt; r.Key, r =&amp;gt; table[r.Key]);
    }
}

/// &amp;lt;summary&amp;gt;
/// Gets the ObjectId of the specified SymbolTable.
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;typeparam name="T"&amp;gt;Type of SymbolTable.&amp;lt;/typeparam&amp;gt;
/// &amp;lt;param name="db"&amp;gt;Instance to which the method applies.&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;The ObjectId of the specified SymbolTable.&amp;lt;/returns&amp;gt;
/// &amp;lt;exception cref="ArgumentNullException"&amp;gt;Thrown if &amp;lt;paramref name ="db"/&amp;gt; is null.&amp;lt;/exception&amp;gt;
/// &amp;lt;exception cref="NotImplementedException"&amp;gt;&amp;lt;/exception&amp;gt;
public static ObjectId GetTableId&amp;lt;T&amp;gt;(this Database db) where T : SymbolTable
{
    if (db is null) throw new ArgumentNullException(nameof(db));

    switch (typeof(T).Name)
    {
        case nameof(BlockTable): return db.BlockTableId;
        case nameof(DimStyleTable): return db.DimStyleTableId;
        case nameof(LayerTable): return db.LayerTableId;
        case nameof(LinetypeTable): return db.LinetypeTableId;
        case nameof(RegAppTable): return db.RegAppTableId;
        case nameof(TextStyleTable): return db.TextStyleTableId;
        case nameof(UcsTable): return db.UcsTableId;
        case nameof(ViewTable): return db.ViewTableId;
        case nameof(ViewportTable): return db.ViewportTableId;
        default:
            throw new NotImplementedException();
    }
}&lt;/LI-CODE&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, 23 Apr 2024 07:18:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12724931#M4344</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2024-04-23T07:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Block from external drawing to current drawing</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12731783#M4345</link>
      <description>&lt;P&gt;Thanks for you valuable time&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4476837"&gt;@ActivistInvestor&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;But seems like&amp;nbsp;&lt;BR /&gt;Here it is copy pasting the objects from external drawing to the current drawing. Hence the objects that are pasted to the current drawing are not adjusting the scale by itself.&amp;nbsp;&lt;BR /&gt;When I am manually trying to import these blocks from "Design Centre" in the "View" tab of the ribbon then they are properly getting scaled&amp;nbsp;&lt;BR /&gt;So I am struggling to write the code for the above requirement&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 21:27:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-block-from-external-drawing-to-current-drawing/m-p/12731783#M4345</guid>
      <dc:creator>swapnil_lokam</dc:creator>
      <dc:date>2024-04-24T21:27:17Z</dc:date>
    </item>
  </channel>
</rss>

