乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 30|回复: 1

vbnet cad内存增加到崩溃,高手帮忙看看!

[复制链接]

9

主题

16

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
52
发表于 2012-10-13 10:33:00 | 显示全部楼层 |阅读模式
请高手帮忙看看,为什么这段代码运行过程中,cad内存一直增加,一直到崩溃?
  1. Dim doc As Document = Autodesk..ApplicationServices.Application.DocumentManager.MdiActiveDocument
  2.         Dim db As Database = doc.Database
  3.         Dim ed As Editor = doc.Editor        '在交点周围选着点
  4.         Dim i As Integer = 0
  5.         For i = 0 To IDian_Num
  6.             Dim IPinFenNum As Integer = 8
  7.             For j As Integer = 0 To IPinFenNum - 1
  8.                 Dim acPoint3d As Point3d = New Point3d(IntersectPointX(i) + 2 * System.Math.Cos(j * 3.14 * 2 / IPinFenNum), IntersectPointY(i) + 2 * System.Math.Cos(j * 3.14 * 2 / IPinFenNum), 0)
  9.                 Dim Pt3dCOLL As New Point3dCollection
  10.                 Dim Ldis As Double = 20
  11.                 Dim acPoint3d1 As Point3d = New Point3d(acPoint3d.X - Ldis, acPoint3d.Y + Ldis, 0)
  12.                 Dim acPoint3d2 As Point3d = New Point3d(acPoint3d.X + Ldis, acPoint3d.Y + Ldis, 0)
  13.                 Dim acPoint3d3 As Point3d = New Point3d(acPoint3d.X + Ldis, acPoint3d.Y - Ldis, 0)
  14.                 Dim acPoint3d4 As Point3d = New Point3d(acPoint3d.X - Ldis, acPoint3d.Y - Ldis, 0)
  15.                 Pt3dCOLL.Add(acPoint3d1)
  16.                 Pt3dCOLL.Add(acPoint3d2)
  17.                 Pt3dCOLL.Add(acPoint3d3)
  18.                 Pt3dCOLL.Add(acPoint3d4)
  19.                 '获取创建边界的对象集合
  20.                 Dim objs As DBObjectCollection = ed.TraceBoundary(acPoint3d, False)
  21.                 If objs.Count > 0 Then
  22.                     Dim tr As Transaction = doc.TransactionManager.StartTransaction()
  23.                     Using doc.LockDocument
  24.                         Using tr
  25.                             '我们将对象添加到模型空间
  26.                             Dim bt As BlockTable = DirectCast(tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead), BlockTable)
  27.                             Dim btr As BlockTableRecord = DirectCast(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)
  28.                             '将每个边界对象添加到块记录中,其ObjectId集合到ids集合
  29.                             Dim ids As New ObjectIdCollection()
  30.                             '' 定义对象数组中   Adds the circle to an object array
  31.                             Dim acDBObjColl As DBObjectCollection = New DBObjectCollection()                            For Each obj As DBObject In objs
  32.                                 Dim ent As Entity = TryCast(obj, Entity)
  33.                                 If ent IsNot Nothing Then
  34.                                     acDBObjColl.Add(ent)
  35.                                     ids.Add(btr.AppendEntity(ent))
  36.                                     tr.AddNewlyCreatedDBObject(ent, True)
  37.                                 End If
  38.                             Next                            ''创建一个面域对象
  39.                             Dim myRegionColl As DBObjectCollection = New DBObjectCollection()
  40.                             myRegionColl = Autodesk.AutoCAD.DatabaseServices.Region.CreateFromCurves(acDBObjColl)
  41.                             Dim acRegion As Region
  42.                             acRegion = myRegionColl(0)
  43.                             '' 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction
  44.                             btr.AppendEntity(acRegion)
  45.                             tr.AddNewlyCreatedDBObject(acRegion, True)
  46.                             '提交事务
  47.                             tr.Commit()
  48.                         End Using
  49.                     End Using
  50.                 End If
  51.             Next
  52.         Next

回复

使用道具 举报

10

主题

45

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2012-10-13 10:54:00 | 显示全部楼层

将using tr 放在锁文档内部试试。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-6-29 14:47 , Processed in 0.857058 second(s), 57 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表