employeePositions.Add(att.Position) Next End If End If End If End If trans.Commit() Finally trans.Dispose() End Try End Sub 第4步 创建第二个文档事件处理函数(回调函数) 当一个命令结束时,第三个事件处理函数被调用。同样地,我们要检查全局变量来验证这个将要结束的命令是我们监视的命令。如果是我们监视的,那么我们要重置这个变量: If bEditCommand = False Then Return End If bEditCommand = False 这个回调函数执行的动作将会再次触发ObjectOpenedForModify事件。我们必须确定在这个回调函数中跳过了所有与此事件有关的动作。 ''''设置标志来跳过OpenedForModify处理函数 bDoRepositioning = True 这个回调函数的剩余代码用来把EMPLOYEE块索引和它的关联属性引用的当前(修改过的)位置与它们的初始位置作比较。如果位置改变了,我们在这个回调函数中把它们重置这初始的位置。下面的代码可以被粘贴到这个事件处理函数中。 Public Sub cmdEnded(ByVal o As Object, ByVal e As CommandEventArgs) ''''Was our monitored command active? If bEditCommand = False Then Return End If bEditCommand = False ''''Set flag to bypass ObjectOpenedForModify handler bDoRepositioning = True Dim db As Database = HostApplicationServices.WorkingDatabase Dim trans As Transaction Dim bt As BlockTable Dim oldpos As Point3d Dim newpos As Point3d Dim i As Integer Dim j As Integer = 1 For i = 0 To changedObjects.Count - 1 trans = db.TransactionManager.StartTransaction() Try bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) Dim ent As Entity = CType(trans.GetObject(changedObjects.Item(i), OpenMode.ForWrite), Entity) If TypeOf ent Is BlockReference Then ''''We use .NET''''s RTTI to establish type. Dim br As BlockReference = CType(ent, BlockReference) newpos = br.Position oldpos = employeePositions.Item(i) ''''Reset blockref position If Not oldpos.Equals(newpos) Then trans.GetObject(br.ObjectId, OpenMode.ForWrite) br.Position = oldpos End If ElseIf TypeOf ent Is AttributeReference Then Dim att As AttributeReference = CType(ent, AttributeReference) newpos = att.Position oldpos = employeePositions.Item(i) ''''Reset attref position 上一页 [1] [2] [3] [4] 下一页 [C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体 [VB.NET程序]在托盘上显示Balloon Tooltip(VB.NET) [VB.NET程序]Henry手记-VB.NET中动态加载Treeview节点(二)
|