.NET

Reply
Active Contributor
C_Witt
Posts: 34
Registered: ‎03-22-2010
Message 1 of 5 (721 Views)
Accepted Solution

Copy object inside same drawing... problems

721 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 (700 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
Active Contributor
C_Witt
Posts: 34
Registered: ‎03-22-2010
Message 3 of 5 (674 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 (669 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 (656 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. 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.