.NET

.NET

Reply
Valued Contributor
C_Witt
Posts: 62
Registered: ‎03-22-2010
Message 1 of 5 (761 Views)
Accepted Solution

Copy object inside same drawing... problems

761 Views, 4 Replies
01-27-2011 09:04 AM

I've been using this method for "copying" objects from one point to another..

 

Dim EntityCopy As Entity = EntitySource.GetTransformedCopy(Matrix3d.Displacement(startPT.GetVectorTo(EndPT)))

 

But have run into a few glitches, not program stopping glitches just annoying ones..

 

With polylines, not all the properties are copied, one for example is the "global width".  it gets re-set to 0.

 

Problem is with dynamic blocks..  the above method creates a "dumb" version of the block rather than a functional dynamic version of the block..

 

Can anyone show me a way to fix this, or an alternate method for copying objects from point a to point b?

In that case as for  Tony Tanzillo's recomendation I wouldt use

DeepCloneObjects method of DataBase instead

Try this quicky

No error trapping in there, do it by yourself

 <CommandMethod("como")> _
Public Shared Sub CopyMove()
Dim doc As Document = acApp.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 = ed.GetPoint(vbCr & "Pick a point from: ").Value
Dim EndPT As Point3d = ed.GetPoint(vbCr & "Pick a point to: ").Value
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.ForRead), 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

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 5 (740 Views)

Re: Copy object inside same drawing... problems

01-27-2011 02:57 PM in reply to: C_Witt

In that case as for  Tony Tanzillo's recomendation I wouldt use

DeepCloneObjects method of DataBase instead

Try this quicky

No error trapping in there, do it by yourself

    <CommandMethod("como")> _
    Public Shared Sub CopyMove()
        Dim doc As Document = acApp.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 = ed.GetPoint(vbCr & "Pick a point from: ").Value
        Dim EndPT As Point3d = ed.GetPoint(vbCr & "Pick a point to: ").Value
        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.ForRead), 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

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
C_Witt
Posts: 62
Registered: ‎03-22-2010
Message 3 of 5 (714 Views)

Re: Copy object inside same drawing... problems

01-28-2011 06:13 AM in reply to: C_Witt

Thank you, that is perfect. :smileyhappy:

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 5 (709 Views)

Re: Copy object inside same drawing... problems

01-28-2011 06:52 AM in reply to: C_Witt

You're welcome :smileyhappy:

Glad to help

Regards,

 

Oleg

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
MRiemenCAD
Posts: 65
Registered: ‎03-31-2003
Message 5 of 5 (696 Views)

Re: Copy object inside same drawing... problems

01-28-2011 07:50 AM in reply to: Hallex

Working with making blocks from existing entities in a file. I've run into problems with iterating through the entities within a selection set and writing them to my new blocktablerecord. How do I take those items from my selection set and add them to this new block? All thoughts and help are appreciated. 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.