This can help you?
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Public Class Class1
_
Public Sub SwapLayers()
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
Dim opt As New PromptEntityOptions(vbLf & "Select first Entity: ")
opt.SetRejectMessage("" & Microsoft.VisualBasic.Chr(10) & "Entity
may
be selected.")
opt.AddAllowedClass(GetType(Circle), True)
Dim res As PromptEntityResult = ed.GetEntity(opt)
If res.Status <> PromptStatus.OK Then Exit Sub
Dim id As ObjectId = res.ObjectId
opt.Message = vbLf & "Select second Entity: "
res = ed.GetEntity(opt)
If res.Status <> PromptStatus.OK OrElse res.ObjectId = id Then Exit
Sub
Dim layer1 As String
Dim layer2 As String
Using tr As Transaction =
HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
Dim ent1 As Entity = CType(tr.GetObject(id, OpenMode.ForRead),
Entity)
Dim ent2 As Entity = CType(tr.GetObject(res.ObjectId,
OpenMode.ForRead), Entity)
layer1 = ent1.Layer
layer2 = ent2.Layer
End Using
Class1.SwapLayers(layer1, layer2)
End Sub
Shared Sub SwapLayers(ByVal Layer1 As String, ByVal Layer2 As String)
Using db As Database = HostApplicationServices.WorkingDatabase
Using tr As Transaction =
HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction
Using lt As LayerTable = tr.GetObject(db.LayerTableId,
OpenMode.ForRead)
If lt.Has(Layer1) AndAlso lt.Has(Layer2) Then
Dim ltr As LayerTableRecord =
tr.GetObject(lt.Item(Layer1), OpenMode.ForWrite)
Dim ltr2 As LayerTableRecord =
tr.GetObject(lt.Item(Layer2), OpenMode.ForWrite)
ltr.Name = "SwapLayers_temp"
ltr2.Name = Layer1
ltr.Name = Layer2
tr.Commit()
End If
End Using
End Using
End Using
End Sub
End Class
tp
escreveu na mensagem news:5450884@discussion.autodesk.com...
How should I repair my code? Some more help,plz.
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Public Class GILSclass1
_
Public Sub EraseObjectsFromLayer()
Dim DB As Database = HostApplicationServices.WorkingDatabase
Dim ED As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
Dim myT As Transaction = DB.TransactionManager.StartTransaction
Dim entselopt1 As PromptEntityOptions = New PromptEntityOptions(""
&
Microsoft.VisualBasic.Chr(10) & "Select first Entity: ")
Dim entselres1 As PromptEntityResult = ED.GetEntity(entselopt1)
entselopt1.SetRejectMessage("" & Microsoft.VisualBasic.Chr(10) &
"Entity may be selected.")
entselopt1.AddAllowedClass(GetType(Entity), True)
Dim Ent1 As Entity = CType(myT.GetObject(entselres1.ObjectId,
OpenMode.ForRead), Entity)
Dim entselopt2 As PromptEntityOptions = New PromptEntityOptions(""
&
Microsoft.VisualBasic.Chr(10) & "Select second Entity: ")
entselopt1.SetRejectMessage("" & Microsoft.VisualBasic.Chr(10) &
"Entity may be selected.")
entselopt1.AddAllowedClass(GetType(Entity), True)
Dim entselres2 As PromptEntityResult = ED.GetEntity(entselopt2)
Dim Ent2 As Entity = CType(myT.GetObject(entselres2.ObjectId,
OpenMode.ForRead), Entity)
Dim layer1 As String = Ent1.Layer.ToString
Dim layer2 As String = Ent2.Layer.ToString
Dim templayer As String = layer2.ToString
layer1 = templayer
layer2 = layer1
templayer = layer2
End Sub
End Class
I'm protected by SpamBrave
http://www.spambrave.com/