<?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: Trying to Insert Block - Error on ReadDWG in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677157#M81355</link>
    <description>Here is code file.&lt;BR /&gt;
&lt;BR /&gt;
I had to change the extension of the file in order for it to allow me to post.   You can change back to .vb, if you wish.&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Adam</description>
    <pubDate>Wed, 21 Jun 2006 13:16:35 GMT</pubDate>
    <dc:creator>acedmond</dc:creator>
    <dc:date>2006-06-21T13:16:35Z</dc:date>
    <item>
      <title>Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677150#M81348</link>
      <description>Hello,&lt;BR /&gt;
  I'm trying to insert a dynamic block w/attributes in to a drawing where a reference doesn't already exist.  I have got some code off of here (Thanks who ever wrote it.)  &lt;BR /&gt;
&lt;BR /&gt;
Here is what I'm running:&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub InsertBlock(ByVal ActiveDoc As Document, ByVal blockname As String)&lt;BR /&gt;
        Dim CompleteFilePath As String&lt;BR /&gt;
        CompleteFilePath = HostApplicationServices.Current.FindFile(blockname &amp;amp; ".dwg", ActiveDoc.Database, FindFileHint.Default)&lt;BR /&gt;
        'Using&lt;BR /&gt;
        Dim tempdb As Database = New Database(False, False)&lt;BR /&gt;
        Try&lt;BR /&gt;
            tempdb.ReadDwgFile(CompleteFilePath, System.IO.FileShare.ReadWrite, True, Nothing)&lt;BR /&gt;
            'Using&lt;BR /&gt;
            Dim t As Transaction = ActiveDoc.TransactionManager.StartTransaction&lt;BR /&gt;
            Try&lt;BR /&gt;
                Dim idBTR As ObjectId = ThisDrawing.Database.Insert(blockname, tempdb, False)&lt;BR /&gt;
                Dim bt As BlockTable = CType(t.GetObject(ActiveDoc.Database.BlockTableId, DatabaseServices.OpenMode.ForRead), BlockTable)&lt;BR /&gt;
                Dim btr As BlockTableRecord = CType(t.GetObject(bt(BlockTableRecord.ModelSpace), DatabaseServices.OpenMode.ForWrite), BlockTableRecord)&lt;BR /&gt;
                Dim origin As acad.Geometry.Point3d = New acad.Geometry.Point3d(0, 0, 0)&lt;BR /&gt;
                'Using&lt;BR /&gt;
                Dim bref As BlockReference = New BlockReference(origin, idBTR)&lt;BR /&gt;
                Try&lt;BR /&gt;
                    btr.AppendEntity(bref)&lt;BR /&gt;
                    t.TransactionManager.AddNewlyCreatedDBObject(bref, True)&lt;BR /&gt;
                Finally&lt;BR /&gt;
                    CType(bref, IDisposable).Dispose()&lt;BR /&gt;
                End Try&lt;BR /&gt;
                t.Commit()&lt;BR /&gt;
                t.Dispose()&lt;BR /&gt;
            Finally&lt;BR /&gt;
                CType(t, IDisposable).Dispose()&lt;BR /&gt;
            End Try&lt;BR /&gt;
        Finally&lt;BR /&gt;
            CType(tempdb, IDisposable).Dispose()&lt;BR /&gt;
        End Try&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
There error always happens on the db.readdwg sub.&lt;BR /&gt;
&lt;BR /&gt;
I get  Error Number: -2147467261&lt;BR /&gt;
Error Description: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."&lt;BR /&gt;
&lt;BR /&gt;
The block I'm trying to insert was a block that had been wblocked, then had dynamic properties added.    I can also open the block with or without blockeditor with no errors, and I'm able to insert the block with no errors either.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Adam Edmonds</description>
      <pubDate>Thu, 15 Jun 2006 21:06:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677150#M81348</guid>
      <dc:creator>acedmond</dc:creator>
      <dc:date>2006-06-15T21:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677151#M81349</link>
      <description>Ok I think I have narrowed down the issue.  I kept getting the error on :&lt;BR /&gt;
tempdb.ReadDwgFile(CompleteFilePath, System.IO.FileShare.ReadWrite, True, Nothing&lt;BR /&gt;
&lt;BR /&gt;
Well, I replaced that line with:&lt;BR /&gt;
Dim BlockDrawing As acad.ApplicationServices.Document = Application.DocumentManager.Open(CompleteFilePath, False)&lt;BR /&gt;
&lt;BR /&gt;
But, Since this block is a dynamic block, It prompted me to open in Block Editor.  If I say no the routine continues with no issues.  My question is, Does database.ReadDWGFile work for Dynamic Blocks, or only for regular blocks?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Adam Edmonds</description>
      <pubDate>Tue, 20 Jun 2006 12:27:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677151#M81349</guid>
      <dc:creator>acedmond</dc:creator>
      <dc:date>2006-06-20T12:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677152#M81350</link>
      <description>Here is the code I used to insert an entity.&lt;BR /&gt;
&lt;BR /&gt;
 - Scott&lt;BR /&gt;
&lt;BR /&gt;
[code]&lt;BR /&gt;
    Public Shared Sub InsertSymbol(ByVal doc As Document, ByVal dwgPath As String, ByVal insertPoint As Point3d, Optional ByRef attribValues As StringDictionary = Nothing, Optional ByVal prompt As Boolean = False)&lt;BR /&gt;
        If Not File.Exists(dwgPath) Then Throw New FileNotFoundException("Could not find symbol file file to insert.", dwgPath)&lt;BR /&gt;
        If doc Is Nothing Then Throw New ArgumentNullException("The document cannot be null.", "doc")&lt;BR /&gt;
&lt;BR /&gt;
        Using t As Transaction = doc.TransactionManager.StartTransaction(), db As Database = New Database(False, False)&lt;BR /&gt;
            'read drawing&lt;BR /&gt;
            db.ReadDwgFile(dwgPath, FileShare.Read, True, Nothing)&lt;BR /&gt;
&lt;BR /&gt;
            'insert it as a new block&lt;BR /&gt;
            Dim idBTR As ObjectId = doc.Database.Insert("Watermark", db, True)&lt;BR /&gt;
            'create a ref to the block&lt;BR /&gt;
&lt;BR /&gt;
            Using bt As BlockTable = t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead), _&lt;BR /&gt;
                  btr As BlockTableRecord = t.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), _&lt;BR /&gt;
                  bref As BlockReference = New BlockReference(insertPoint, idBTR)&lt;BR /&gt;
&lt;BR /&gt;
                btr.AppendEntity(bref)&lt;BR /&gt;
                doc.TransactionManager.AddNewlyCreatedDBObject(bref, True)&lt;BR /&gt;
&lt;BR /&gt;
                Using btAttRec As BlockTableRecord = t.GetObject(bref.BlockTableRecord, OpenMode.ForRead)&lt;BR /&gt;
                    For Each idEnt As ObjectId In btAttRec&lt;BR /&gt;
                        Dim ent As Entity = t.GetObject(idEnt, OpenMode.ForRead)&lt;BR /&gt;
                        If TypeOf (ent) Is AttributeDefinition Then&lt;BR /&gt;
                            'MsgBox("test2")&lt;BR /&gt;
                            Dim attDef As AttributeDefinition = ent&lt;BR /&gt;
                            Dim attRef As AttributeReference = New AttributeReference()&lt;BR /&gt;
                            With attRef&lt;BR /&gt;
                                '.SetAttributeFromBlock(attDef, bref.BlockTransform)&lt;BR /&gt;
                                .HorizontalMode = attDef.HorizontalMode&lt;BR /&gt;
                                If attDef.VerticalMode &amp;lt;&amp;gt; TextVerticalMode.TextBase Or attDef.HorizontalMode &amp;lt;&amp;gt; TextHorizontalMode.TextLeft Then&lt;BR /&gt;
                                    .AlignmentPoint = New Point3d(attDef.AlignmentPoint.X + bref.Position.X, _&lt;BR /&gt;
                                                                  attDef.AlignmentPoint.Y + bref.Position.Y, _&lt;BR /&gt;
                                                                  attDef.AlignmentPoint.Z + bref.Position.Z)&lt;BR /&gt;
                                End If&lt;BR /&gt;
                                .VerticalMode = attDef.VerticalMode&lt;BR /&gt;
                                .WidthFactor = attDef.WidthFactor&lt;BR /&gt;
                                .FieldLength = attDef.FieldLength&lt;BR /&gt;
                                .Height = attDef.Height&lt;BR /&gt;
                                .Rotation = attDef.Rotation&lt;BR /&gt;
                                .TextStyle = attDef.TextStyle&lt;BR /&gt;
                                .Position = New Point3d(attDef.Position.X + bref.Position.X, _&lt;BR /&gt;
                                                        attDef.Position.Y + bref.Position.Y, _&lt;BR /&gt;
                                                        attDef.Position.Z + bref.Position.Z)&lt;BR /&gt;
                                .Tag = attDef.Tag&lt;BR /&gt;
                                If attribValues IsNot Nothing AndAlso attribValues.ContainsKey(attDef.Tag) Then&lt;BR /&gt;
                                    .TextString = attribValues(attDef.Tag)&lt;BR /&gt;
                                ElseIf prompt Then&lt;BR /&gt;
                                    Dim value As String = InputBox(attDef.Prompt, "Set Attribute Value", "")&lt;BR /&gt;
                                    If attribValues IsNot Nothing Then attribValues.Add(attDef.Tag, value)&lt;BR /&gt;
                                    .TextString = value&lt;BR /&gt;
                                End If&lt;BR /&gt;
                            End With&lt;BR /&gt;
                            bref.AppendAttribute(attRef)&lt;BR /&gt;
                            doc.TransactionManager.AddNewlyCreatedDBObject(attRef, True)&lt;BR /&gt;
                        End If&lt;BR /&gt;
                    Next&lt;BR /&gt;
                End Using&lt;BR /&gt;
            End Using&lt;BR /&gt;
            t.Commit()&lt;BR /&gt;
        End Using&lt;BR /&gt;
    End Sub&lt;BR /&gt;
[/code]

Message was edited by: smcclure</description>
      <pubDate>Wed, 21 Jun 2006 12:32:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677152#M81350</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-21T12:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677153#M81351</link>
      <description>Thank you Scott for you reply.   &lt;BR /&gt;
&lt;BR /&gt;
Can you tell me what namespaces you have imported for this code?&lt;BR /&gt;
&lt;BR /&gt;
Thank you again,&lt;BR /&gt;
Adam</description>
      <pubDate>Wed, 21 Jun 2006 12:38:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677153#M81351</guid>
      <dc:creator>acedmond</dc:creator>
      <dc:date>2006-06-21T12:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677154#M81352</link>
      <description>Oops! Here are the imports at the top of the file (this is my utility file, though, so there may be A LOT of extras... My guess is most of them are not needed...)&lt;BR /&gt;
&lt;BR /&gt;
[code]&lt;BR /&gt;
Imports System.IO&lt;BR /&gt;
Imports System.Collections.Specialized&lt;BR /&gt;
Imports Autodesk.AutoCAD.Runtime&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop.Common&lt;BR /&gt;
Imports Autodesk.AutoCAD.ApplicationServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.DatabaseServices&lt;BR /&gt;
Imports Autodesk.AutoCAD.Geometry&lt;BR /&gt;
[/code]</description>
      <pubDate>Wed, 21 Jun 2006 12:43:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677154#M81352</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-21T12:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677155#M81353</link>
      <description>Ok after trying that routine on multiple drawings, trying to insert a number of different blocks, dynamic and not.  I still get the same error.&lt;BR /&gt;
&lt;BR /&gt;
Error Number: -2147467261&lt;BR /&gt;
Error Description: Attempted to read or write protected memory.  This is often an indication that other memory is corrupt.&lt;BR /&gt;
&lt;BR /&gt;
Anyone have any ideas?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Adam</description>
      <pubDate>Wed, 21 Jun 2006 13:04:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677155#M81353</guid>
      <dc:creator>acedmond</dc:creator>
      <dc:date>2006-06-21T13:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677156#M81354</link>
      <description>Hmmm... If it is producing an error with both routines, I think that the surroujnding code may be at fault. Is it possible you can post the full file as an attachment?&lt;BR /&gt;
&lt;BR /&gt;
 - Scott</description>
      <pubDate>Wed, 21 Jun 2006 13:07:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677156#M81354</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-21T13:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677157#M81355</link>
      <description>Here is code file.&lt;BR /&gt;
&lt;BR /&gt;
I had to change the extension of the file in order for it to allow me to post.   You can change back to .vb, if you wish.&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Adam</description>
      <pubDate>Wed, 21 Jun 2006 13:16:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677157#M81355</guid>
      <dc:creator>acedmond</dc:creator>
      <dc:date>2006-06-21T13:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677158#M81356</link>
      <description>Make sure you notify the transaction of your newly created objects (I think you are using 2006+, so that is under the Transaction.AddNewlyCreatedDBObject() or something) and maybe try using ReadDWG under the Database object instead of Open().&lt;BR /&gt;
&lt;BR /&gt;
 - Scott</description>
      <pubDate>Wed, 21 Jun 2006 13:29:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677158#M81356</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-06-21T13:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Insert Block - Error on ReadDWG</title>
      <link>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677159#M81357</link>
      <description>Are you referring to InsertBlock or InsertSymbol routine.  I Commented my InsertBlock method out and tried using your InsertSymbol.  I still got the error when I tried db.ReadDWGFile.   I can't get past this line in order to notify the transaction manager. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I used Open in Insert Block in order to get around the error.  I'm able to insert  the block by using the open method.  The are two backs to using the Open method. 1). On the drawing shows up as open on the screen, and  2). If the target block is a dynamic block the user is prompted if they want to open it in the block editor.&lt;BR /&gt;
&lt;BR /&gt;
Thank you,&lt;BR /&gt;
Adam</description>
      <pubDate>Wed, 21 Jun 2006 13:34:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/trying-to-insert-block-error-on-readdwg/m-p/1677159#M81357</guid>
      <dc:creator>acedmond</dc:creator>
      <dc:date>2006-06-21T13:34:44Z</dc:date>
    </item>
  </channel>
</rss>

