Load XREF from SQL

< previous    1 2 3
Wout
3/18/2020 9:08 PM

That's not correct. As I said you need to load the xref in ProcessBlock. This method is called for each block with an external reference, so it should be called as many times as there are blocks with an xref. Put a breakpoint in that method in Visual Studio and debug.

- Wout

Lagen
3/18/2020 9:41 PM

Hi Wout

Is this the right way to do this?

Visual Basic Code:
Imports WW.Cad.Model
Imports WW.Cad.Model.Tables
Imports System.Data.SqlClient
Imports System.IO

Imports WW.Cad.IO
Imports WW.Cad.Model.Objects
Imports WW.Cad.UI.Extensions
Imports WW.Cad.UI.Windows.Forms
Imports WeifenLuo.WinFormsUI.Docking
Imports WW.Cad.Drawing

Public Class Form2
    Public Function CustomLoadExternalReferences(ByVal model As DxfModel) As DxfModel
        Dim missingReferences As IList(Of DxfBlock) = Nothing
        model.LoadExternalReferences(AddressOf ProcessBlock, missingReferences)
    End Function


    Public Shared Function ProcessBlock(ByVal block As WW.Cad.Model.Tables.DxfBlock) As WW.Cad.Model.DxfModel
        Dim [return] As WW.Cad.Model.DxfModel = Nothing
        [return] = openDWG(block.Name)
        Return [return]
    End Function
    Public Shared Function openDWG(ByVal DWG_Name As String) As DxfModel
        Using cn As SqlConnection = GetConnectionSQL()
            cn.Open()
            Using cmd As SqlCommand = New SqlCommand("select FileStream from DWG_FILESTREAM where FileName='" & DWG_Name & ".DWG'", cn)
                Using dr As SqlDataReader = cmd.ExecuteReader(System.Data.CommandBehavior.[Default])
                    If dr.Read() Then
                        'Dim fileData As Byte() = CType(dr.GetValue(0), Byte())
                        Dim memoryStream As MemoryStream = New MemoryStream()
                        memoryStream = New MemoryStream(CType(dr.GetValue(0), Byte()))
                        Dim reader As DwgReader = New DwgReader(memoryStream)
                        reader.LoadUnknownObjects = True
                        Dim Model As DxfModel = reader.Read
                        Return Model
                    End If
                    dr.Close()
                End Using
            End Using
        End Using
    End Function

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Using cn As SqlConnection = GetConnectionSQL()
            cn.Open()
            Using cmd As SqlCommand = New SqlCommand("select FileStream from DWG_FILESTREAM where FileName='E64F_0130102M.dwg'", cn)
                Using dr As SqlDataReader = cmd.ExecuteReader(System.Data.CommandBehavior.[Default])
                    If dr.Read() Then
                        'Dim fileData As Byte() = CType(dr.GetValue(0), Byte())
                        Dim memoryStream As MemoryStream = New MemoryStream()
                        memoryStream = New MemoryStream(CType(dr.GetValue(0), Byte()))
                        Dim reader As DwgReader = New DwgReader(memoryStream)
                        reader.LoadUnknownObjects = True
                        Dim openModel As DxfModel = reader.Read
                        Dim displayedLayout As DxfLayout = If(openModel.Header.ShowModelSpace, openModel.ModelLayout, openModel.ActiveLayout)
                        Dim cadAnnotationControl As CadAnnotationControl = New CadAnnotationControl()
                        Dim annotationsModel As DxfModel = New DxfModel()
                        CustomLoadExternalReferences(openModel)
                    End If
                    dr.Close()
                End Using
            End Using
        End Using
    End Sub
    Public Shared Function GetConnectionSQL() As SqlConnection
        Return New SqlConnection("Data Source =.\SQLExpress; Initial Catalog =LOCUM_TEST; Integrated Security =SSPI;")
    End Function
    Public ReadOnly Property ActiveCadEditControl As CadEditControl
        Get
            Dim item As CadEditControl
            If (Me.dockPanel.ActiveDocument Is Nothing) Then
                item = Nothing
            Else
                item = TryCast(DirectCast(Me.dockPanel.ActiveDocument, DockContent).Controls(0), CadEditControl)
            End If
            Return item
        End Get
    End Property
End Class

< previous    1 2 3