.NET

Reply
Active Member
Babak
Posts: 8
Registered: ‎10-12-2006
Message 1 of 5 (148 Views)

Copy an Entity to another Layer

148 Views, 4 Replies
11-03-2006 11:08 PM
How can I copy an Entity to another layer? I have its ObjectID.
Any idea or comment?

Thanks,
Babak
*tp
Message 2 of 5 (148 Views)

Re: Copy an Entity to another Layer

11-04-2006 02:38 AM in reply to: Babak
Imports AcAp = Autodesk.AutoCAD.ApplicationServices
Imports AcDb = Autodesk.AutoCAD.DatabaseServices


_
Public Sub MyTest()

Dim ed As AcEd.Editor =
AcAp.Application.DocumentManager.MdiActiveDocument.Editor
Dim res As AcEd.PromptEntityResult = ed.GetEntity("Select Entity")
Dim id As AcDb.ObjectId = res.ObjectId
'Dim dl As AcAp.DocumentLock =
AcAp.Application.DocumentManager.MdiActiveDocument.LockDocument
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
Dim ent As AcDb.Entity = tr.GetObject(id,
AcDb.OpenMode.ForWrite)
ent.Layer = "NewLayer"
tr.Commit()
End Using
End Using
'dl.Dispose()

End Sub

tp


escreveu na mensagem news:5385151@discussion.autodesk.com...
How can I copy an Entity to another layer? I have its ObjectID.
Any idea or comment?

Thanks,
Babak



I'm protected by SpamBrave
http://www.spambrave.com/
Active Member
Babak
Posts: 8
Registered: ‎10-12-2006
Message 3 of 5 (148 Views)

Re: Copy an Entity to another Layer

11-04-2006 09:40 AM in reply to: Babak
ٰThank you very much for your answer, but this code cuts the selected object and move it to NewLayer. I want to Copy it and have a copy of that object to another layer. Would you help me with this?

Thank you,
Babak
*tp
Message 4 of 5 (148 Views)

Re: Copy an Entity to another Layer

11-05-2006 05:39 AM in reply to: Babak
Hi, Babak
I hope it can help you

Imports AcAp = Autodesk.AutoCAD.ApplicationServices
Imports AcEd = Autodesk.AutoCAD.EditorInput
Imports AcGe = Autodesk.AutoCAD.Geometry
Imports AcRx = Autodesk.AutoCAD.Runtime
Imports AcDb = Autodesk.AutoCAD.DatabaseServices

Public Module Module1

_
Public Sub Copy2Layer()
Dim ed As AcEd.Editor =
AcAp.Application.DocumentManager.MdiActiveDocument.Editor()
ed.WriteMessage(vbLf & "Copy entities to layer")
Dim res As AcEd.PromptEntityResult = ed.GetEntity("Select entity")
If res.Status <> AcEd.PromptStatus.OK Then Exit Sub
Dim optp As New AcEd.PromptPointOptions(vbLf & "Copy from point")
Dim resp As AcEd.PromptPointResult = ed.GetPoint(optp)
If resp.Status <> AcEd.PromptStatus.OK Then Exit Sub
Dim fromPt As AcGe.Point3d = resp.Value
optp.Message = "To point"
optp.UseBasePoint = True
optp.BasePoint = fromPt
resp = ed.GetPoint(optp)
If resp.Status <> AcEd.PromptStatus.OK Then Exit Sub
Dim toPt As AcGe.Point3d = resp.Value
Dim id As AcDb.ObjectId = Module1.CopyEntity(res.ObjectId, fromPt,
toPt)
Module1.ChangeLayer(id, "NewLayer")
End Sub

Friend Function CopyEntity(ByVal objID As AcDb.ObjectId, ByVal fromPt
As
AcGe.Point3d, ByVal toPt As AcGe.Point3d) As AcDb.ObjectId
If objID = Nothing Then Return Nothing
Dim id As AcDb.ObjectId = Nothing
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction
Try
Dim v3d As New AcGe.Vector3d(toPt.X - fromPt.X, toPt.Y -
fromPt.Y, toPt.Z - fromPt.Z)
Dim m3d As AcGe.Matrix3d = AcGe.Matrix3d.Displacement(v3d)
Using btr As AcDb.BlockTableRecord =
tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite, False)
Dim ent As AcDb.Entity = tr.GetObject(objID,
AcDb.OpenMode.ForRead, False)
Dim e As AcDb.Entity = ent.GetTransformedCopy(m3d)
id = btr.AppendEntity(e)
db.TransactionManager.AddNewlyCreatedDBObject(e, True)
tr.Commit()
End Using
Catch ex As Exception
tr.Abort()
End Try
End Using
End Using
Return id
End Function

Friend Sub ChangeLayer(ByVal objID As AcDb.ObjectId, ByVal newLayer As
String)
'Dim dl As AcAp.DocumentLock =
AcAp.Application.DocumentManager.MdiActiveDocument.LockDocument()
Using db As AcDb.Database =
AcDb.HostApplicationServices.WorkingDatabase()
Using tr As AcDb.Transaction =
db.TransactionManager.StartTransaction()
Dim ent As AcDb.Entity = tr.GetObject(objID,
AcDb.OpenMode.ForWrite)
ent.Layer = newLayer
tr.Commit()
End Using
End Using
'dl.Dispose()
End Sub

End Module

tp



escreveu na mensagem news:5385306@discussion.autodesk.com...
?Thank you very much for your answer, but this code cuts the selected
object
and move it to NewLayer. I want to Copy it and have a copy of that object
to
another layer. Would you help me with this?

Thank you,
Babak



I'm protected by SpamBrave
http://www.spambrave.com/
Active Member
Babak
Posts: 8
Registered: ‎10-12-2006
Message 5 of 5 (148 Views)

Re: Copy an Entity to another Layer

11-06-2006 12:01 PM in reply to: Babak
Thank you very much,
It works perfectly :smileyhappy:
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!