打印本文 打印本文 关闭窗口 关闭窗口
Autodesk官方最新的.NET教程(七)(vb.net版)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3070  更新时间:2009/4/23 19:00:03  文章录入:mintao  责任编辑:mintao
                            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]  下一页

打印本文 打印本文 关闭窗口 关闭窗口