Friend zcOriginalDoc As Document = Application.DocumentManager.MdiActiveDocument
<CommandMethod("SMR", CommandFlags.Session)>
Public Sub SmartInsert()
Application.SetSystemVariable("SDI", 0)
Application.SetSystemVariable("attdia", 1)
Application.SetSystemVariable("cmdecho", 0)
Dim OpenDwgFileDialog As New System.Windows.Forms.OpenFileDialog()
With OpenDwgFileDialog
.InitialDirectory = EdrivePath
.Filter = "E-drive Block Files |*.Dwg"
.Title = "Select an E-drive Block File....."
.FileName = ""
.RestoreDirectory = True
End With
If OpenDwgFileDialog.ShowDialog = System.Windows.Forms.DialogResult.OK Then
FullEdriveFileName = OpenDwgFileDialog.FileName.ToUpper
zcBlockDoc = zcDocMngr.Open(FullEdriveFileName, True)
zcBlockDoc = ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Else
OpenDwgFileDialog.Dispose()
End If
End Sub
Then we perfume some operations on the file and close it and set the MDI Active document back to the original file
With zcBlockDoc
.Database.SaveAs(_RandomName, DwgVersion.Current) ', False)
.CloseAndDiscard()
End With
zcBlockDoc.Dispose()
ZwSoft.ZwCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = zcOriginalDoc
The problem appears when trying to insert the zcBlockDoc document as a block in the zcOriginalDoc
In the blow code as the .net environment always finds the zcOriginalDoc Not active
Dim zcInsPntRes As PromptPointResult
Dim zcInsPntOpts As PromptPointOptions = New PromptPointOptions("")
With zcInsPntOpts
.UseBasePoint = False
.Message = vbCrLf & "Specify the insertion point for block :"
End With
zcInsPntRes = zcOriginalDoc.Editor.GetPoint(zcInsPntOpts)