- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all 😄
I'm having some issues with a modeless dialog box that's inhibiting the importation of an XREF. Here's the only code that transpires before the dialog is generated:
Public Class Scanner_Command
<CommandMethod("SCANNER")>
Public Sub ScannerCommand()
If scannerWindow Is Nothing OrElse scannerWindow.IsDisposed Then
scannerWindow = New SCANNERWindow
End If
Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(scannerWindow)
scannerWindow.Size = New Size(868, 644)
scannerWindow.MinimumSize = scannerWindow.Size
scannerWindow.MaximumSize = scannerWindow.Size
scannerWindow.DataGridView1.ColumnHeadersVisible = False
scannerWindow.DataGridView1.RowHeadersWidth = 140
End Sub
End Class
from there, a dialog is generated, with a button that does this:
Public Class ScannerWindow
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Scanner_Command.LoadAndCopyTemplate()
End Sub
End Class
which invokes this command:
<CommandMethod("LOADTEST")>
Public Shared Sub LoadAndCopyTemplate()
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim templatePath As String = "C:\TEMPLATE.dwg"
Dim xrefName As String = "_EATEMPLATE" & DateTime.Now.ToString("yyyyMMddHHmmss")
Dim insertionPoint As New Point3d(0, 0, 0)
Dim paddingValue As Double = 50.0 ' Define your padding value here
' Define filter bounds
Dim origFilterBounds As New Point3dCollection()
origFilterBounds.Add(New Point3d(12932565.9598, 262220.6699, 0))
origFilterBounds.Add(New Point3d(12932565.9598, 262683.1699, 0))
origFilterBounds.Add(New Point3d(12933345.9598, 262683.1699, 0))
origFilterBounds.Add(New Point3d(12933345.9598, 262220.6699, 0))
' Get padded filter bounds
Dim paddedFilterBounds As Point3dCollection = GetPaddedCoordsBox(origFilterBounds, paddingValue)
' Attach and bind xref
Dim xrefId As ObjectId = AttachAndBindXref(db, templatePath, xrefName)
' Extract required entities and add to database
ExtractEntitiesWithinBounds(db, xrefId, paddedFilterBounds)
' Delete empty layers if there are any
'DeleteEmptyLayers(db)
' Zoom to the block
ZoomToPoint(insertionPoint, 462) ' Replace 462 with the proper window width after adjustment
End Sub
Public Shared Function AttachAndBindXref(db As Database, filePath As String, blockName As String) As ObjectId
Dim xrefId As ObjectId
Using acTrans As Transaction = db.TransactionManager.StartTransaction()
xrefId = db.AttachXref(filePath, blockName)
acTrans.Commit()
Using acTransBind As Transaction = db.TransactionManager.StartTransaction()
If Not xrefId.IsNull Then
Dim xrefs As New ObjectIdCollection()
xrefs.Add(xrefId)
db.BindXrefs(xrefs, True)
End If
acTransBind.Commit()
End Using
End Using
Return xrefId
End Function
And it all finally culminates with a crash on this offending line:
xrefId = db.AttachXref(filePath, blockName)
and an eFileAccessErr unhandles exception. Some observations are that using the LOADTEST command works just fine! It's only when I try to invoke it from a dialog window that my problems begin, so I'm able to confirm the functionality of the script at least. Also it works when the dialog box is Modal but not Modeless, however my needs depend on it being modeless. I've tried disposing and closing and using events and everything else I can think of but nothing I do is working, any advice?
Solved! Go to Solution.