Chuyển đến nội dung
Diễn đàn CADViet
Đăng nhập để thực hiện theo  
hoathuongphuoc

Cách lưu kiểu dữ liệu DBObjectCollection xuống access

Các bài được khuyến nghị

Chào các bạn,

Mình không biết bỏ topic này ở đâu. Nên xin phép admin cho mình đặt nó ở đây. Mình có thực hiện việc lấy Boundary bằng lệnh ed.TraceBoundary() của 1 hình vuông trên file cad. Giờ mình muốn lưu cái boundary này xuống access nhưng không được. Bạn nào đã từng làm việc với access có thể chỉ giúp mình được không. Mình có lưu boundary này dưới bằng kiểu OLEObject nhưng không được. Thanks.

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Chào các bạn,

Mình không biết bỏ topic này ở đâu. Nên xin phép admin cho mình đặt nó ở đây. Mình có thực hiện việc lấy Boundary bằng lệnh ed.TraceBoundary() của 1 hình vuông trên file cad. Giờ mình muốn lưu cái boundary này xuống access nhưng không được. Bạn nào đã từng làm việc với access có thể chỉ giúp mình được không. Mình có lưu boundary này dưới bằng kiểu OLEObject nhưng không được. Thanks.

Cụ thể là lưu không được chỗ nào ?

Và tại sao lại lưu DBObjectCollection mà không phải là các giá trị của nó (diện tích, chu vi, ...)

Bạn nên post code lên để "ai đó" có cơ sở mà debug.

 

PS : theo tôi biết thì CadViet ít người sử dụng Access để lưu Database, có chăng là đọc file Access (readonly) để lấy thông tin từ bên thứ ba (Etabs, SAP, ...)

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Đây là code lưu xuống database của mình.

 

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Interop
Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports form = System.Windows.Forms
Imports System.Text
Imports System
Imports System.Data.OleDb
 <CommandMethod("MYPOLY")> Public Sub MyPoly()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim pline As Polyline = Nothing
        ' Get the current color, for our temp graphics
        Dim col As Color = doc.Database.Cecolor
        ' Create a point collection to store our vertices
        Dim pts As Point3dCollection = New Point3dCollection()
        'Set up the selection options
        ' (used for all vertices)
        Dim opt As PromptPointOptions = New PromptPointOptions("")
        opt.Message = vbLf & "Select polyline vertex:"
        opt.AllowNone = True
        ' Get the start point for the polyline
        Dim res As PromptPointResult = ed.GetPoint(opt)
        While (res.Status = PromptStatus.OK)
            'Add the selected point to the list
            pts.Add(res.Value)
            'Drag a temp line during selection
            'of subsequent points
            opt.UseBasePoint = True
            opt.BasePoint = res.Value
            res = ed.GetPoint(opt)
            If (res.Status = PromptStatus.OK) Then
                ' For each point selected,
                'draw a temporary segment
                ed.DrawVector(pts.Item(pts.Count - 1), res.Value, col.ColorIndex, False) 'highlighted?
            End If
        End While
        If (res.Status = PromptStatus.Cancel) Then
            ' Get the current UCS
            Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem
            Dim origin As Point3d = New Point3d(0, 0, 0)
            Dim normal As Vector3d = New Vector3d(0, 0, 1)
            normal = normal.TransformBy(ucs)
            ' Create a temporary plane, to help with calcs
            Dim plane As Plane = New Plane(origin, normal)
            ' Create the polyline, specifying
            'the number of vertices up front
            pline = New Polyline(pts.Count)
            pline.Normal = normal
            For Each pt As Point3d In pts
                Dim transformedPt As Point3d = pt.TransformBy(ucs)
                pline.AddVertexAt(pline.NumberOfVertices, plane.ParameterOf(transformedPt), 0, 0, 0)
            Next
            ' Now let's add the polyline to the modelspace
            Using tr As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = TryCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
                Dim btr As BlockTableRecord = TryCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                Dim plineId As ObjectId = btr.AppendEntity(pline)
                tr.AddNewlyCreatedDBObject(pline, True)
                tr.Commit()
                ed.WriteMessage("\nPolyline entity is: " & plineId.ToString())
            End Using
        End If
        ' ed.Regen()
        InsertTablePolyline(pline)
    End Sub
    Private Sub InsertTablePolyline(ByVal pline As Polyline)
        ''define Class DBQuery
        clsDBQuery = New DBQuery
        Dim con As New OleDbConnection(clsDBQuery.getConnectionString())
        Dim query As String = "INSERT INTO tbPolyline(Polyline) VALUES(@polyline)"
        'Create the command.
        Dim cmd As New OleDbCommand(query, con)
        cmd.Parameters.AddWithValue("@polyline", pline)
        ''insert row
        clsDBQuery.InsertRow(cmd, con)
    End Sub
 

Và đây là database.

http://www.cadviet.com/upfiles/3/125141_stonenumbering_1.rar

Còn đây là class dùng để đổ dữ liệu vào database.

http://www.cadviet.com/upfiles/3/125141_dbquery.rar

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

 

Đây là code lưu xuống database của mình.

 

............
        InsertTablePolyline(pline)
...........

Lỗi phát sinh khi lưu dữ liệu xuống Database : "Multiple-step OLE DB operation generated errors."

Lỗi này thường là do sai kiểu dữ liệu datatype

Có thể khắc phục bằng cách convert qua string trước khi lưu.

Thắc mắc cũ : tại sao lại lưu DBObjectCollection mà không phải là các giá trị của nó (diện tích, chu vi, ...)

' Gọi InsertTablePolyline(pline.ToString())

        Private Sub InsertTablePolyline(ByVal pline As String)
            ''define Class DBQuery
            Dim clsDBQuery As New DBQuery
            Dim con As New OleDbConnection(clsDBQuery.getConnectionString())
            Dim query As String = "INSERT INTO tbPolyline(Polyline) VALUES(@polyline)"
            'Create the command.
            Dim cmd As New OleDbCommand(query, con)
            cmd.Parameters.AddWithValue("@polyline", pline)
            ''insert row
            clsDBQuery.InsertRow(cmd, con)
        End Sub

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Mình lưu DBObjectCollection khi mình muốn vẽ lại hay thao tác với hình mình vừa mới lưu sẽ đơn giản hơn. Nếu chỉ lưu diện tích hay chu vi...thì không thể biết được toàn bộ thuộc tính của cái hình mình muốn vẽ. Nó hơi khó giải thích. Hi.

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Tạo một tài khoản hoặc đăng nhập để nhận xét

Bạn cần phải là một thành viên để lại một bình luận

Tạo tài khoản

Đăng ký một tài khoản mới trong cộng đồng của chúng tôi. Điều đó dễ mà.

Đăng ký tài khoản mới

Đăng nhập

Bạn có sẵn sàng để tạo một tài khoản ? Đăng nhập tại đây.

Đăng nhập ngay
Đăng nhập để thực hiện theo  

×