Tạo Text AutoCAD bằng VB.Net

Public Sub AddDText(ByVal X, ByVal Y, ByVal TS, ByVal heigh, ByVal Text, ByVal color, ByVal CanLe, ByVal Goc)
        '' Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

            '' Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, DatabaseServices.OpenMode.ForRead)

            '' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), DatabaseServices.OpenMode.ForWrite)

            '' Create a multiline text object
            Dim acMText As DBText = New DBText()
            Dim acTextStyleTable1 As TextStyleTable
            acTextStyleTable1 = acTrans.GetObject(acCurDb.TextStyleTableId, DatabaseServices.OpenMode.ForRead)
            acMText.SetDatabaseDefaults()

            SET_TEXT_STYLE(acMText, acTextStyleTable1.Item(TS))
            Dim acPtIns As Point3d = New Point3d(X, Y, 0)
            acMText.TextString = Text
            acMText.Height = heigh
            acMText.ColorIndex = color
            acMText.Position = acPtIns
            acMText.Rotation = Goc

            Dim textAlign(0 To 2) As Integer
            textAlign(0) = TextHorizontalMode.TextLeft
            textAlign(1) = TextHorizontalMode.TextMid
            textAlign(2) = TextHorizontalMode.TextRight
            acMText.HorizontalMode = textAlign(CanLe)
            acMText.VerticalMode = TextVerticalMode.TextVerticalMid
            acMText.AlignmentPoint = acPtIns

            acBlkTblRec.AppendEntity(acMText)
            acTrans.AddNewlyCreatedDBObject(acMText, True)

            '' Save the changes and dispose of the transaction
            acTrans.Commit()
        End Using
    End Sub


 Sub SET_TEXT_STYLE(ByVal acText As Object, ByVal TextTypeTable As Object)
        Try
            acText.TextStyle = TextTypeTable
        Catch ex As System.Exception
            acText.TextStyleID = TextTypeTable
        End Try
   End Sub

********************
Ví dụ gọi hàm:
AddDText(point.X, point.Y, "HEC3_KichThuoc", 0.15, NoiDung.ToString, 3, 1, Math.PI / 2)



Không có nhận xét nào:

Đăng nhận xét