| ‘ ‘''''Delete all stored information ‘ ‘ End If 如果MOVE命令开始执行的话,我们要相应地设置Boolean变量bEditCommand的值,这样我们可以知道我们所监视的命令是活动的。同样地,我们应该把另外一个Boolean变量bDoRepositioning设置为false来忽略ObjectOpenedForModify事件处理函数。两个变量设置好以后,在命令活动期间,我们必须要获得所选块索引的信息。 我们还应该把两个集合对象的内容清空。我们只关心当前选择的对象。 第3步: 创建数据库事件处理函数(回调函数) 无论什么时候一个对象被打开并要被修改时,数据库事件处理函数会被调用。当然,如果这时我们监视的命令不是活动的,我们就应该跳过任何被这个回调函数调用的内容。 If bEditCommand = False Then Return End If 同样地,如果我们监视的命令已经结束,而ObjectOpenedForModify事件被另一个回调函数再次触发的话,而这时有对象被修改时,我们要阻止所有由这个回调函数执行的动作。 If bDoRepositioning = True Then Return End If 这个回调函数剩余部分的代码用来验证我们是否正在处理EMPLOYEE块索引。如果是的话,我们就获取它的ObjectID和位置(三维点)。下面的代码可以被粘贴到这个事件处理函数函数。 Public Sub objOpenedForMod(ByVal o As Object, ByVal e As ObjectEventArgs) If bEditCommand = False Then Return End If If bDoRepositioning = True Then Return End If Dim objId As ObjectId objId = e.DBObject.ObjectId Dim trans As Transaction Dim bt As BlockTable Dim db As Database db = HostApplicationServices.WorkingDatabase trans = db.TransactionManager.StartTransaction() Try ''''Use it to open the current object! Dim ent As Entity = trans.GetObject(objId, OpenMode.ForRead, False) If TypeOf ent Is BlockReference Then ''''We use .NET''''s RTTI to establish type. Dim br As BlockReference = CType(ent, BlockReference) ''''Test whether it is an employee block ''''open its extension dictionary If br.ExtensionDictionary().IsValid Then Dim brExtDict As DBDictionary = trans.GetObject(br.ExtensionDictionary(), OpenMode.ForRead) If brExtDict.GetAt("EmployeeData").IsValid Then ''''successfully got "EmployeeData" so br is employee block ref ''''Store the objectID and the position changedObjects.Add(objId) employeePositions.Add(br.Position) ''''Get the attribute references,if any Dim atts As AttributeCollection atts = br.AttributeCollection If atts.Count > 0 Then Dim attId As ObjectId For Each attId In atts Dim att As AttributeReference att = trans.GetObject(attId, OpenMode.ForRead, False) changedObjects.Add(attId) 上一页 [1] [2] [3] [4] 下一页 |