- 积分
- 1447
- 明经币
- 个
- 注册时间
- 2009-6-19
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- Imports Autodesk.AutoCAD.ApplicationServices
- Imports Autodesk.AutoCAD.EditorInput
- Imports Autodesk.AutoCAD.Runtime
- Imports Autodesk.AutoCAD.DatabaseServices
- Imports Autodesk.AutoCAD.Geometry
- Public Class Class1
- _
- Public Sub DWG()
- Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
- Dim db As Database = HostApplicationServices.WorkingDatabase
- Dim TrimEdge As New Polyline '裁剪边界
- Dim JZD As New Polyline '界址线
- Dim trans As Transaction = db.TransactionManager.StartTransaction
- Dim docLock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument
- Try
- Dim fillist_JZD() As TypedValue = {New TypedValue(DxfCode.LayerName, "JZD"), _
- New TypedValue(70, "1")}
- Dim res_JZD As PromptSelectionResult = ed.SelectAll(New SelectionFilter(fillist_JZD)) '选择所有界址线
- If res_JZD.Status = PromptStatus.OK Then
- Dim ss As SelectionSet = res_JZD.Value
- For Each ID_JZD As ObjectId In ss.GetObjectIds
- JZD = trans.GetObject(ID_JZD, OpenMode.ForRead)
- Dim minPt As Point3d = JZD.GeomExtents.MinPoint
- Dim maxPt As Point3d = JZD.GeomExtents.MaxPoint
- Dim RecPts As New Point3dCollection
- RecPts.Add(New Point3d((minPt.X + maxPt.X) / 2 - 364, (minPt.Y + maxPt.Y) / 2 - 241, 0))
- RecPts.Add(New Point3d((minPt.X + maxPt.X) / 2 - 364, (minPt.Y + maxPt.Y) / 2 + 241, 0))
- RecPts.Add(New Point3d((minPt.X + maxPt.X) / 2 + 364, (minPt.Y + maxPt.Y) / 2 - 241, 0))
- RecPts.Add(New Point3d((minPt.X + maxPt.X) / 2 + 364, (minPt.Y + maxPt.Y) / 2 + 241, 0))
- TrimEdge = CreatePolyline(RecPts, True) '根据界址线外接矩形生成裁剪边界
- Dim res_Other As PromptSelectionResult = ed.SelectCrossingWindow(TrimEdge.GeomExtents.MinPoint, TrimEdge.GeomExtents.MaxPoint) '根据裁剪边界外接矩形选择实体
- If res_Other.Status = PromptStatus.OK Then
- Dim ss1 As SelectionSet = res_Other.Value
- Dim idColl As ObjectIdCollection = New ObjectIdCollection(ss1.GetObjectIds)
- Dim ndb As Database = New Database(True, False) '新建数据库
- Try
- db.WblockCloneObjects(idColl, ndb.CurrentSpaceId, DuplicateRecordCloning.Replace, False) '不同数据库之间复制实体
- '裁剪,已经实现了主要实体裁剪
- ndb.SaveAs("c:\qqqq.dwg", DwgVersion.Current) '在这个位置报错
- '即时窗口里面出现如下信息:
- '在 System.AccessViolationException 中第一次偶然出现的“acdbmgd.dll”类型的异常
- 'Forgot to call Dispose? (Autodesk.AutoCAD.DatabaseServices.Polyline): DisposableWrapper
- 'Forgot to call Dispose? (Autodesk.AutoCAD.DatabaseServices.Polyline): DisposableWrapper
- '如果是从TrimEdge = CreatePolyline(RecPts, True)开始单步,这样不会出错,从这句之后单步会报错。如果是直接运行也会报错。
- Catch ex As Exception
- Finally
- ndb.Dispose()
- End Try
- End If
- Next
- End If
- Catch ex As Exception
- Finally
- '提交事务,释放资源
- trans.Commit()
- trans.Dispose()
- TrimEdge.Dispose()
- JZD.Dispose()
- docLock.Dispose()
- db.Dispose()
- End Try
- End Sub
- '''
- ''' 创建多段线
- '''
- ''' 点集
- ''' 是否闭合
- '''
- '''
- Private Function CreatePolyline(ByVal ptColl As Point3dCollection, ByVal bl As Boolean) As Polyline
- Dim pline As New Polyline
- For i As Integer = 0 To ptColl.Count - 1
- pline.AddVertexAt(i, ptColl(i).Convert2d(New Plane()), 0, 0, 0)
- Next
- pline.Closed = bl
- Return pline
- End Function
- End Class
开发环境:VS2008+.NET2.0+CAD2006
代码如上,这个是一个裁剪程序里面一小段,裁剪的主题部分已差不多了,我是准备new数据库来保存的,可是保存出错了,详细描述在注释里。希望高手们指导一下
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|