.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update attribute based on event

0 REPLIES 0
Reply
Message 1 of 1
Anonymous
297 Views, 0 Replies

Update attribute based on event

    Private Sub callback_commandWillStart(ByVal sender As Object, ByVal e As CommandEventArgs)
        If e.GlobalCommandName = "EATTEDIT" Then
            MsgBox("hey")
            Return
        ElseIf e.GlobalCommandName = "POWEREDITINAPP" Then
            AddHandler myDB.ObjectModified, AddressOf callback_ObjectModified
            AddHandler myDoc.CommandEnded, AddressOf callback_CommandEnded
        End If
    End Sub
    Private Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs)
        Dim trans As Transaction = e.DBObject.Database.TransactionManager.StartTransaction

        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)
                    Dim BTR As BlockTableRecord = myBlockRef.BlockTableRecord.GetObject(OpenMode.ForRead)
                    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 myDWG As Document = DocumentManager.MdiActiveDocument
            Dim objid As ObjectId
            Try

                Using trans As Transaction = myDWG.TransactionManager.StartTransaction
                    For Each objid In IDList
                        Dim myent As Entity = objid.GetObject(OpenMode.ForRead)
                        Dim myBlockRef As DatabaseServices.BlockReference = objid.GetObject(OpenMode.ForRead)
                        Dim myattcoll As DatabaseServices.AttributeCollection = myBlockRef.AttributeCollection
                        Dim myAttent As DatabaseServices.ObjectId
                        Dim myAttRef As AttributeReference
                        For Each myAttent In myattcoll
                            myAttRef = myAttent.GetObject(OpenMode.ForRead)
                            Debug.Print(myAttRef.Tag)
                        Next
                        Debug.Print(myent.Layer)
                        Debug.Print(objid.ToString)
                        'MsgBox(e.GetType.ToString)
                    Next
                    IDList.Clear()
                End Using
            Catch ex As Exception

            End Try
        End If

    End Sub

 

Hey All

I'm trying to write a program that updates a block attribute based on the change of another attribute. The code I've got so far seams to work as far as printing to the immediate window but whenever I try to open anything for write I get an exception.

 

Here is the code I've got so far.

Tags (1)
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report