<?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 Create block frm external dwg file using .Net API freeze(hangs) the AutoCAD 2016 in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6566609#M34559</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created function which creates block using external drawing file, I have used following code. &lt;STRONG&gt;It creates the block properly but after creating block in the current active document auto cad hangs. &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Public Sub InsertDrawingAsBlock(doc As Document, path As String, blockname As String, ipt As Point3d, ByVal scalefator As Scale3d, ByVal rotation As Double, ByVal xmlAttribList As XmlNodeList)

        'current drawing database
        Dim currentdb As Database = doc.Database

        'current drawing's editor
        Dim editor As Editor = doc.Editor
        Dim lock As DocumentLock = doc.LockDocument()

        Dim strAttribTag As String
        Dim strAttribValue As String


        Using lock

            Dim blockid As ObjectId = ObjectId.Null

            ' create database to read dwg file
            Dim sourcedb As New Database(False, True)

            Using sourcedb

                sourcedb.ReadDwgFile(path, System.IO.FileShare.Read, True, "")

                blockid = currentdb.Insert(path, sourcedb, True)

                Using tr As Transaction = doc.TransactionManager.StartTransaction()
                    Dim bt As BlockTable = DirectCast(tr.GetObject(currentdb.BlockTableId, OpenMode.ForRead), BlockTable)


                    If bt.Has(blockname) Then
                        ' MessageBox.Show(string.Format("Block {0} does already exist\nTry another block or Exit", blockname));
                        Return
                    End If

                    bt.UpgradeOpen()

                    Dim btrec As BlockTableRecord = DirectCast(blockid.GetObject(OpenMode.ForRead), BlockTableRecord)
                    btrec.UpgradeOpen()

                    btrec.Name = blockname

                    btrec.DowngradeOpen()

                    '---&amp;gt; debug only
                    ' this code block is written in the good programming manner (remember that)
                    'For Each index As ObjectId In btrec
                    '    Dim en As Entity = DirectCast(index.GetObject(OpenMode.ForRead), Entity)

                    '    Dim adef As AttributeDefinition = TryCast(en, AttributeDefinition)

                    '    If adef IsNot Nothing Then
                    '        editor.WriteMessage(vbLf + adef.Tag)
                    '    End If
                    'Next
                    '&amp;lt;--- debug only

                    Dim btr As BlockTableRecord = DirectCast(currentdb.CurrentSpaceId.GetObject(OpenMode.ForWrite), BlockTableRecord)

                    Using btr
                        Using bref As New BlockReference(ipt, blockid)
                            Dim mat As Matrix3d = Matrix3d.Identity

                            bref.TransformBy(mat)

                            bref.ScaleFactors = scalefator
                            bref.Rotation = rotation
                            btr.AppendEntity(bref)

                            tr.AddNewlyCreatedDBObject(bref, True)

                            Using btAttRec As BlockTableRecord = DirectCast(bref.BlockTableRecord.GetObject(OpenMode.ForRead), BlockTableRecord)
                                Dim atcoll As Autodesk.AutoCAD.DatabaseServices.AttributeCollection = bref.AttributeCollection

                                For Each subid As ObjectId In btAttRec
                                    Dim ent As Entity = DirectCast(subid.GetObject(OpenMode.ForRead), Entity)
                                    Dim attDef As AttributeDefinition = TryCast(ent, AttributeDefinition)

                                    If attDef IsNot Nothing Then
                                        ' ed.WriteMessage("\nValue: " + attDef.TextString);
                                        Dim attRef As New AttributeReference()

                                        attRef.SetPropertiesFrom(attDef)

                                        attRef.Visible = attDef.Visible

                                        attRef.SetAttributeFromBlock(attDef, bref.BlockTransform)
                                        attRef.HorizontalMode = attDef.HorizontalMode

                                        attRef.VerticalMode = attDef.VerticalMode

                                        attRef.Rotation = attDef.Rotation

                                        attRef.TextStyleId = attDef.TextStyleId

                                        attRef.Position = attDef.Position + ipt.GetAsVector()
                                        attRef.Tag = attDef.Tag

                                        attRef.FieldLength = attDef.FieldLength


                                        If xmlAttribList IsNot Nothing Then
                                            For Each xmlAttrib In xmlAttribList
                                                strAttribTag = GetXMLAttribute(xmlAttrib, "tag")
                                                strAttribValue = GetXMLAttribute(xmlAttrib, "value")
                                                If attDef.Tag = strAttribTag Then
                                                    ' set the attribute text to to the correct string
                                                    attRef.TextString = strAttribValue

                                                End If
                                            Next xmlAttrib
                                        End If


                                        atcoll.AppendAttribute(attRef)

                                        tr.AddNewlyCreatedDBObject(attRef, True)

                                    End If

                                Next
                            End Using

                            bref.DowngradeOpen()
                        End Using
                    End Using

                    btrec.DowngradeOpen()

                    bt.DowngradeOpen()

                    'editor.Regen()
                    tr.TransactionManager.QueueForGraphicsFlush()
                    doc.TransactionManager.FlushGraphics()
                    tr.Commit()
                End Using
            End Using
        End Using
    End Sub&lt;/PRE&gt;&lt;P&gt;I have also executed the profiler and found that acad.exe takes more time. (Please find attached screenshot of the profiler) As per the profiler some "Malloc" funciton from ACGE20.dll (auto cad file) takes more CPU time for execution. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Profiler output" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/273556i41360B7D28DC472D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Profiler.PNG" alt="Profiler.PNG" /&gt;&lt;/span&gt;﻿&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2016 12:55:57 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-09-16T12:55:57Z</dc:date>
    <item>
      <title>Create block frm external dwg file using .Net API freeze(hangs) the AutoCAD 2016</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6566609#M34559</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created function which creates block using external drawing file, I have used following code. &lt;STRONG&gt;It creates the block properly but after creating block in the current active document auto cad hangs. &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Public Sub InsertDrawingAsBlock(doc As Document, path As String, blockname As String, ipt As Point3d, ByVal scalefator As Scale3d, ByVal rotation As Double, ByVal xmlAttribList As XmlNodeList)

        'current drawing database
        Dim currentdb As Database = doc.Database

        'current drawing's editor
        Dim editor As Editor = doc.Editor
        Dim lock As DocumentLock = doc.LockDocument()

        Dim strAttribTag As String
        Dim strAttribValue As String


        Using lock

            Dim blockid As ObjectId = ObjectId.Null

            ' create database to read dwg file
            Dim sourcedb As New Database(False, True)

            Using sourcedb

                sourcedb.ReadDwgFile(path, System.IO.FileShare.Read, True, "")

                blockid = currentdb.Insert(path, sourcedb, True)

                Using tr As Transaction = doc.TransactionManager.StartTransaction()
                    Dim bt As BlockTable = DirectCast(tr.GetObject(currentdb.BlockTableId, OpenMode.ForRead), BlockTable)


                    If bt.Has(blockname) Then
                        ' MessageBox.Show(string.Format("Block {0} does already exist\nTry another block or Exit", blockname));
                        Return
                    End If

                    bt.UpgradeOpen()

                    Dim btrec As BlockTableRecord = DirectCast(blockid.GetObject(OpenMode.ForRead), BlockTableRecord)
                    btrec.UpgradeOpen()

                    btrec.Name = blockname

                    btrec.DowngradeOpen()

                    '---&amp;gt; debug only
                    ' this code block is written in the good programming manner (remember that)
                    'For Each index As ObjectId In btrec
                    '    Dim en As Entity = DirectCast(index.GetObject(OpenMode.ForRead), Entity)

                    '    Dim adef As AttributeDefinition = TryCast(en, AttributeDefinition)

                    '    If adef IsNot Nothing Then
                    '        editor.WriteMessage(vbLf + adef.Tag)
                    '    End If
                    'Next
                    '&amp;lt;--- debug only

                    Dim btr As BlockTableRecord = DirectCast(currentdb.CurrentSpaceId.GetObject(OpenMode.ForWrite), BlockTableRecord)

                    Using btr
                        Using bref As New BlockReference(ipt, blockid)
                            Dim mat As Matrix3d = Matrix3d.Identity

                            bref.TransformBy(mat)

                            bref.ScaleFactors = scalefator
                            bref.Rotation = rotation
                            btr.AppendEntity(bref)

                            tr.AddNewlyCreatedDBObject(bref, True)

                            Using btAttRec As BlockTableRecord = DirectCast(bref.BlockTableRecord.GetObject(OpenMode.ForRead), BlockTableRecord)
                                Dim atcoll As Autodesk.AutoCAD.DatabaseServices.AttributeCollection = bref.AttributeCollection

                                For Each subid As ObjectId In btAttRec
                                    Dim ent As Entity = DirectCast(subid.GetObject(OpenMode.ForRead), Entity)
                                    Dim attDef As AttributeDefinition = TryCast(ent, AttributeDefinition)

                                    If attDef IsNot Nothing Then
                                        ' ed.WriteMessage("\nValue: " + attDef.TextString);
                                        Dim attRef As New AttributeReference()

                                        attRef.SetPropertiesFrom(attDef)

                                        attRef.Visible = attDef.Visible

                                        attRef.SetAttributeFromBlock(attDef, bref.BlockTransform)
                                        attRef.HorizontalMode = attDef.HorizontalMode

                                        attRef.VerticalMode = attDef.VerticalMode

                                        attRef.Rotation = attDef.Rotation

                                        attRef.TextStyleId = attDef.TextStyleId

                                        attRef.Position = attDef.Position + ipt.GetAsVector()
                                        attRef.Tag = attDef.Tag

                                        attRef.FieldLength = attDef.FieldLength


                                        If xmlAttribList IsNot Nothing Then
                                            For Each xmlAttrib In xmlAttribList
                                                strAttribTag = GetXMLAttribute(xmlAttrib, "tag")
                                                strAttribValue = GetXMLAttribute(xmlAttrib, "value")
                                                If attDef.Tag = strAttribTag Then
                                                    ' set the attribute text to to the correct string
                                                    attRef.TextString = strAttribValue

                                                End If
                                            Next xmlAttrib
                                        End If


                                        atcoll.AppendAttribute(attRef)

                                        tr.AddNewlyCreatedDBObject(attRef, True)

                                    End If

                                Next
                            End Using

                            bref.DowngradeOpen()
                        End Using
                    End Using

                    btrec.DowngradeOpen()

                    bt.DowngradeOpen()

                    'editor.Regen()
                    tr.TransactionManager.QueueForGraphicsFlush()
                    doc.TransactionManager.FlushGraphics()
                    tr.Commit()
                End Using
            End Using
        End Using
    End Sub&lt;/PRE&gt;&lt;P&gt;I have also executed the profiler and found that acad.exe takes more time. (Please find attached screenshot of the profiler) As per the profiler some "Malloc" funciton from ACGE20.dll (auto cad file) takes more CPU time for execution. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Profiler output" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/273556i41360B7D28DC472D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Profiler.PNG" alt="Profiler.PNG" /&gt;&lt;/span&gt;﻿&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 12:55:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6566609#M34559</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-16T12:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create block frm external dwg file using .Net API freeze(hangs) the AutoCAD</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6567006#M34560</link>
      <description>&lt;P&gt;What value is passed to the argument "path" when this InsertDrawingAsBlock() method is called? A simple file name without path, like "xxxx.dwg", or a fully pathed file name, like "C:\My drawings\my blocks\xxxx.dwg"? In either case (unless the "path" and "blockname" arguments are given the SAME value, your code will not work as expected:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. you code creates a block definition, named the same as the value of "path" parameter in this line of code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;blockId=currentdb.Insert(&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;path&lt;/STRONG&gt;&lt;/FONT&gt;, sourcedb, True)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, the value of "path" could be invalid as block name (containing character "\", "."...). Oddly enough, AutoCAD still inserts the drawing as block definition and gives it a BLANK name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2, Then your your code creates a block reference to the newly inserted block definition, and changes the block reference's name to the value of parameter "blockname", which effectively changes the blockrefernce's definition from the newly inserted definition to an pre-existing block definition named the same as the value of "blockname" parameter. As you can see, if the drawing does not have block definition with the name as the value of "blockname" parameter already existing, your code would fail to continue after you test&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If bt.Has(blockname) Then....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the correct code should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;blockid = currentdb.Insert(blockname, sourcedb, True)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case, if the drawing has a block with the same name already, this line of code will redefine the block definition into the inserted drawing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you do not need to use so many levels of "Using...End Using" block inside a transaction. Any DB-residing DBObject opened inside a transaction will be disposed by the Transaction automatically. So the code would a lot easier to write/read, sothing like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dim blockid As ObjectId=ObjectId.Null&lt;/P&gt;
&lt;P&gt;Using sourcedb&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sourceDb.ReadDwgFile(....)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;blockid=currentdb.Insert(blockname,sourcedb,true)&lt;/P&gt;
&lt;P&gt;End Using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using tran As Transaction = ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp; tran.Commit()&lt;/P&gt;
&lt;P&gt;End Using&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 15:10:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6567006#M34560</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2016-09-16T15:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create block frm external dwg file using .Net API freeze(hangs) the AutoCAD</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6567383#M34561</link>
      <description>Thanks for reviewing the code, Drawing generation working fine. I am focusing to the performance and auto cad hang issue.</description>
      <pubDate>Fri, 16 Sep 2016 17:42:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6567383#M34561</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-16T17:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create block frm external dwg file using .Net API freeze(hangs) the AutoCAD</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6568630#M34562</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;tejas.mer wrote:&lt;BR /&gt;...Drawing generation working fine. ...&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, if the values of "path" and "blockname" parameters passed ti InsertDrawingAsBlock() method are different (they should be different, or you would not need 2 arguments for this method, right?), then "Drawing generating" would ONLY be "working fine" when the drawing has a block names as the value of "blockname" parameter. The block reference you see generated in the drawing IS NOT because of inserting a drawing file as block, which probably is not you really expected. You can try run your code against a new/blank drawing (e.g. no block definition already exists in that drawing).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, if I were you, knowing the code does not do what I want to do, I'd fix that before worrying AutoCAD freezing. That is , CHANGE this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;blockId=currentdb.Insert(&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;path&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;, sourcedb, True)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;to this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;blockid = currentdb.Insert(blockname, sourcedb, True)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As for the AutoCAD freezing, does it happen when you run your faulty code the second time (or more than once)? If that is the case, then that is likely because of the line of code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;blockId=currentdb.Insert(&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;path&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;, sourcedb, True)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;when the value of path is a file name with ".dwg" and/or with full path "c:\xxxx\xxxx\aaa.dwg". As I said, this kind of value is not VALID as block name, but AutoCAD somehow still take the inserted drawing as a block definition with blank name. But if you run that line of code again, AutoCAD would try to create another block definition with blank name, which would likely crash AutoCAD in some way, thus the freezing. However, I did not actually write code to try this, just a guess. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Anyway, using a file path/name in Database.Insert() is a big NO. As common convention, when inserting block from external file, the file name (without path and extension) would be used as the block name, so your code could be:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dim blockid As ObjectId=ObjectId.Null&lt;/P&gt;
&lt;P&gt;Dim blkName=System.IO.Path.GetFileNameWithoutExtension(path)&lt;/P&gt;
&lt;P&gt;Using sourcedb&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sourceDb.ReadDwgFile(path,....)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;blockid=currentdb.Insert(blkName,sourcedb,true)&lt;/P&gt;
&lt;P&gt;End Using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Sep 2016 17:56:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6568630#M34562</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2016-09-17T17:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create block frm external dwg file using .Net API freeze(hangs) the AutoCAD</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6569862#M34563</link>
      <description>&lt;P&gt;Hi Norman,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for updates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I have reduced my code to just focus on the AutoCAD hang issue. Below is the updated code....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Public Sub InsertDrawingAsBlock(doc As Document, path As String, blockname As String, ipt As Point3d, ByVal scalefator As Scale3d, ByVal rotation As Double)

        'current drawing database
        Dim currentdb As Database = doc.Database

        'current drawing's editor
        Dim editor As Editor = doc.Editor
        Dim lock As DocumentLock = doc.LockDocument()


        Using lock

            Dim blockid As ObjectId = ObjectId.Null

            ' create database to read dwg file
            Dim sourcedb As New Database(False, True)

            Using sourcedb
                sourcedb.ReadDwgFile(path, System.IO.FileShare.Read, True, "")
                blockid = currentdb.Insert(blockname, sourcedb, True)
            End Using
        End Using
    End Sub&lt;/PRE&gt;&lt;P&gt;In the above, Path is the complete path&amp;nbsp;like&amp;nbsp;&lt;SPAN&gt;"c:\xxxx\xxxx\aaa.dwg" and blockName is "aaa". After execution of above code autocad freezes for few seconds.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can you please try this and let me know why autocad 2016 hangs?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Tejas&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 06:13:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6569862#M34563</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-19T06:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create block frm external dwg file using .Net API freeze(hangs) the AutoCAD</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6569972#M34564</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Isn't this related to the file you insert ? &lt;BR /&gt;Did you notice the same problem with different files (size, location, ...) ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried your code and it worked fine without any freezing.&lt;/P&gt;
&lt;P&gt;By my side I use similar methods with AutoCAD 2007 to 2017 without having such problem.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 07:53:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6569972#M34564</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-09-19T07:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create block frm external dwg file using .Net API freeze(hangs) the AutoCAD</title>
      <link>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6570126#M34565</link>
      <description>Hi Gilles,&lt;BR /&gt;&lt;BR /&gt;Yes, You are right it is related to specific drawing file for most of the drawing files it is working fine. I will share drawing file if possible. So that it will be helpful to find root cause.</description>
      <pubDate>Mon, 19 Sep 2016 09:54:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/create-block-frm-external-dwg-file-using-net-api-freeze-hangs/m-p/6570126#M34565</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-09-19T09:54:02Z</dc:date>
    </item>
  </channel>
</rss>

