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

open the LayerTable for write Event trigger from UserControl butten

4 REPLIES 4
Reply
Message 1 of 5
Danny.isr
382 Views, 4 Replies

open the LayerTable for write Event trigger from UserControl butten

hello all, i'm trying to open the LayerTable for write,and i get
this error: "eLockViolation"
when i'm calling the function within Event trigger from UserControl butten that is assign ToolPalette

if i use the same function directly from the command line it works good .
i would like to hear some suggestion . thank you, danny Edited by: Danny.isr on Nov 30, 2008 10:38 PM
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Danny.isr


Without seeing your code, it is difficult to have
any meaningful suggestion. With that said, looking at "DocumentLock" may help
you.


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
hello
all, i'm trying to open the LayerTable for write,and i get this error:
"eLockViolation" when i'm calling the function within Event trigger from
UserControl butten that is assign ToolPalette if i use the same function
directly from the command line it works good . i would like to hear some
suggestion . thank you, danny Edited by: Danny.isr on Nov 30, 2008 10:38
PM
Message 3 of 5
Danny.isr
in reply to: Danny.isr

UserControl butten that is assign to ToolPalette

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.RadioButton1.Checked Then
SetActiveLayer("Layer5")
End If
End Sub

Module Module1
Public Sub SetActiveLayer(ByVal LayerName As String, Optional ByVal Fleg As Boolean = True)
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Autodesk.AutoCAD.EditorInput.Editor
ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
Dim tm As Autodesk.AutoCAD.DatabaseServices.TransactionManager = db.TransactionManager
Dim tr As Autodesk.AutoCAD.DatabaseServices.Transaction = tm.StartTransaction
Try
Dim tbl As LayerTable = _
CType(tr.GetObject(db.LayerTableId, OpenMode.ForRead), LayerTable)
If tbl.Has(LayerName) Then
db.Clayer = tbl.Item(LayerName)
tr.Commit()
Else
If Fleg Then
Dim NewLayer As LayerTableRecord = AddNewLayer(LayerName)
tbl.UpgradeOpen()
tbl.Add(NewLayer)
tm.AddNewlyCreatedDBObject(NewLayer, True)
tr.Commit()
'db.Clayer = tbl.Item(LayerName)
'tr.Commit()
End If
End If

Catch e As System.Exception
ed.WriteMessage(e.Message)
tr.Abort()
Finally
tr.Dispose()
End Try
If Fleg Then
SetActiveLayer(LayerName, False)
End If

End Sub
Private Function AddNewLayer(ByVal LayerName As String) As LayerTableRecord

AddNewLayer = New LayerTableRecord With {.Name = LayerName, .Color = Autodesk.AutoCAD.Colors.Color.FromColor(Drawing.Color.Red), .LineWeight = LineWeight.LineWeight120, .IsPlottable = True, .Description = "Layer test1"}

End Function
End Module

thank you, danny
Message 4 of 5
Danny.isr
in reply to: Danny.isr

tenk you

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.RadioButton1.Checked Then
Dim docLock As DocumentLock = _
Application.DocumentManager.MdiActiveDocument.LockDocument()
SetActiveLayer("Layer5")
docLock.Dispose()End If
End Sub
Message 5 of 5
Anonymous
in reply to: Danny.isr


You have to call the Document's LockDocument()
method,

and once you've finished accessing the database, call
Dispose()

on the result:

 

{code}

 

   Using myLock as DocumentLock =
myDocument.LockDocument()

 

      ' Modify the drawing
here

 

   End Using

 

{code}


 

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

href="http://www.acadxtabs.com">http://www.acadxtabs.com

 


 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
hello
all, i'm trying to open the LayerTable for write,and i get this error:
"eLockViolation" when i'm calling the function within Event trigger from
UserControl butten that is assign ToolPalette if i use the same function
directly from the command line it works good . i would like to hear some
suggestion . thank you, danny Edited by: Danny.isr on Nov 30, 2008 10:38
PM

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