本帖最后由 lindunling 于 2012-2-29 10:47 编辑
- <CommandMethod("CreateTkMap")> Public Sub CreateTkMap()
- Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection()
- Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
- Dim acCurDb As Database = acDoc.Database
- Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
- Dim acSSPrompt As PromptSelectionResult
- acSSPrompt = acDocEd.SelectAll()
- If acSSPrompt.Status = PromptStatus.OK Then
- Dim acSSet As SelectionSet = acSSPrompt.Value
- For Each acSSObj As SelectedObject In acSSet
- acObjIdColl.Add(acSSObj.ObjectId)
- Next
- Else
- Application.ShowAlertDialog("活动文档无内容或复杂过程出现错误!")
- Exit Sub ' 退出
- End If
- Dim sLocalRoot As String = Application.GetSystemVariable("LOCALROOTPREFIX")
- Dim sTemplatePath As String = sLocalRoot + "Template\acad.dwt"
- Dim acDocMgr As DocumentCollection = Application.DocumentManager
- Dim acNewDoc As Document = acDocMgr.Add(sTemplatePath)
- Dim acDbNewDoc As Database = acNewDoc.Database
- Using acLckDoc As DocumentLock = acNewDoc.LockDocument()
- Using acTrans = acDbNewDoc.TransactionManager.StartTransaction()
- Dim acBlkTblNewDoc As BlockTable
- acBlkTblNewDoc = acTrans.GetObject(acDbNewDoc.BlockTableId, OpenMode.ForWrite)
- Dim acBlkTblRecNewDoc As BlockTableRecord
- acBlkTblRecNewDoc = acTrans.GetObject(acBlkTblNewDoc(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
- Dim acIdMap As IdMapping = New IdMapping()
- ' acIdMap.DestinationDatabase = acCurDb
- acDocMgr.MdiActiveDocument = acNewDoc
- acCurDb.WblockCloneObjects(acObjIdColl, acBlkTblRecNewDoc.ObjectId, acIdMap, DuplicateRecordCloning.Replace, False)
- acTrans.Commit()
- End Using
- End Using
- 'acDocMgr.MdiActiveDocument = acNewDoc
- ' 对新图形文件继续操作出问题 如双击图形
- End Sub
|