I'm running into a problem. I've created a pallet for my program and I'll be needing to insert blocks from that pallet.
Now I've nailed down the inserting of the blocks etc. But only of I do it by issuing a command from the commandline. If I call
that same procedure from my pallet an exception is thrown "eLockViolation".
Now I've boiled it down to this (removed everything except that which was needed):
Public Sub test()
Dim destDB As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = destDB.TransactionManager
Dim myT As Transaction = tm.StartTransaction
Dim btr As BlockTableRecord = CType(myT.GetObject(destDB.CurrentSpaceId, OpenMode.ForWrite, True), BlockTableRecord) ' <--- this throws the exception
Catch ex As Exception
Giving the command "mytest" from the command line gives no errors. Clicking the button that calls the same sub
throws the exception. What am I doing wrong here? I get the feeling the activedocument is not actually active or
something to that extend.
> try locking the document before you open the transaction dim docLock as
> documentLock =
> Application.DocumentManager.MdiActiveDocument.LockDocument() then, when
> your code is done executing call the dispose method of the documentLock
> variable docLock.dispose() -Mark P.
Thanks, that seems to work. But (there's always a but isn't there) I have to click in
my drawing before my jig shows up. Hovering over a line also doesn't highlight it before
I click in the drawing first. That's a bit of a nuisance. Is there a way to put the focus
on the document? I looked for methods like bringToFront, Select, Focus, SetFocus on the
MdiActiveDocument but it doesn't seem to be there.
> Thanks, that seems to work. But (there's always a but isn't there) I have to click in
> my drawing before my jig shows up. Hovering over a line also doesn't highlight it before
> I click in the drawing first. That's a bit of a nuisance. Is there a way to put the focus
> on the document? I looked for methods like bringToFront, Select, Focus, SetFocus on the
> MdiActiveDocument but it doesn't seem to be there.
Further investigation shows me that I seem to have a problem with pictureboxes vs buttons.
My pallet shows previews of the blocks to insert. I show these previews in a pictureboxes.
When I click a picturebox the click event of the picture box fires off the insert routine.
The activewindow doesn't seem to get the focus (even though I hide my palletset for a moment).
When the button is clicked, it works as I want and the document gets the focus immediately.
I even set it up so the picturebox click event is handled by the same sub as the buttonclick.
What am I missing? Why does it even matter that it's a picturebox being clicked and not a button.
The eventhandler for the click has only 1 line and that's the insert function I wrote.
A button control can contain an image (at least in .NET 3.5 and VS 2008)
i'm totally guessing at this next part here: i suspect that the control acts differently because it's not designed to take focus in the same way buttons and text boxes are. I couldn't find a tabstop or tabindex property. I'm guessing that the control retains focus even while you're in autocad trying to pick your insertion point.
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SetActiveWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Sub SetAcadFocus()
Dim AcadHandle As Long
Dim WindowReturn As Long
AcadHandle = FindWindow(vbNullString, Application.AcadApplication.Caption)
WindowReturn = SetActiveWindow(AcadHandle)