- 积分
- 608
- 明经币
- 个
- 注册时间
- 2009-10-15
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2010-6-24 16:22:00
|
显示全部楼层
我改成了vb.net的,但是还是有问题,请帮忙看看:-
- 'VB.NET
- Imports System.IO
- 'CAD
- Imports Autodesk.AutoCAD.ApplicationServices
- Imports Autodesk.AutoCAD.DatabaseServices
- Imports Autodesk.AutoCAD.EditorInput
- Imports Autodesk.AutoCAD.Geometry
- Imports Autodesk.AutoCAD.Runtime
- Public Class CopyCls
- <CommandMethod("netcopy")> Public Shared Sub Test13()
- Dim doc As Document = Application.DocumentManager.MdiActiveDocument
- Dim dbDesc As Database = doc.Database
- Dim dbSouce As New Database(False, True)
- dbSouce.ReadDwgFile("C:\1.dwg", FileShare.Read, True, Nothing)
- Using trSouce As Transaction = dbSouce.TransactionManager.StartTransaction()
- Dim btSouce As BlockTable = TryCast(trSouce.GetObject(dbSouce.BlockTableId, OpenMode.ForRead), BlockTable)
- Dim tstSouce As TextStyleTable = TryCast(trSouce.GetObject(dbSouce.TextStyleTableId, OpenMode.ForRead), TextStyleTable)
- Dim ltSouce As LinetypeTable = TryCast(trSouce.GetObject(dbSouce.LinetypeTableId, OpenMode.ForRead), LinetypeTable)
- Dim dstSouce As DimStyleTable = TryCast(trSouce.GetObject(dbSouce.DimStyleTableId, OpenMode.ForRead), DimStyleTable)
- Dim dstrSouce As DimStyleTableRecord = TryCast(trSouce.GetObject(dstSouce("1"), OpenMode.ForRead), DimStyleTableRecord)
- Using trDesc As Transaction = dbDesc.TransactionManager.StartTransaction() '在这里就出错了
- Dim btDesc As BlockTable = TryCast(trDesc.GetObject(dbDesc.BlockTableId, OpenMode.ForRead), BlockTable)
- Dim tstDesc As TextStyleTable = TryCast(trDesc.GetObject(dbDesc.TextStyleTableId, OpenMode.ForWrite), TextStyleTable)
- Dim ltDesc As LinetypeTable = TryCast(trDesc.GetObject(dbDesc.LinetypeTableId, OpenMode.ForWrite), LinetypeTable)
- Dim dstDesc As DimStyleTable = TryCast(trDesc.GetObject(dbDesc.DimStyleTableId, OpenMode.ForWrite), DimStyleTable)
- Dim dstrDesc As New DimStyleTableRecord()
- dstrDesc.CopyFrom(dstrSouce)
- dstrDesc.Dimblk = GetBtrForm(dstrSouce.Dimblk, btSouce, btDesc)
- dstrDesc.Dimblk1 = GetBtrForm(dstrSouce.Dimblk1, btSouce, btDesc)
- dstrDesc.Dimblk2 = GetBtrForm(dstrSouce.Dimblk2, btSouce, btDesc)
- dstrDesc.Dimldrblk = GetBtrForm(dstrSouce.Dimldrblk, btSouce, btDesc)
- dstrDesc.Dimtxsty = GetTstrForm(trDesc, dstrSouce.Dimtxsty, tstSouce, tstDesc)
- dstrDesc.Dimltex1 = GetLtrForm(trDesc, dstrSouce.Dimltex1, ltSouce, ltDesc)
- dstrDesc.Dimltex2 = GetLtrForm(trDesc, dstrSouce.Dimltex2, ltSouce, ltDesc)
- dstDesc.Add(dstrDesc)
- trDesc.AddNewlyCreatedDBObject(dstrDesc, True)
- trDesc.Commit()
- End Using
- trSouce.Commit()
- End Using
- End Sub
- Public Shared Function GetTstrForm(ByVal tr As Transaction, ByVal rid As ObjectId, ByVal tstSouce As TextStyleTable, ByVal tstDesc As TextStyleTable) As ObjectId
- If rid <> ObjectId.Null Then
- Dim tstrSouce As TextStyleTableRecord = DirectCast(rid.GetObject(OpenMode.ForRead), TextStyleTableRecord)
- Dim idRes As ObjectId = GetRecordId(tstDesc, tstrSouce.Name)
- If idRes = ObjectId.Null Then
- Dim tstrDesc As New TextStyleTableRecord()
- tstrDesc.CopyFrom(tstrSouce)
- idRes = tstDesc.Add(tstrDesc)
- tr.AddNewlyCreatedDBObject(tstrDesc, True)
- End If
- Return idRes
- End If
- Return ObjectId.Null
- End Function
- Public Shared Function GetLtrForm(ByVal tr As Transaction, ByVal rid As ObjectId, ByVal ltSouce As LinetypeTable, ByVal ltDesc As LinetypeTable) As ObjectId
- If rid <> ObjectId.Null Then
- Dim ltrSouce As LinetypeTableRecord = DirectCast(rid.GetObject(OpenMode.ForRead), LinetypeTableRecord)
- Dim idRes As ObjectId = GetRecordId(ltDesc, ltrSouce.Name)
- If idRes = ObjectId.Null Then
- Dim ltrDesc As New LinetypeTableRecord()
- ltrDesc.CopyFrom(ltrSouce)
- idRes = ltDesc.Add(ltrDesc)
- tr.AddNewlyCreatedDBObject(ltrDesc, True)
- End If
- Return idRes
- End If
- Return ObjectId.Null
- End Function
- Public Shared Function GetBtrForm(ByVal rid As ObjectId, ByVal btSouce As BlockTable, ByVal btDesc As BlockTable) As ObjectId
- If rid <> ObjectId.Null Then
- Dim btrSouce As BlockTableRecord = DirectCast(rid.GetObject(OpenMode.ForRead), BlockTableRecord)
- Dim idRes As ObjectId = GetRecordId(btDesc, btrSouce.Name)
- If idRes = ObjectId.Null Then
- Dim ids As New ObjectIdCollection()
- ids.Add(rid)
- btSouce.Database.Wblock(btDesc.Database, ids, New Point3d(), DuplicateRecordCloning.Replace)
- idRes = GetRecordId(btDesc, btrSouce.Name)
- End If
- Return idRes
- End If
- Return ObjectId.Null
- End Function
- Public Shared Function GetRecordId(ByVal st As SymbolTable, ByVal key As String) As ObjectId
- If st.Has(key) Then
- Dim idres As ObjectId = st(key)
- If Not idres.IsErased Then
- Return idres
- End If
- For Each id As ObjectId In st
- If Not id.IsErased Then
- Dim str As SymbolTableRecord = DirectCast(id.GetObject(OpenMode.ForRead), SymbolTableRecord)
- If str.Name = key Then
- Return id
- End If
- End If
- Next
- Return st(key)
- End If
- Return ObjectId.Null
- End Function
- End Class
|
|