<?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: How to include extension dictionary in block inserted using ReadDwgFile in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4898686#M44949</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Thank you for the sample. WblockCloneObjects is new to me and I have learnt something useful.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Only one issue I have now is if the source database is created using the default constructor I get eBrokenHandle error from &lt;SPAN&gt;WblockCloneObjects.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;If I use the alternative constructor, new Database(false, true) ,&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;when I add a block reference using the new block it is drawn 25.4 times greater in size. I've checked the units in both the block's drawing and the target drawing; both set to millimeters. If I change both to unitless and set insertion default unit to millimeters I get the same result. When manually using INSERT, scale is left at 1,1,1, it is drawn at the correct size.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried setting source database Insunits to 0 but that made no difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There may be more thatn a single issue here.&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>Thu, 20 Mar 2014 15:33:56 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-03-20T15:33:56Z</dc:date>
    <item>
      <title>How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4895790#M44942</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm inserting a block using ReadDwgFile(). The block has an extension dictionary which I want to preserve in the inserted block.&lt;/P&gt;&lt;P&gt;If I do it manually , for example, by dragging it from Design Center into Model Space, when I look at the block definition in the block table (using MgdDbg) the extension dictionary is there, which is what I want. When I try it in code the extension dictionary is not included.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code I am using.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using (Database sideDb = new Database(false, true))
{
   sideDb.ReadDwgFile(blkFile,FileOpenMode.OpenForReadAndReadShare, true, "");
   newObjectId = targetDb.Insert(Path.GetFileNameWithoutExtension(blkFile), sideDb, false);
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What can I do to improve it to get the desired result?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Craig&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>Wed, 19 Mar 2014 14:29:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4895790#M44942</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-19T14:29:33Z</dc:date>
    </item>
    <item>
      <title>Re : How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896024#M44943</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when you say:&lt;/P&gt;
&lt;P&gt;"I'm inserting a block using ReadDwgFile(). The block has an extension dictionary which I want to preserve in the inserted block."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean the Dwg file model space has an extension dictionary or the Dwg file contains a block definition which has an extension dictionary ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Database.Insert() method copies all the Model Space entities in the source database to a new BlockTableRecord in the target database BlockTable.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2014 15:18:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896024#M44943</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-03-19T15:18:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896030#M44944</link>
      <description>Your not telling the code to return the full path....&lt;BR /&gt;&lt;BR /&gt;maybe something like: IO.Path.GetFullPath(bla bla bla) would work</description>
      <pubDate>Wed, 19 Mar 2014 15:19:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896030#M44944</guid>
      <dc:creator>Mikko</dc:creator>
      <dc:date>2014-03-19T15:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896408#M44945</link>
      <description>&lt;P&gt;The file name was different to the block name so on insert I got two block table entries. One for &lt;EM&gt;filename&lt;/EM&gt; and one for &lt;EM&gt;blockname&lt;/EM&gt;. The entry for &lt;EM&gt;blockname&lt;/EM&gt; had the extension dictionary, the entry for &lt;EM&gt;filename&lt;/EM&gt; did not. The block reference in model space referred to the &lt;EM&gt;filename&lt;/EM&gt; entry so no extension dictionary. (I'm listening for ObjectAppended and copy the extension dictionary from the block table entry to the block reference but the name was not expected so it did not get copied).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To overcome this manually using INSERT, I'd select my file, change the block name to &lt;EM&gt;blockname&lt;/EM&gt; and opt to explode then I get a single block table&amp;nbsp;entry, the block reference refers to &lt;EM&gt;blockname&lt;/EM&gt;&amp;nbsp;and my ObjectAppended handler copies the extension dictionary successfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So how to I replicate that in code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed the insert&amp;nbsp;line to use&amp;nbsp;blockname instead of the filename but I get a self-reference error (which also occurs manually if you don't explode).&lt;/P&gt;&lt;PRE&gt;newObjectId = targetDb.Insert("blockname", sideDb, false);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess I need to tell it to explode it before calling insert somehow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2014 17:04:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896408#M44945</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-19T17:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896502#M44946</link>
      <description>just a thought that if you have a drawing with a block in it you could do something like this which would insert the block from an external drawing into your current drawing.&lt;BR /&gt;&lt;BR /&gt;Public Sub BlockGrabber(ByVal whatDwg As String, ByVal whichBlock As String)&lt;BR /&gt;Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;Dim db As Database = New Database()&lt;BR /&gt;db.ReadDwgFile(whatDwg, System.IO.FileShare.ReadWrite, True, "")&lt;BR /&gt;Dim ids As ObjectIdCollection = New ObjectIdCollection()&lt;BR /&gt;Using tr As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;Dim bt As BlockTable&lt;BR /&gt;bt = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)&lt;BR /&gt;Try&lt;BR /&gt;ids.Add(bt(whichBlock))&lt;BR /&gt;Catch&lt;BR /&gt;tr.Commit()&lt;BR /&gt;Return&lt;BR /&gt;End Try&lt;BR /&gt;Dim destdb As Database = ed.Document.Database&lt;BR /&gt;Dim iMap As IdMapping = New IdMapping()&lt;BR /&gt;db.WblockCloneObjects(ids, destdb.BlockTableId, iMap, DuplicateRecordCloning.Ignore, False)&lt;BR /&gt;tr.Commit()&lt;BR /&gt;End Using&lt;BR /&gt;End Sub</description>
      <pubDate>Wed, 19 Mar 2014 17:32:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896502#M44946</guid>
      <dc:creator>Mikko</dc:creator>
      <dc:date>2014-03-19T17:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896514#M44947</link>
      <description>&lt;P&gt;If I don't misundertand you try to import a block which exists in another file.&lt;/P&gt;
&lt;P&gt;if so, I do not think Databse.Insert() is the good route. as I said Databse.Insert() creates a new BlockTableRecord in the Database BlockTable which contains all the entites in the model space of the source file, so you block in the source file is a block reference nested in the newly created BlockTablerecord.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to import only the block from the external file, you may use WblockCloneObjects().&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2014 17:36:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4896514#M44947</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-03-19T17:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4897542#M44948</link>
      <description>&lt;P&gt;Here's a little sample:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;        private ObjectId ImportBlock(string fileName, string blockName)
        {
            if (!File.Exists(fileName))
                throw new FileNotFoundException("File not found", fileName);

            Database targetDb = HostApplicationServices.WorkingDatabase;
            ObjectId owner = targetDb.BlockTableId;

            using (Database sourceDb = new Database())
            {
                sourceDb.ReadDwgFile(fileName, System.IO.FileShare.Read, false, "");
                using (Transaction tr = sourceDb.TransactionManager.StartOpenCloseTransaction())
                {
                    BlockTable bt = (BlockTable)tr.GetObject(sourceDb.BlockTableId, OpenMode.ForRead);
                    if (!bt.Has(blockName))
                        return ObjectId.Null;

                    ObjectId id = bt[blockName];
                    ObjectIdCollection ids = new ObjectIdCollection();
                    ids.Add(id);
                    IdMapping idMap = new IdMapping();
                    sourceDb.WblockCloneObjects(ids, owner, idMap, DuplicateRecordCloning.Replace, false);
                    return idMap[id].IsCloned ? idMap[id].Value : ObjectId.Null;
                }
            }
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2014 07:31:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4897542#M44948</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-03-20T07:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4898686#M44949</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thank you for the sample. WblockCloneObjects is new to me and I have learnt something useful.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Only one issue I have now is if the source database is created using the default constructor I get eBrokenHandle error from &lt;SPAN&gt;WblockCloneObjects.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;If I use the alternative constructor, new Database(false, true) ,&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;when I add a block reference using the new block it is drawn 25.4 times greater in size. I've checked the units in both the block's drawing and the target drawing; both set to millimeters. If I change both to unitless and set insertion default unit to millimeters I get the same result. When manually using INSERT, scale is left at 1,1,1, it is drawn at the correct size.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried setting source database Insunits to 0 but that made no difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There may be more thatn a single issue here.&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>Thu, 20 Mar 2014 15:33:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4898686#M44949</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-20T15:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4898842#M44950</link>
      <description>&lt;P&gt;You say you checked the drawings units, but did you checked the block definition units ?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2014 16:08:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4898842#M44950</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-03-20T16:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4898972#M44951</link>
      <description>&lt;P&gt;I have now. It is Milimeters.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2014 16:48:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4898972#M44951</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-20T16:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899094#M44952</link>
      <description>&lt;P&gt;Could you post a drawing sample ?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2014 17:28:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899094#M44952</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-03-20T17:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899132#M44953</link>
      <description>&lt;P&gt;Yes. Block drawing attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2014 17:34:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899132#M44953</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-20T17:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899162#M44954</link>
      <description>&lt;P&gt;Nothing wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the drawing you posted the block reference is scaled to 0.03937 which is equal to 1 / 25.4 (1" = 25.4 mm).&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2014 17:45:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899162#M44954</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2014-03-20T17:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899224#M44955</link>
      <description>&lt;P&gt;Yes, indeed, on the block reference. I did make the link between 1 inch = 25.4 mm.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It must be me expecting it to be smaller when imported but the scale factor is not applied and is drawn correctly at 1:1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll look into how to get the scaling back to 1 in the block drawing and see if that cures it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2014 18:10:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899224#M44955</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-20T18:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to include extension dictionary in block inserted using ReadDwgFile</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899294#M44956</link>
      <description>&lt;P&gt;Gilles and Mikko&lt;/P&gt;&lt;P&gt;Thank you both for making me aware of WblockCloneObjects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll mark Gilles post as the answer for the follow through.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The scale issue was something else besides.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Craig&lt;/P&gt;</description>
      <pubDate>Thu, 20 Mar 2014 18:22:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-include-extension-dictionary-in-block-inserted-using/m-p/4899294#M44956</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-03-20T18:22:49Z</dc:date>
    </item>
  </channel>
</rss>

