copy Model Space to external DWG
' copy Model Space to external DWG
' by Fenton Webb, DevTech 14/9/2012
<CommandMethod("CoSpypaceToExtDWG")> _
Public Shared Sub CopySpaceToExtDWG()
' get the working database (in AutoCAD)
Dim sourceDb As Database = Application.DocumentManager.MdiActiveDocument.Database
Try
' create a new destination database
Using destDb As New Database(True, True)
' get the model space object ids for both dbs
Dim sourceMsId As ObjectId = SymbolUtilityServices.GetBlockModelSpaceId(sourceDb)
Dim destDbMsId As ObjectId = SymbolUtilityServices.GetBlockModelSpaceId(destDb)
' now create an array of object ids to hold the source objects to copy
Dim sourceIds As New ObjectIdCollection()
' open the sourceDb ModelSpace (current autocad dwg)
Using ms As BlockTableRecord = TryCast(sourceMsId.Open(OpenMode.ForRead), BlockTableRecord)
' loop all the entities and record their ids
For Each id As ObjectId In ms
sourceIds.Add(id)
Next
End Using
' next prepare to deepclone the recorded ids to the destdb
Dim mapping As New IdMapping()
' now clone the objects into the destdb
sourceDb.WblockCloneObjects(sourceIds, destDbMsId, mapping, DuplicateRecordCloning.Replace, False)
destDb.SaveAs("c:\temp\dwgs\CopyTest.dwg", DwgVersion.Current)
End Using
Catch eXP As System.Exception
System.Windows.Forms.MessageBox.Show(eXP.ToString())
End Try
End Sub
folder and files cannot
欢迎关注微信公众账号ByCAD