'绘多义线 <CommandMethod("AddPL")> _ Public Sub AddPL() Dim pl As New Polyline Dim DB As Database Dim trans As Transaction Dim btr As BlockTableRecord Dim bt As BlockTable 'Dim li As Object DB = HostApplicationServices.WorkingDatabase trans = DB.TransactionManager.StartTransaction bt = trans.GetObject(DB.BlockTableId, OpenMode.ForWrite) btr = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) 'Dim pLinetypeTbl As LinetypeTable = trans.GetObject(DB.LinetypeTableId, OpenMode.ForRead)
'If pLinetypeTbl.Has("DASHDOT") Then 'DB.LoadLineTypeFile("DASHDOT", "acadiso.lin") 'End If Dim point2D(2) As Point2d point2D(0) = New Point2d(10, 10) point2D(1) = New Point2d(10, 5) point2D(2) = New Point2d(30, 40) pl.AddVertexAt(0, point2D(0), 0, 1, 1) pl.AddVertexAt(1, point2D(1), 0, 1, 1) pl.AddVertexAt(2, point2D(2), 0, 1, 1) pl.LinetypeId = CreatLineType("DASHDOT") ' pl.Linetype = "DASHDOT" btr.AppendEntity(pl) trans.AddNewlyCreatedDBObject(pl, True) trans.Commit() trans.Dispose() End Sub Private Function CreatLineType(ByVal LineTypeName As String) As ObjectId Dim LineTypeID As ObjectId Dim db As Database = HostApplicationServices.WorkingDatabase Using trans As Transaction = db.TransactionManager.StartTransaction Dim it As LinetypeTable = trans.GetObject(db.LinetypeTableId, OpenMode.ForRead) If it.Has(LineTypeName) Then LineTypeID = it.Item(LineTypeName) Else db.LoadLineTypeFile(LineTypeName, "acadiso.lin") Dim ltr As New LinetypeTableRecord ltr.Name = LineTypeName it.UpgradeOpen() LineTypeID = it.Add(ltr) trans.AddNewlyCreatedDBObject(ltr, True) End If trans.Commit() End Using Return LineTypeID End Function |