本帖最后由 guohq 于 2011-10-28 23:14 编辑
- '''
- ''' 向任意空间添加多个对象
- '''
- '''
- '''
- '''
- '''
- Public Function AppendEntity(ByVal Ents() As Entity, ByVal LayoutName As String) As ObjectId()
- Dim rtnIDs(Ents.Length - 1) As ObjectId
- Using Trans As Transaction = DB.TransactionManager.StartTransaction
- Dim DictLy As DBDictionary = Trans.GetObject(DB.LayoutDictionaryId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
- If DictLy.Contains(LayoutName) = False Then
- For I As Integer = 0 To rtnIDs.Length - 1
- rtnIDs(I) = ObjectId.Null
- Next
- Trans.Commit()
- Return rtnIDs
- End If
- Dim Lyid As ObjectId = DictLy.GetAt(LayoutName)
- Dim Ly As Layout = Trans.GetObject(Lyid, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
- Dim BTR As BlockTableRecord = Trans.GetObject(Ly.BlockTableRecordId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
- Dim Ent As Entity = Nothing
- For I As Integer = 0 To Ents.Length - 1
- Ent = Ents(I)
- rtnIDs(I) = BTR.AppendEntity(Ent)
- Trans.AddNewlyCreatedDBObject(Ent, True)
- Next
- Trans.Commit()
- End Using
- Return rtnIDs
- End Function
|