.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Re: ObjectModi fied event
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
AddHandler myDB.ObjectModified, AddressOf callback_ObjectModified
AddHandler myDoc.CommandEnded, AddressOf callback_CommandEnded
End Using
End Sub
Private Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs)
Dim myBlockRef As BlockReference = e.DBObject.Id.GetObject(OpenMode.ForRead)
Dim BTR As BlockTableRecord = myBlockRef.BlockTableRecord.GetObject(OpenMode.For Read)
MsgBox(myBlockRef.Layer)' & vbCr & BTR.Name)
If Not IDList.Contains(e.DBObject.Id) Then
IDList.Add(e.DBObject.Id)
End If
End Sub
Private Sub callback_CommandEnded(ByVal sender As Object, ByVal e As CommandEventArgs)
If IDList.Count > 0 Then
Dim objid As ObjectId
For Each objid In IDList
MsgBox("aaaaaaahhhhhh")
Next
IDList.Clear()
End If
End SubHere is some of the code (basically copying yours) I'm not sure how to test for the block name and layer of the object I modified. Like I said I'm really new at this and appreciate all your help. I'm still at the point where I have to add these events manually with the netload and commandmethods. I'd be willing to pay you for some phone help if this is to much to accomplish through email.
once again thanks for your time
Dave
Re: ObjectModi fied event
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Private Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs)
Dim trans As Transaction = e.DBObject.Database.TransactionManager.StartTransa ction
Try
Dim obj As Object = trans.GetObject(e.DBObject.Id, OpenMode.ForRead)
If obj.GetType.Name.ToString = "BlockReference" Then
If Not IDList.Contains(e.DBObject.Id) Then
IDList.Add(e.DBObject.Id)
MsgBox(obj.GetType.Name.ToString)
Dim myBlockRef As BlockReference = e.DBObject.Id.GetObject(OpenMode.ForRead)
Dim BTR As BlockTableRecord = myBlockRef.BlockTableRecord.GetObject(OpenMode.For Read)
MsgBox(BTR.Name)
End If
End If
Catch ex As Exception
End Try
trans.Dispose()
End Sub
Private Sub callback_CommandEnded(ByVal sender As Object, ByVal e As CommandEventArgs)
If IDList.Count > 0 Then
Dim objid As ObjectId
For Each objid In IDList
MsgBox(e.GetType.ToString)
Next
IDList.Clear()
End If
End Sub
I got a little farther than earlier but I'm still not sure how to get blockref name in the commandended event
Re: ObjectModi fied event
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Dave,
Sorry for the delay. I am still very new to .NET as well and have not done much with block references. I will look at this and help where I can but you should at least know that I'm not well versed in this language.
That said try using this in your object modified event. Then do the work in command ended event. I don't think you want to try opening the object that called the event.
If e.DBObject.Id.ObjectClass.Name = "AcDbAttribute" Then
IDList.Add(e.DBObject.Id)
End If
Re: ObjectModi fied event
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Then try this in your Command ended event.
For Each ObjID In IDList
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Data
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim Myatt As AttributeReference = trans.GetObject(ObjID, OpenMode.ForRead, False)
MsgBox(Myatt.TextString)
End Using
Next
Re: ObjectModi fied event
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks
I'll try that and get back to you
Re: ObjectModi fied event
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Private Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs)
Dim trans As Transaction = e.DBObject.Database.TransactionManager.StartTransa ction
Try
Dim obj As Object = trans.GetObject(e.DBObject.Id, OpenMode.ForRead)
If obj.GetType.Name.ToString = "BlockReference" Then
If Not IDList.Contains(e.DBObject.Id) Then
IDList.Add(e.DBObject.Id)
Debug.Print(e.DBObject.Id.ToString)
Debug.Print(sender.ToString)
MsgBox(obj.GetType.Name.ToString)
Dim myBlockRef As BlockReference = e.DBObject.Id.GetObject(OpenMode.ForRead)
MsgBox(myBlockRef.ObjectId.ToString)
Dim BTR As BlockTableRecord = myBlockRef.BlockTableRecord.GetObject(OpenMode.For Read)
MsgBox(BTR.Name)
End If
End If
Catch ex As Exception
End Try
trans.Dispose()
End Sub
Private Sub callback_CommandEnded(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim myDwg As Document = DocumentManager.MdiActiveDocument
Dim myDB As Database = ApplicationServices.Application.DocumentManager.Md iActiveDocument.Database
Try
For Each objid In IDList
Using myTrans As Transaction = myDwg.TransactionManager.StartTransaction
Dim myTags As New ArrayList
Dim myStrings As New ArrayList
myTags.Add("FunctionText")
myStrings.Add("This is a test")
SetAttributes(objid, myTags, myStrings)
myTrans.Commit()
End Using
Next
IDList.Clear()
Catch ex As Exception
End Try
RemoveHandler myDB.ObjectModified, AddressOf callback_ObjectModified
RemoveHandler myDoc.CommandEnded, AddressOf callback_CommandEnded
End Sub
Public Sub SetAttributes(ByVal BlockID As ObjectId, ByVal TagList As ArrayList, ByVal StringList As ArrayList)
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDwg As Document
myDwg = Application.DocumentManager.MdiActiveDocument
myTransMan = myDwg.TransactionManager
myTrans = myTransMan.StartTransaction
Dim myBlockRef As BlockReference
Dim myAttColl As AttributeCollection
myBlockRef = BlockID.GetObject(OpenMode.ForWrite, False)
myAttColl = myBlockRef.AttributeCollection
Dim myEnt As ObjectId
Dim myAttRef As AttributeReference
For Each myEnt In myAttColl
myAttRef = myEnt.GetObject(OpenMode.ForWrite, False)
If TagList.Contains(myAttRef.Tag) Then
Dim X As Integer = TagList.BinarySearch(myAttRef.Tag)
If X >= 0 Then
myAttRef.TextString = StringList(X)
End If
End If
Next
myTrans.Commit()
myTrans.Dispose()
myTransMan.Dispose()
End SubSeams like everthing works great until I try to open up the attref for read then I get an exception...any ideas
Thanks
Re: ObjectModi fied event
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Dave,
Sorry I haven't looked at this much. I've been right out straight.
I see several potential problems I think but have not had time to test. It would be helpfult too if you could tell me what it is you're trying to accomplish. Please post any progress you've made and I'll try to look at it later next week.
Bill


