乐筑天下

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

.IsDynamicBlock 返回 false ?

[复制链接]

5

主题

27

帖子

12

银币

初来乍到

Rank: 1

铜币
36
发表于 2013-9-4 02:24:51 | 显示全部楼层
我假设下面的代码示例的工作方式与WILL HATCH建议的相同?
(它涉及通过一个参数传递“活动”事务)
  1. Function main()
  2. ...
  3. Using Transaction tr = db.TransactionManager.StartTransaction()
  4. Dim DbObjectCollection blocks = get_blocks(db, tr)
  5. sort_blocks(blocks)
  6. ...
  7. End Using
  8. End Function
  9. Function get_Blocks(db As Database, tr as Transaction) As DbObjectCollection
  10. If tr == null Then throw new ArgumentNullException( "Function called outside the scope of transaction" )
  11. ...get blocks
  12. End Function

话又说回来,熟练使用事务通过参数接收事务的每个方法可能不是那么可取的。
*编辑*
使用事务 tr = db。TransactionManager.StartTransaction()
我显然说:
Dim Transaction tr = db。TransactionManager.TopTransaction
*/EDIT*
看起来更容易接受
回复

使用道具 举报

5

主题

27

帖子

12

银币

初来乍到

Rank: 1

铜币
36
发表于 2013-9-4 03:45:10 | 显示全部楼层
首先
欢迎来到沼泽伯特
您使用的是垂直命令吗?因为我记得Will使用的是MEP或其他不同的命令,但他发现它会为每个自定义命令创建一个事务
此外,任何需要或希望使用事务的方法都不需要传递事务
如果您后退一步查看,AutoCAD将执行您的代码的入口点只有这么多。
-初始化
-命令
—事件
-,否决
,等等,
并可以更改需要处理的方式
如果不注意使用嵌套或大量事务,则只能部分更改数据
需要休息一下,但当更好地了解需求时,有人可以帮助重构代码,以及如何在一个事务中封装方法。
回复

使用道具 举报

5

主题

27

帖子

12

银币

初来乍到

Rank: 1

铜币
36
发表于 2013-9-4 09:44:11 | 显示全部楼层
感谢杰夫的欢迎!
你用我用“垂直”是什么意思?
如前所述,我的代码确实早就应该进行一些重构了。
我听从了WILL HATCH的建议,将所有操作都保留在1笔交易中。
这花了一些工作,但结果如下:
  1. Sub Main()
  2.         ' Get the current document and database
  3.         Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  4.         Dim acCurDb As Database = acDoc.Database
  5.         ' Lock the document
  6.         Using acLckDoc As DocumentLock = acDoc.LockDocument()
  7.             ' Start a transaction
  8.             Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
  9.                
  10.                 Call function1()
  11.                 dim obj as DbObject = function2()
  12.                 If TypeOf (obj) Is BlockReference Then
  13.                       Call function3(obj)
  14.                 end if
  15.                 ' Save the changes
  16.                 acTrans.Commit()
  17.             End Using ' Transaction
  18.         End Using ' Lock
  19. End Sub
  20. Function method1()
  21.         ' Get the current document and database
  22.         Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  23.         Dim acCurDb As Database = acDoc.Database
  24.         Dim acTrans As Transaction = db.TransactionManager.TopTransaction
  25.         Dim blkTable As BlockTable = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
  26.         If blkTable.Has(_blockName) Then
  27.             ......
  28.         End If
  29. End Function
  30. Function method2() as DBObject
  31.         ' Get the current document and database
  32.         Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  33.         Dim acCurDb As Database = acDoc.Database
  34.         Dim acTrans As Transaction = db.TransactionManager.TopTransaction
  35.         Dim pPtOpts As PromptEntityOptions = New PromptEntityOptions("")
  36.         ' Prompt for the start point
  37.         pPtOpts.Message = vbLf & _prompt
  38.         pPtOpts.AllowNone = False
  39.         Dim pPtRes As PromptEntityResult = acDoc.Editor.GetEntity(pPtOpts)
  40.         ' Exit if the user presses ESC or cancels the command
  41.         If pPtRes.Status = PromptStatus.Cancel Then Return Nothing
  42.         Return acTrans.GetObject(pPtRes.ObjectId, OpenMode.ForRead)
  43. End Function
  44. sub method3(_blkRef as BlockReference)
  45.        ' Get the current document and database
  46.         Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
  47.         Dim acCurDb As Database = acDoc.Database
  48.         Dim acTrans As Transaction = db.TransactionManager.TopTransaction
  49.         Dim attCol As AttributeCollection = _blkRef.AttributeCollection
  50.         For Each attId As ObjectId In attCol
  51.              Dim attRef As AttributeReference = DirectCast(acTrans.GetObject(attId, OpenMode.ForWrite), AttributeReference)
  52.              Dim recievedValue As String = get_AttVal(attRef.Tag, _attVals)
  53.              If Not String.IsNullOrEmpty(recievedValue) Then attRef.TextString = recievedValue
  54.         Next
  55. End sub

目前我遇到了与管理大量事务,管理单个事务完全相反的麻烦:
我正在左右回避以下错误:
“由于对象的当前状态,操作无效。
我有代码想要在同一事务的早期打开ForRead的对象上Allready已经准备好打开ForRead/Write。
也许我正在使这种方式变得复杂?
回复

使用道具 举报

4

主题

219

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
238
发表于 2013-9-4 10:25:12 | 显示全部楼层
通过垂直,我的意思是
Civil3D,Autocad Arch,AutoCAD MEP等。添加到 AutoCAD 或扩展 AutoCAD 的产品。

必须找到一份工作,但稍后会发布一些东西,或者其他人会发布更好的东西。
回复

使用道具 举报

4

主题

219

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
238
发表于 2013-9-4 10:35:58 | 显示全部楼层
不,我是在100%纯AutoCAD背景下编写.NET的
替换我在过去5年为我工作的公司编写的400页VBA代码。(不要问)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-2-5 07:54 , Processed in 0.249648 second(s), 71 queries .

© 2020-2025 乐筑天下

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