.NET

Reply
*Rinze
Message 1 of 23 (660 Views)

eLockViolation

660 Views, 22 Replies
05-18-2009 07:50 AM
Hi all,

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
Try
Dim btr As BlockTableRecord = CType(myT.GetObject(destDB.CurrentSpaceId, OpenMode.ForWrite, True), BlockTableRecord) ' <--- this throws the exception
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

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.

Rinze
Mentor
MarkPendergraft
Posts: 385
Registered: ‎06-27-2005
Message 2 of 23 (660 Views)

Re: eLockViolation

05-18-2009 08:52 AM in reply to: *Rinze
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.
*Rinze
Message 3 of 23 (660 Views)

Re: eLockViolation

05-19-2009 04:34 AM in reply to: *Rinze
MarkPendergraft wrote:
> 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.

Rinze
*Rinze
Message 4 of 23 (660 Views)

Re: eLockViolation

05-19-2009 05:36 AM in reply to: *Rinze
Rinze wrote:
> 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.

Rinze
Mentor
MarkPendergraft
Posts: 385
Registered: ‎06-27-2005
Message 5 of 23 (660 Views)

Re: eLockViolation

05-19-2009 08:05 AM in reply to: *Rinze
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.

-Mark
*Expert Elite*
arcticad
Posts: 1,286
Registered: ‎06-21-2004
Message 6 of 23 (660 Views)

Re: eLockViolation

05-19-2009 10:16 AM in reply to: *Rinze
You can try to set the focus back to Autocad.

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)
End Sub
---------------------------



(defun botsbuildbots() (botsbuildbots))
Distinguished Contributor
mohnston
Posts: 184
Registered: ‎09-22-2006
Message 7 of 23 (660 Views)

Re: eLockViolation

05-19-2009 11:30 AM in reply to: *Rinze
You could try
Autodesk.AutoCAD.Internal.Utils.GraphScr()

You will need to add a reference to the acmgdinternal dll.
CAD Programming Solutions
Distinguished Contributor
BillZndl
Posts: 393
Registered: ‎09-23-2008
Message 8 of 23 (660 Views)

Re: eLockViolation

05-19-2009 12:10 PM in reply to: *Rinze
Not sure what version you're using but Paletteutils.CS helped me on version 2006 Autocad.

You can use PaletteUtils.ActivateEditor(); to put focus to the Autocad screen.

Here's a link to how to use it in VB.net

http://discussion.autodesk.com/forums/thread.jspa?threadID=728268&tstart=25

HTH

Bill
*Expert Elite*
arcticad
Posts: 1,286
Registered: ‎06-21-2004
Message 9 of 23 (660 Views)

Re: eLockViolation

05-19-2009 03:24 PM in reply to: *Rinze
http://www.caddzone.com/PaletteUtils.cs
---------------------------



(defun botsbuildbots() (botsbuildbots))
*Rinze
Message 10 of 23 (660 Views)

Re: eLockViolation

05-20-2009 01:13 AM in reply to: *Rinze
mohnston wrote:
> You could try Autodesk.AutoCAD.Internal.Utils.GraphScr() You will need
> to add a reference to the acmgdinternal dll.

I'm not sure what I'm supposed to do with that. I added that command just before the input and it doesn't seem to do anything.

Rinze
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.