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

Tạo layer cho Text

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

Chào các bạn,

Các bạn cho mình hỏi sao mình làm như thế này:

 <CommandMethod("dd")> Public Sub DrawText()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        ucs = ed.CurrentUserCoordinateSystem
        doc.LockDocument()
        ''Messenger select stone
        Dim pOption As New PromptPointOptions("")
        pOption.Message = vbLf & "Select Point:"
        Dim pResult As PromptPointResult = ed.GetPoint(pOption)
        doc.LockDocument()
        '' Start a transaction
        Using acTrants As Transaction = db.TransactionManager.StartTransaction()
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrants.GetObject(db.BlockTableId, _
            OpenMode.ForRead)
            '' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrants.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            OpenMode.ForWrite)

            ''Create a single-line text object
           Dim acText As DBText = New DBText()
            acText.SetDatabaseDefaults()
            acText.Position = New Point3d(0, 0, 0)
            acText.Height = 100
            acText.TextString = "Cadviet"
            acText.Layer = "LTEXT"
            acText.WidthFactor = 0.8
            acBlkTblRec.AppendEntity(acText)
            '' condition add floor
            acBlkTblRec.AppendEntity(acText)
            acTrants.AddNewlyCreatedDBObject(acText, True)
            acTrants.Commit()
        End Using

Thứ nhất: Không biết tại sao nó lại báo lỗi chỗ acText.Layer = "LTEXT".

Thứ hai: Làm sao khi mình click tạo nhiều chữ "CadViet" thì chữ sau sẽ dóng hàng theo các chữ trước(Ortho). Mình xin cảm ơn.

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,

Các bạn cho mình hỏi sao mình làm như thế này:

 <CommandMethod("dd")> Public Sub DrawText()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        ucs = ed.CurrentUserCoordinateSystem
        doc.LockDocument()
        ''Messenger select stone
        Dim pOption As New PromptPointOptions("")
        pOption.Message = vbLf & "Select Point:"
        Dim pResult As PromptPointResult = ed.GetPoint(pOption)
        doc.LockDocument()
        '' Start a transaction
        Using acTrants As Transaction = db.TransactionManager.StartTransaction()
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrants.GetObject(db.BlockTableId, _
            OpenMode.ForRead)
            '' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrants.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            OpenMode.ForWrite)

            ''Create a single-line text object
           Dim acText As DBText = New DBText()
            acText.SetDatabaseDefaults()
            acText.Position = New Point3d(0, 0, 0)
            acText.Height = 100
            acText.TextString = "Cadviet"
            acText.Layer = "LTEXT"
            acText.WidthFactor = 0.8
            acBlkTblRec.AppendEntity(acText)
            '' condition add floor
            acBlkTblRec.AppendEntity(acText)
            acTrants.AddNewlyCreatedDBObject(acText, True)
            acTrants.Commit()
        End Using

Thứ nhất: Không biết tại sao nó lại báo lỗi chỗ acText.Layer = "LTEXT".

Thứ hai: Làm sao khi mình click tạo nhiều chữ "CadViet" thì chữ sau sẽ dóng hàng theo các chữ trước(Ortho). Mình xin cảm ơn.

Trả lời cho bạn :

Câu hỏi thứ nhất : nó lại báo lỗi chỗ acText.Layer = "LTEXT".

- khi gán thuộc tính Layer cho 1 Entity, CAD y/cầu Layer đó phải tồn tại (nghĩa là trong bản vẽ đã có layer đó hoặc trong code có dòng thêm layer này trước đó). Nhưng khi chạy lệnh vì 1 lý do nào đó (???) nếu bản vẽ đã có layer tên là "LTEXT" thì sẽ không có lỗi.

Câu hỏi thứ hai :  chữ sau sẽ dóng hàng theo các chữ trước.

- trong code trên, dòng acText.Position = New Point3d(0, 0, 0) gán vị trí của Text tại tọa độ : (0, 0, 0) nên k/quả đương nhiên là các Text phải trùng nhau tại gốc tọa độ (chứ không chỉ là dóng hàng theo chữ trước).

- nếu muốn thay đổi theo v/trí pick chuột, thay dòng trên bằng dòng : acText.Position = pResult.Value (thêmTransformBy nếu đang ở UCS)

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  

×