i have tried with this code,
its copying the selected object in same layer with different color
could you tell me in this code how paste the object in different layer.
Also attached a dwg file, shows the output required
<CommandMethod("cp")>
Public Shared Sub CopyMove()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim peo As New PromptEntityOptions(vbLf & "Select object:")
Dim per As PromptEntityResult = ed.GetEntity(peo)
If per.Status <> PromptStatus.OK Then
Return
End If
Dim startPT As Point3d = per.PickedPoint
Dim EndPT As Point3d = per.PickedPoint
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
Dim sourceId As ObjectId = per.ObjectId
Dim EntitySource As Entity = CType(tr.GetObject(sourceId, OpenMode.ForWrite), Entity)
Dim ids As New ObjectIdCollection()
ids.Add(sourceId)
db.DeepCloneObjects(ids, db.CurrentSpaceId, New IdMapping, False)
Dim EntityCopy As Entity = CType(tr.GetObject(ids(0), OpenMode.ForRead), Entity)
EntityCopy.UpgradeOpen()
EntityCopy.TransformBy(Matrix3d.Displacement(startPT.GetVectorTo(EndPT)))
EntityCopy.ColorIndex = 2
tr.Commit()
End Using
End Sub