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

Swapping layers problem

4 REPLIES 4
Reply
Message 1 of 5
gilseorin
198 Views, 4 Replies

Swapping layers problem

Hi, all.
Is it possible to swap two layers?
Layer1---->Layer2
Layer2---->Layer1
Any help would be appreciated.
4 REPLIES 4
Message 2 of 5
caddie75
in reply to: gilseorin

Hi,

What exactly do you want to do;

If you want all entities on layer1 on layer2 and Layer2 on Layer1
I think the easiest is to rename "Layer1" into "tempLayer1" (check if it doesn't exist else "2" etc..
Then rename "Layer2" into "Layer1", and then the "tempLayer1" into "Layer2"

A. Caddie
Message 3 of 5
gilseorin
in reply to: gilseorin

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

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/
Message 5 of 5
gilseorin
in reply to: gilseorin

How generous!
Thank you so much,tp.
It works great.
Happy day!

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