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

Change Active Layer in AutoCAD 2007

4 REPLIES 4
Reply
Message 1 of 5
bob4963
771 Views, 4 Replies

Change Active Layer in AutoCAD 2007

I'm using VB.net 2005 and AutoCAD 2007. I have seen a lot of suggestions but none of them work. Does anyone know how to change the active layer to a layer that already exist? Please don't just give me a line of code without saying what namespaces are needed.

Thanks,
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: bob4963

< I have seen a lot of suggestions but none of them work.
What doesn't work? Post what your're trying and we'll help out.

wrote in message news:5714229@discussion.autodesk.com...
I'm using VB.net 2005 and AutoCAD 2007. I have seen a lot of suggestions but none of them work. Does anyone know how to change
the active layer to a layer that already exist? Please don't just give me a line of code without saying what namespaces are
needed.

Thanks,
Message 3 of 5
bob4963
in reply to: bob4963

I figured it out.

Thanks
Message 4 of 5
Anonymous
in reply to: bob4963

I hope that this can help you

Shared Function ActivateLayer(ByVal LayerID As AcDb.ObjectId) As
AcDb.ObjectId
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
Try
Dim tbl As AcDb.LayerTable = _
DirectCast(tr.GetObject(db.LayerTableId,
AcDb.OpenMode.ForRead, False), AcDb.LayerTable)
If tbl.Has(LayerID) Then
db.Clayer = LayerID
tr.Commit()
Else
tp.Utils.GetEditor.WriteMessage(vbLf & "Layer not
exists")
End If
Catch ex As Exception
tr.Abort()
End Try
End Using
End Using
Return LayerID
End Function

Shared Function ActivateLayer(ByVal LayerName As String) As
AcDb.ObjectId
Dim id As AcDb.ObjectId = LayerNameToId(LayerName)
If Not id = Nothing Then
Return tp.Layers.ActivateLayer(id)
End If
Return Nothing
End Function

Shared Function LayerNameToId(ByVal LayerName As String) As
AcDb.ObjectId
Dim tbl As AcDb.LayerTable = GetLayerTableForRead
If tbl.Has(LayerName) Then
Return tbl.Item(LayerName)
End If
Return Nothing
End Function

Shared Function GetLayerTableForRead() As AcDb.LayerTable
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
Try
Return DirectCast(tr.GetObject(db.LayerTableId,
AcDb.OpenMode.ForRead, False), AcDb.LayerTable)
Catch ex As Exception
End Try
End Using
End Using
Return Nothing
End Function

tp


escreveu na mensagem news:5714229@discussion.autodesk.com...
I'm using VB.net 2005 and AutoCAD 2007. I have seen a lot of suggestions
but none of them work. Does anyone know how to change the active layer to a
layer that already exist? Please don't just give me a line of code without
saying what namespaces are needed.

Thanks,
Message 5 of 5
Anonymous
in reply to: bob4963

Change this line
tp.Utils.GetEditor.WriteMessage(vbLf & "Layer not exists")
for this
AcAp.Application.DocumentManager.MdiActiveDocument.Editor

tp

escreveu na mensagem news:5714229@discussion.autodesk.com...
I'm using VB.net 2005 and AutoCAD 2007. I have seen a lot of suggestions
but none of them work. Does anyone know how to change the active layer to a
layer that already exist? Please don't just give me a line of code without
saying what namespaces are needed.

Thanks,

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