<?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 external DWG file as block using support file search path locations in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/insert-external-dwg-file-as-block-using-support-file-search-path/m-p/5729475#M39277</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The FindFile() method throws an exception (eFileError) if the file is not found in the search paths.&lt;/P&gt;
&lt;P&gt;Try replacing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim blockPath As String = HostApplicationServices.Current.FindFile(blockName &amp;amp; Convert.ToString(".dwg"), db, FindFileHint.[Default])
If String.IsNullOrEmpty(blockPath) Then
    Return ObjectId.Null
 End If&lt;/PRE&gt;
&lt;P&gt;with&amp;nbsp;something like this (not sure about VB syntax):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim blockPath As String&lt;BR /&gt;Try&lt;BR /&gt;    blockPath = HostApplicationServices.Current.FindFile(blockName &amp;amp; Convert.ToString(".dwg"), db, FindFileHint.[Default])
Catch ex As Exception&lt;BR /&gt;    MessageBox.Show(ex.Message)
    Return ObjectId.Null
End Try&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jul 2015 19:07:20 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2015-07-20T19:07:20Z</dc:date>
    <item>
      <title>Insert external DWG file as block using support file search path locations</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-external-dwg-file-as-block-using-support-file-search-path/m-p/5729434#M39276</link>
      <description>&lt;P&gt;I have a .NET app that I wrote and pieced together from the internet. My app works in AutoCAD 2012 no problem. But we're moving to&amp;nbsp;AutoCAD 2015 and I had to change the DLL files that are referenced to the 2015 files. Most of the app works fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The app checks the current Database if a certain block exists.&amp;nbsp;If the block does exist, it reads all of the paperspace tabs and reads the titleblock in each tab and stores the drawing numbers, sheet numbers and&amp;nbsp;titles&amp;nbsp;from each. It then updates the attributes of a "Drawing List" block. If the block doesn't exist it inserts the block into the drawing where the user selected. And then updates the attributes as described above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function I use to insert the block and where the error is happening is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Function InsertBlockReference(db As Database, blockName As String, insertPoint As Point3d, scale As Scale3d, angle As Double, layer As String, _
    attValues As System.Collections.Hashtable) As ObjectId
        Using tr As Transaction = db.TransactionManager.StartTransaction()
            Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
            If Not bt.Has(blockName) Then
                Dim blockPath As String = HostApplicationServices.Current.FindFile(blockName &amp;amp; Convert.ToString(".dwg"), db, FindFileHint.[Default])
                If String.IsNullOrEmpty(blockPath) Then
                    Return ObjectId.Null
                End If
                bt.UpgradeOpen()
                Using tmpDb As New Database(False, True)
                    tmpDb.ReadDwgFile(blockPath, FileShare.Read, True, Nothing)
                    db.Insert(blockName, tmpDb, True)
                End Using
            End If
            Dim btr As BlockTableRecord = TryCast(tr.GetObject(bt(blockName), OpenMode.ForRead), BlockTableRecord)

            Using br As New BlockReference(insertPoint, btr.ObjectId) With {.ScaleFactors = scale, .Rotation = angle, .Layer = layer}
                Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
                br.TransformBy(ed.CurrentUserCoordinateSystem)

                br.RecordGraphicsModified(True)
                If btr.Annotative = AnnotativeStates.[True] Then
                    Dim contextCollection As ObjectContextCollection = db.ObjectContextManager.GetContextCollection("ACDB_ANNOTATIONSCALES")
                    Autodesk.AutoCAD.Internal.ObjectContexts.AddContext(br, contextCollection.GetContext("1:1"))
                End If
                TryCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord).AppendEntity(br)
                For Each id As ObjectId In btr
                    Dim aDef As AttributeDefinition = TryCast(tr.GetObject(id, OpenMode.ForRead), AttributeDefinition)
                    If aDef IsNot Nothing Then
                        Using aRef As New AttributeReference()
                            aRef.SetAttributeFromBlock(aDef, br.BlockTransform)
                            aRef.Position = aDef.Position + br.Position.GetAsVector()
                            If attValues.ContainsKey(aDef.Tag.ToUpper()) Then
                                aRef.TextString = attValues(aDef.Tag.ToUpper()).ToString()
                            End If
                            br.AttributeCollection.AppendAttribute(aRef)
                            tr.AddNewlyCreatedDBObject(aRef, True)
                        End Using
                    End If
                Next
                tr.AddNewlyCreatedDBObject(br, True)
                tr.Commit()
                Return br.ObjectId
            End Using
        End Using
    End Function&lt;/PRE&gt;&lt;P&gt;I got the above Function from a forum online and I can't seem to find it again. I'll update if I can find it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The line that seems to have the issue is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim blockPath As String = HostApplicationServices.Current.FindFile(blockName &amp;amp; Convert.ToString(".dwg"), db, FindFileHint.[Default])&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And the error I'm&amp;nbsp;receiving is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Autodesk.AutoCAD.Runtime.Exception: eFilerError
   at Autodesk.AutoCAD.DatabaseServices.ImpHostApplicationServices.FindFile(String fileName, Database database, FindFileHint hint)
   at DrawingList.Class1.InsertBlockReference(Database db, String blockName, Point3d insertPoint, Scale3d scale, Double angle, String layer, Hashtable attValues) in \DrawingList - 2015\DrawingList\Class1.vb:line 541
   at DrawingList.Class1.newDrawingList() in \DrawingList\Class1.vb:line 84
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I can't seem to figure out why this is happening. Any help would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 18:43:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-external-dwg-file-as-block-using-support-file-search-path/m-p/5729434#M39276</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-07-20T18:43:59Z</dc:date>
    </item>
    <item>
      <title>Re : Insert external DWG file as block using support file search path locations</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-external-dwg-file-as-block-using-support-file-search-path/m-p/5729475#M39277</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The FindFile() method throws an exception (eFileError) if the file is not found in the search paths.&lt;/P&gt;
&lt;P&gt;Try replacing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim blockPath As String = HostApplicationServices.Current.FindFile(blockName &amp;amp; Convert.ToString(".dwg"), db, FindFileHint.[Default])
If String.IsNullOrEmpty(blockPath) Then
    Return ObjectId.Null
 End If&lt;/PRE&gt;
&lt;P&gt;with&amp;nbsp;something like this (not sure about VB syntax):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim blockPath As String&lt;BR /&gt;Try&lt;BR /&gt;    blockPath = HostApplicationServices.Current.FindFile(blockName &amp;amp; Convert.ToString(".dwg"), db, FindFileHint.[Default])
Catch ex As Exception&lt;BR /&gt;    MessageBox.Show(ex.Message)
    Return ObjectId.Null
End Try&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 19:07:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-external-dwg-file-as-block-using-support-file-search-path/m-p/5729475#M39277</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2015-07-20T19:07:20Z</dc:date>
    </item>
    <item>
      <title>Re : Insert external DWG file as block using support file search path locations</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-external-dwg-file-as-block-using-support-file-search-path/m-p/5729558#M39278</link>
      <description>&lt;P&gt;Thank you!!! I thought I had the correct path in my Support File Search Path and&amp;nbsp;I didn't. I had even checked it but I missed the last sub folder. I'm going to add the error catch to the program as soon as I can.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 19:51:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-external-dwg-file-as-block-using-support-file-search-path/m-p/5729558#M39278</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-07-20T19:51:55Z</dc:date>
    </item>
  </channel>
</rss>

