.NET

.NET

Reply
Moderator
1,468 Posts
277 Kudos
Registered: ‎04-09-2008
Post 11 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-26-2012 10:30 PM in reply to: NovayaEra

freestyler8 wrote:
How to find cloned entities in destination dwg after cloning? When it was cloned, it got new ObjectID, truly?

All ObjectID's of cloned entities are in acIDMap as a idPair.Value


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
13 Posts
0 Kudos
Registered: ‎08-10-2011
Post 12 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-27-2012 12:15 AM in reply to: cwelkusl

I make so:

  For Each idp As IdPair In acIDMap
       Try
              Dim acEnt As Object = acDestTrans.GetObject(idp.Value, OpenMode.ForWrite)
               acEnt.TransformBy(m) 'm as Matrix3d
       Catch
       End Try
  Next

 But cloned objects was Text, Line and Block. This code moves only Text. Line and Block are disappear

Moderator
1,468 Posts
277 Kudos
Registered: ‎04-09-2008
Post 13 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-27-2012 01:24 AM in reply to: NovayaEra

freestyler8 wrote:

I make so:

  For Each idp As IdPair In acIDMap
       Try
              Dim acEnt As Object = acDestTrans.GetObject(idp.Value, OpenMode.ForWrite)
               acEnt.TransformBy(m) 'm as Matrix3d
       Catch
       End Try
  Next

 But cloned objects was Text, Line and Block. This code moves only Text. Line and Block are disappear


You have to move only entities that acEnt.OwnerId is equal acDestModelSpace.ObjectId


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
13 Posts
0 Kudos
Registered: ‎08-10-2011
Post 14 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-27-2012 04:24 AM in reply to: Alexander.Rivilis

Alexander.Rivilis wrote:
You have to move only entities that acEnt.OwnerId is equal acDestModelSpace.ObjectId

Yes, acEnt.OwnerId is equal acDestModelSpace.ObjectId for three objects: Line, DBText and BlockReference. And successfully moved only DBtext.  Block and Line becomes invisible, but I can see it's central points (it's moved).

 

 

 

 

 

Moderator
1,468 Posts
277 Kudos
Registered: ‎04-09-2008
Post 15 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-27-2012 04:28 AM in reply to: NovayaEra

freestyler8 wrote:
Yes, acEnt.OwnerId is equal acDestModelSpace.ObjectId for three objects: Line, DBText and BlockReference. And successfully moved only DBtext.  Block and Line becomes invisible, but I can see it's central points (it's moved).

Maybe layer's of BlockReference and Line is off or frozen, or property Visible of those entities is False

P.S.: Without full code and a sample dwg-file I can not help you.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
13 Posts
0 Kudos
Registered: ‎08-10-2011
Post 16 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-27-2012 04:43 AM in reply to: Alexander.Rivilis

No, it's Visible property is True, layer is same that DText's layer.  And if I don't move it, it's visible :-(

 

this code:

 

Public Function InsertAll(sFN As String, ipt As Point3d) As Boolean

        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim acdocDest As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim acDestDB As Database = acdocDest.Database
        Dim acObjIDs As ObjectIdCollection = New ObjectIdCollection()
        Dim acIDMap As IdMapping = New IdMapping()

        Try

            Using acDocLock As DocumentLock = acdocDest.LockDocument()
                Using acSourceDB As New Database(False, True)
                    Using acSourceTrans As Transaction = acSourceDB.TransactionManager.StartTransaction()
                        acSourceDB.ReadDwgFile(sFN, IO.FileShare.Read, True, "")
                        Using acDestTrans As Transaction = acDestDB.TransactionManager.StartTransaction()

                            Dim acSourceBlockTable As BlockTable = acSourceTrans.GetObject(acSourceDB.BlockTableId, OpenMode.ForRead)
                            Dim acSourceModelSpace As BlockTableRecord = acSourceTrans.GetObject(acSourceBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForRead)

                            Dim acDestBlockTable As BlockTable = acDestTrans.GetObject(acDestDB.BlockTableId, OpenMode.ForWrite)
                            Dim acDestModelSpace As BlockTableRecord = acDestTrans.GetObject(acDestBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

                            For Each acObjID As ObjectId In acSourceModelSpace
                                acObjIDs.Add(acObjID)
                            Next acObjID

                            'Copy
                            acSourceDB.WblockCloneObjects(acObjIDs, acDestModelSpace.ObjectId, acIDMap, DuplicateRecordCloning.Ignore, False)

                            'Move
                            ed.WriteMessage(ipt.ToString)
                            Dim origin As Point3d = New Point3d(0, 0, 0)
                            Dim v As Vector3d = New Vector3d(0, 0, 0)
                            Dim m As Matrix3d = Matrix3d.AlignCoordinateSystem(origin, v, v, v, ipt, v, v, v)

                            For Each idp As IdPair In acIDMap
                                Try
                                    Dim acEnt As Object = acDestTrans.GetObject(idp.Value, OpenMode.ForWrite)
                                    If acEnt.OwnerID.ToString = acDestModelSpace.ObjectId.ToString Then
                                        ed.WriteMessage(vbLf & acEnt.GetType.ToString)
                                        ed.WriteMessage(vbLf & acEnt.OwnerID.ToString)
                                        acEnt.TransformBy(m)
                                        ed.WriteMessage(vbLf & "moved")
                                    End If
                                Catch
                                    ed.WriteMessage(vbLf & "err")
                                End Try
                            Next

                            acDestTrans.Commit()
                        End Using
                    End Using
                End Using
            End Using

        Catch ex As Exception
            MsgBox("Error importing objects: " & ex.Message & vbCrLf & vbTab & ex.StackTrace, MsgBoxStyle.Critical)
        End Try

    End Function

 this result:

 

Autodesk.AutoCAD.DatabaseServices.BlockReference
(8796083599856)
moved
Autodesk.AutoCAD.DatabaseServices.DBText
(8796083599856)
moved
Autodesk.AutoCAD.DatabaseServices.Line
(8796083599856)
moved

Moderator
1,468 Posts
277 Kudos
Registered: ‎04-09-2008
Post 17 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-27-2012 04:55 AM in reply to: NovayaEra

Very strange code:

Dim origin As Point3d = New Point3d(0, 0, 0)
Dim v As Vector3d = New Vector3d(0, 0, 0)
Dim m As Matrix3d = Matrix3d.AlignCoordinateSystem(origin, v, v, v, ipt, v, v, v)

 Maybe:

Dim m As Matrix3d = Matrix3d.Displacement(ipt - origin)

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
13 Posts
0 Kudos
Registered: ‎08-10-2011
Post 18 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-27-2012 09:55 PM in reply to: Alexander.Rivilis
Yes, it works! Thank you very much!! С наступающим Вас! :-)
New Member
2 Posts
0 Kudos
Registered: ‎05-30-2012
Post 19 of 19

Re: "Clone" an object from one drawing to another with modifications p

12-09-2014 01:25 AM in reply to: NovayaEra

sry, this was already asked, i didn't see page 2 for some reason.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!