.NET

Reply
Active Member
Danny.isr
Posts: 9
Registered: ‎11-19-2008
Message 1 of 5 (181 Views)

open the LayerTable for write Event trigger from UserControl butten

181 Views, 4 Replies
11-30-2008 01:08 PM
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
*Norman Yuan
Message 2 of 5 (181 Views)

Re: open the LayerTable for write Event trigger from UserControl butten

12-01-2008 09:29 AM 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
Active Member
Danny.isr
Posts: 9
Registered: ‎11-19-2008
Message 3 of 5 (181 Views)

my code

12-01-2008 12:14 PM 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
Active Member
Danny.isr
Posts: 9
Registered: ‎11-19-2008
Message 4 of 5 (181 Views)

Re: open the LayerTable for write Event trigger from UserControl butten

12-01-2008 12:37 PM 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
*Tony Tanzillo
Message 5 of 5 (181 Views)

Re: open the LayerTable for write Event trigger from UserControl butten

12-01-2008 12:37 PM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community