Author Topic: Responding to the Properties Palette  (Read 3107 times)

0 Members and 1 Guest are viewing this topic.

MRWEBBER

  • Guest
Responding to the Properties Palette
« on: November 04, 2011, 12:35:02 PM »
Hi all,

Its my first post so go easy on me  :-o

I am writing in the process of writing a AutoCAD/Civil3D plug-in (in VB.Net) product that needs current detects all of the updates (modified, erased , Unmodified, etc) on my own Entities and then only act on these once. So to this end I am maintaining a list of the affect entities and then processing the 'queue' on
Code: [Select]
Document.CommandEnded.
This worked perfectly for me until I realised that the Properties Palette (and probably others) do not actually perform a command so the command end event is never caught. Obviously the queue will be processed on the next command but it looks sloppy that my data is not updated straight away.

I have seen various blog posts and a similar post on here that suggest using
Code: [Select]
DocumentManager.DocumentLockModeWillChange or
Code: [Select]
Editor.EnteringQuiescentState as the event to detect the end of the edit. However I am finding that no matter which of there I use I am unable to apply my Document Lock and this leads to Access Violations no matter what checks I do passed on the EventArgs.

I believe I have all the right Document locks in place, all in Using Statements so they should be disposed of correctly.

Can anyone point me in the right direction or correct the error of my ways?

Many Thanks!

Mat

MRWEBBER

  • Guest
Re: Responding to the Properties Palette
« Reply #1 on: November 14, 2011, 06:06:44 AM »
BUMP

Does anyone have any thoughts on this one?

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Responding to the Properties Palette
« Reply #2 on: November 14, 2011, 06:38:30 PM »
I am not sure what year but you say your 'own' entites.
 
If you have them marked with a extension dictionary or keep up with ObjectIds you could have a overrule that will filter for them and update through the overrule

MRWEBBER

  • Guest
Re: Responding to the Properties Palette
« Reply #3 on: November 16, 2011, 04:57:49 AM »
Thanks Jeff,

By 'own' entities I mean standard lines/polylines/circle etc that I have appended my data to in their Extension dictionaries as you suggest. Each of these has event handlers hooked up to deal capture the changes and store the objectId of the entities that are changed/erased etc. I then process this queue on CommandEnded using the mapping to the ObjectIds i have.

If I am honest I am not sure what you mean by an 'Overule'?

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Responding to the Properties Palette
« Reply #4 on: November 16, 2011, 07:43:53 AM »
Quote
ObjectARX®  provides interfaces where you can overrule at runtime, or modify, default behavior of a target class derived from AcDbEntity, AcDbObject, or AcGiDrawable, without the overhead of implementing a custom entity.
The base overrule functionality is provided by AcRxOverrule. Specialized overrule classes are derived for modifying behavior implemented in the following function types:
  • Grip point
  • Snap
  • Subentity
  • Transform
  • Geometry
  • Visibility
  • Object properties
  • Certain AcDbObject
  • Draw
The default behavior of the listed overrule functions is to call the function being overruled, without modification. To modify the default behavior, derive from one of the specialized overrule classes and override the corresponding virtual functions defined by that overrule class.
The overruled behavior is then invoked for a target class at runtime when the following conditions are met:
  • The application-wide overrule switch is turned on.
  • A corresponding overrule has been registered for the target class.
  Topics in this section

If you have access to AU online
 
http://au.autodesk.com/?nd=class&session_id=7560
 
 
At Through the Interface
http://through-the-interface.typepad.com/through_the_interface/
 
There are a number of post and a quick way would be to click on overrules on side bar and a pic to better explain.
 

MRWEBBER

  • Guest
Re: Responding to the Properties Palette
« Reply #5 on: November 18, 2011, 07:54:25 AM »
Hi Jeff,

Thanks for that, I have had a good read up on Kean's blog (i had missed those topics) and the other links. I was at AU 2010 and I picked up lots of other good stuff, but that was a class i missed. From reading and experimenting I now have a good understanding of Overrules and what they can do for me. I am sure they will come in handy for many other things I want to do later.

However I still not sure how 'overrules' could be used to achieve what I am after, there does not appear to be any overule that relates to data being changed specifically by the properties box. I am quite happy tracking changes via events, it is just the cases where no CommandEnded is thrown that breaks my approach.

Thanks

LE3

  • Guest
Re: Responding to the Properties Palette
« Reply #6 on: November 18, 2011, 12:18:56 PM »
BUMP

Does anyone have any thoughts on this one?

I think you are out of luck on this, as you have find out so far...

The only way I was able to capture anything from the props palette was with my own custom objects and by wrapping it - apart of that....

Maybe, if you find information from Master/Guru Tony Tanzillo about palettes he might did something.... (paletteUtils.cs if i recall) - maybe.

0.02cts.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Responding to the Properties Palette
« Reply #7 on: November 18, 2011, 12:45:54 PM »
Hi Jeff,

Thanks for that, I have had a good read up on Kean's blog (i had missed those topics) and the other links. I was at AU 2010 and I picked up lots of other good stuff, but that was a class i missed. From reading and experimenting I now have a good understanding of Overrules and what they can do for me. I am sure they will come in handy for many other things I want to do later.

However I still not sure how 'overrules' could be used to achieve what I am after, there does not appear to be any overule that relates to data being changed specifically by the properties box. I am quite happy tracking changes via events, it is just the cases where no CommandEnded is thrown that breaks my approach.

Thanks

It was a thought and do not know the details of your application but was pointing out maybe with
For filtering:
Overrule.SetIdFilter
Overrule.SetExtensionDictionaryEntryFilter
 
And for updating:
ObjectOverrule.Erase
ObjectOverrule.Open
ObjectOverrule.Close
DrawableOverrule.WorldDraw
 
Just thought I would throw it out there that it might be a option to handle changes.
 
 
 

LE3

  • Guest
Re: Responding to the Properties Palette
« Reply #8 on: November 18, 2011, 01:31:14 PM »
Quote
ObjectOverrule.Open
ObjectOverrule.Close

If those two are the same as subOpen() and subClose() as what you can use inside of a custom object - but you also have to do a comwrapper inorder to capture your own stuff for your custom object inside of the properties palette...

Never did anything about overrule... so, can't comment on this.

MRWEBBER

  • Guest
Re: Responding to the Properties Palette
« Reply #9 on: November 21, 2011, 08:23:07 AM »
Thanks again for your input, I do apprechiate you guys taking the time to answer me.

I suspect though that I was not as clear as I could be on what the problem is. Maybe some code would help out here to highlight where I am? I have added some code below below that shows my basic setup, obviously my creation of data is a bit more involved and data is appended as XRecords but it demostrates the problem. If you move with the cursor the line (after running DrawData) you will see the two messages (Entity Modified & Command Ended), however Properties Palette changes will only give the 'Entity Modified' message as the commanded ended in not thrown.

Code: [Select]
Public Class App
    Implements Autodesk.AutoCAD.Runtime.IExtensionApplication

    ''' <summary>
    ''' Start app
    ''' </summary>
    Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
        'For now we will Greet the user
        ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine + "Welcome to My Test App!" + vbNewLine)

        'Add handler for CommandEnded
        AddHandler ApplicationServices.Application.DocumentManager.MdiActiveDocument.CommandEnded, AddressOf CommandEnded

    End Sub

    ''' <summary>
    ''' End App
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
        'Do something....
    End Sub

    ''' <summary>
    ''' Entity has been modified
    ''' </summary>
    Public Sub EntityModified(ByVal senderObj As Object, ByVal evtArgs As EventArgs)

        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine + "Entity Changed" + vbNewLine)

        'Store the Entity ID

    End Sub

    ''' <summary>
    ''' Command Has Ended
    ''' </summary>
    Public Sub CommandEnded(sender As Object, e As CommandEventArgs)

        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(vbNewLine + "Command Ended" + vbNewLine)

        'Process the list of Entity IDs

    End Sub

    ''' <summary>
    ''' Draw my data and add handlers
    ''' </summary>
    <CommandMethod("DrawData")> _
    Public Sub DrawData()

        Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim l As Line

        'Lock the document and start a new transation
        Using dl As DocumentLock = acDoc.LockDocument()
            Using myTrans As Transaction = acDoc.TransactionManager.StartTransaction()
                ' Open Model space for write
                Using acBlkTbl As BlockTable = CType(myTrans.GetObject(acDoc.Database.BlockTableId, OpenMode.ForRead), BlockTable)
                    Using acBlkTblRec As BlockTableRecord = CType(myTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite), BlockTableRecord)

                        'Draw the entities in loop (for example)

                        'Just adding a single line here
                        l = New Line(New Geometry.Point3d(1, 1, 0), New Geometry.Point3d(100, 100, 0))

                        'Assign to the layer zero
                        l.LayerId = acDoc.Database.LayerZero

                        'Add handlers (only one added in demo)
                        AddHandler l.Modified, AddressOf EntityModified

                        acBlkTblRec.AppendEntity(l)
                        myTrans.AddNewlyCreatedDBObject(l, True)

                        myTrans.Commit()

                    End Using
                End Using
            End Using
        End Using

    End Sub

End Class

As you can see the events are all hooked up so I know exactly what changes are happening and I store these. I then process these chanegs at once in the CommandEnded event handler. However This is NOT thrown when a change is made on the properties box so this is where my code falls down.

What I need to find is another event to handle other than command ended (DocumentManager.DocumentLockModeWillChange & Editor.EnteringQuiescentState are not working for me either). Or some way of telling that an change occur as a result of the Properties box (i.e. not part of a command).

Does that help?