<?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 Importing a dynamic block from an embedded resource within a dll. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5633870#M40108</link>
    <description>&lt;P&gt;Hello, I'm trying to write a dll in vb.net that will import a dynamic block from an autocad file that is embedded as a resource file in the project solution at a given point in the current document. The issue is that the file location for the drawing with the block is at a different folder on each computer. If it is embedded in the dll it will make it easier to distribute to the other computers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
    <pubDate>Wed, 13 May 2015 21:09:43 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-05-13T21:09:43Z</dc:date>
    <item>
      <title>Importing a dynamic block from an embedded resource within a dll.</title>
      <link>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5633870#M40108</link>
      <description>&lt;P&gt;Hello, I'm trying to write a dll in vb.net that will import a dynamic block from an autocad file that is embedded as a resource file in the project solution at a given point in the current document. The issue is that the file location for the drawing with the block is at a different folder on each computer. If it is embedded in the dll it will make it easier to distribute to the other computers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2015 21:09:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5633870#M40108</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-05-13T21:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a dynamic block from an embedded resource within a dll.</title>
      <link>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5634619#M40109</link>
      <description>&lt;P&gt;Since you can only, in .NET API, open a drawing (or read drawing data into a side Database) from a file, the solution would be to save the binary data of the embedded resources (DWG file) into a temporary file and then open/read it into AutoCAD.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, you would&amp;nbsp;use AutoCAD's temporary file location, which you could find out via Application.Preferences.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The drawback of embedding Dwg file with your DLL is that if there is requirement to make change to the DWG (block or blocks), you have to recompile your app and redistribute/deploy the app.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The usual approach to find CAD resources that may be in different locations is to set up AutoCAD support paths properly, and always let your code search support paths for CAD resources (DWG/block files). If not found, handle the FileNotFound Exception to prompt user something is wrong. This way gives you flexibility of not tying the DWG/Block file to your code so that you can update the DWG/Block as needed without having to rebuild your app.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2015 13:31:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5634619#M40109</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2015-05-14T13:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a dynamic block from an embedded resource within a dll.</title>
      <link>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5638146#M40110</link>
      <description>&lt;P&gt;Thank you for the information. I was able to save the file to a location and then retrieve the file when needed. Now my issue is that the block gets added to the blocktable record but it does not get placed in the model space at the location that I want it. What am I doing wrong?&lt;/P&gt;&lt;PRE&gt;Public Class InsertBlocks

    Public Shared Sub InsertBlock(ByVal InsertionPoint As Point3d)
        'Get the block needed for inserting
        Dim FileName As String = "E:\Documents\Documents\vbNET\Balloon 1-2.dwg"
        Dim Rotation As Double = 0

        'Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        'Before making any changes to an AutoCAD document you must lock it
        'Lock the document
        Using acLckDoc As DocumentLock = acDoc.LockDocument()

            Dim blockId As ObjectId

            Using blockDb As New Database(False, True)
                blockDb.ReadDwgFile(FileName, System.IO.FileShare.Read, True, "")
                blockId = acCurDb.Insert(System.IO.Path.GetFileNameWithoutExtension(FileName), blockDb, True)

                'Start a transaction
                Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                    'Open the Block table for read
                    Dim acBlkTbl As BlockTable
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)


                    If acBlkTbl.Has(blockId) = False Then
                        'Open the Block table record Model space for write
                        Dim acBlkTblRec As BlockTableRecord
                        acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                                         OpenMode.ForWrite)

                        'Create a BlockReference in the current document
                        Dim acBlkRef As New BlockReference(InsertionPoint, blockId)
                        Dim acBlkMat As Matrix3d = Matrix3d.Identity
                        acBlkRef.TransformBy(acBlkMat)
                        acBlkRef.Layer = "0"
                        acBlkRef.Rotation = 0

                        If acBlkRef.IsDynamicBlock Then
                            Dim acDynBlkRefPropCol As DynamicBlockReferencePropertyCollection = acBlkRef.DynamicBlockReferencePropertyCollection
                            For Each acDynBlkRefProp As DynamicBlockReferenceProperty In acDynBlkRefPropCol
                                If acDynBlkRefProp.PropertyName.ToUpper = "VISIBILITY" Then
                                    acDynBlkRefProp.Value = "Right"
                                End If
                            Next
                        End If

                        'Add the new object to the block table record and the transaction
                        acBlkTblRec.AppendEntity(acBlkRef)
                        acTrans.AddNewlyCreatedDBObject(acBlkRef, True)

                    End If
                    acTrans.Commit()
                End Using
            End Using
        End Using
    End Sub
End Class&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 May 2015 04:37:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5638146#M40110</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-05-17T04:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a dynamic block from an embedded resource within a dll.</title>
      <link>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5638253#M40111</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for the information. I was able to save the file to a location and then retrieve the file when needed. Now my issue is that the block gets added to the blocktable record but it does not get placed in the model space at the location that I want it. What am I doing wrong?&lt;/P&gt;
&lt;PRE&gt;Public Class InsertBlocks

    Public Shared Sub InsertBlock(ByVal InsertionPoint As Point3d)
        'Get the block needed for inserting
        Dim FileName As String = "E:\Documents\Documents\vbNET\Balloon 1-2.dwg"
        Dim Rotation As Double = 0

        'Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        'Before making any changes to an AutoCAD document you must lock it
        'Lock the document
        Using acLckDoc As DocumentLock = acDoc.LockDocument()

            Dim blockId As ObjectId

            Using blockDb As New Database(False, True)
                blockDb.ReadDwgFile(FileName, System.IO.FileShare.Read, True, "")
                blockId = acCurDb.Insert(System.IO.Path.GetFileNameWithoutExtension(FileName), blockDb, True)

                'Start a transaction
                Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

                    'Open the Block table for read
                    Dim acBlkTbl As BlockTable
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)


                    If &lt;FONT color="#FF0000"&gt;&lt;EM&gt;&lt;STRONG&gt;acBlkTbl.Has(blockId) = False&lt;/STRONG&gt;&lt;/EM&gt;&lt;/FONT&gt; Then
                        'Open the Block table record Model space for write
                        Dim acBlkTblRec As BlockTableRecord
                        acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                                         OpenMode.ForWrite)

                        'Create a BlockReference in the current document
                        Dim acBlkRef As New BlockReference(InsertionPoint, blockId)
                        Dim acBlkMat As Matrix3d = Matrix3d.Identity
                        acBlkRef.TransformBy(acBlkMat)
                        acBlkRef.Layer = "0"
                        acBlkRef.Rotation = 0

                        If acBlkRef.IsDynamicBlock Then
                            Dim acDynBlkRefPropCol As DynamicBlockReferencePropertyCollection = acBlkRef.DynamicBlockReferencePropertyCollection
                            For Each acDynBlkRefProp As DynamicBlockReferenceProperty In acDynBlkRefPropCol
                                If acDynBlkRefProp.PropertyName.ToUpper = "VISIBILITY" Then
                                    acDynBlkRefProp.Value = "Right"
                                End If
                            Next
                        End If

                        'Add the new object to the block table record and the transaction
                        acBlkTblRec.AppendEntity(acBlkRef)
                        acTrans.AddNewlyCreatedDBObject(acBlkRef, True)

                    End If
                    acTrans.Commit()
                End Using
            End Using
        End Using
    End Sub
End Class&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I made it in red in your code that prevents the block refernce from being inserted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If acBlkTbl.Has(blockId) = True Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; ......&lt;/P&gt;
&lt;P&gt;End if&lt;/P&gt;</description>
      <pubDate>Sun, 17 May 2015 12:47:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/importing-a-dynamic-block-from-an-embedded-resource-within-a-dll/m-p/5638253#M40111</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2015-05-17T12:47:39Z</dc:date>
    </item>
  </channel>
</rss>

