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

eLockViolation

22 REPLIES 22
Reply
Message 1 of 23
Anonymous
2106 Views, 22 Replies

eLockViolation

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
22 REPLIES 22
Message 2 of 23
MarkPendergraft
in reply to: Anonymous

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.
Message 3 of 23
Anonymous
in reply to: Anonymous

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
Message 4 of 23
Anonymous
in reply to: Anonymous

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
Message 5 of 23
MarkPendergraft
in reply to: Anonymous

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
Message 6 of 23
arcticad
in reply to: Anonymous

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))
Message 7 of 23
mohnston
in reply to: Anonymous

You could try
Autodesk.AutoCAD.Internal.Utils.GraphScr()

You will need to add a reference to the acmgdinternal dll.
CAD Programming Solutions
Message 8 of 23
BillZndl
in reply to: Anonymous

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
Message 9 of 23
arcticad
in reply to: Anonymous

http://www.caddzone.com/PaletteUtils.cs
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 10 of 23
Anonymous
in reply to: Anonymous

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
Message 11 of 23
Anonymous
in reply to: Anonymous

BillZndl wrote:
> 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

I'm using AutoCAD 2009, VB 2005 and ObjectARX 2009. I looked at PaletteUtils and converted the ActivateEditor function, but it did not help me 😞

Rinze
Message 12 of 23
Anonymous
in reply to: Anonymous

arcticad wrote:
> http://www.caddzone.com/PaletteUtils.cs

Thanks you. But alas, it did not solve my problem 😞

Rinze
Message 13 of 23
Anonymous
in reply to: Anonymous

I'm getting very frustrated here. It shouldn't be this difficut. I've created a compact vb project with just the basics to
show the problem I'm facing. I've attached it to this message.

If you compile it and netload the DLL you can open the pallet with the command "mytest". If you click on the button you are
prompted for a inputpoint which updates immediately if you move your mouse in the drawing. If you click the image that doesn't
happen. You see the prompt on the commandline, but you have to click inside the drawing first before the input starts updating.

This example doesn't really do anything with the input given, but it's just to show the underlying problem I'm facing.

Normally I would just use buttons with pictures on it, but I need these images to process doubleclicks and singleclicks and
that just doesn't work with buttons.

Rinze
Message 14 of 23
arcticad
in reply to: Anonymous

Same problem in VS 2008.

You know you could always just use a real button and change the flatstlye to flat.

Then add your image.

Problem solved.
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 15 of 23
Anonymous
in reply to: Anonymous

In AutoCAD 2009, add a reference to acmgdinternal.dll,
and then do this just *before* you call GetPoint():

Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()

In AutoCAD 2010, you don't have to add the reference to
acmgdinternal.dll, as it was merged into acmdg.dll.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm


"Rinze" wrote in message news:6186550@discussion.autodesk.com...
arcticad wrote:
> http://www.caddzone.com/...



Message 16 of 23
Anonymous
in reply to: Anonymous

arcticad schreef:
> Same problem in VS 2008. You know you could always just use a real
> button and change the flatstlye to flat. Then add your image. Problem
> solved.

That doesn't solve my problem because I need to distinguish between
single clicks and double clicks. Otherwise I would have used buttons
already 😉

Rinze
Message 17 of 23
Anonymous
in reply to: Anonymous

Tony Tanzillo schreef:
> In AutoCAD 2009, add a reference to acmgdinternal.dll,
> and then do this just *before* you call GetPoint():
>
> Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()
>
> In AutoCAD 2010, you don't have to add the reference to
> acmgdinternal.dll, as it was merged into acmdg.dll.
>

I'll test this as soon as I get back in the office on Monday. For now I
have a long weekend 🙂

Rinze
Message 18 of 23
Anonymous
in reply to: Anonymous

Tony Tanzillo wrote:
> In AutoCAD 2009, add a reference to acmgdinternal.dll,
> and then do this just *before* you call GetPoint():
>
> Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView()
>
> In AutoCAD 2010, you don't have to add the reference to
> acmgdinternal.dll, as it was merged into acmdg.dll.
>

Unfortunately this didn't work either 😞

Rinze
Message 19 of 23
Anonymous
in reply to: Anonymous

Rinze wrote:
> I'm getting very frustrated here.

Alright I have it fixed so I'm putting it up for future reference. It seems all I needed to do was disable my pallet while the point was being picked.
i.e. myPallet.enabled = False. It's weird that hiding the palletset where this pallet was put on didn't work, but just disabling the pallet itself does.

Rinze
Message 20 of 23
Anonymous
in reply to: Anonymous

Give this a try.

Joe ...


_
Public Sub test()

'get the editor object for the current document
Dim ed As Editor = oAcadApp.DocumentManager.MdiActiveDocument.Editor

'get the working database
Dim dwg As Database = ed.Document.Database

'start a transaction
Using ta As Transaction = dwg.TransactionManager.StartTransaction

Try

'get the current drawing space block table record
Dim btr As BlockTableRecord = ta.GetObject(dwg.CurrentSpaceId,
OpenMode.ForWrite, 0, 0)

Catch ex As Exception

'otherwise, tell the user about an error
ed.WriteMessage("A problem occurred because " + ex.Message)

End Try

End Using

End Sub




"Rinze" wrote in message news:6185241@discussion.autodesk.com...
Hi all,

I'm running into a problem. I've ...































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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost