.NET

.NET

Reply
Moderator
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 11 of 18 (208 Views)

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
NovayaEra
Posts: 13
Registered: ‎08-10-2011
Message 12 of 18 (203 Views)

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
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 13 of 18 (192 Views)

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
NovayaEra
Posts: 13
Registered: ‎08-10-2011
Message 14 of 18 (182 Views)

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
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 15 of 18 (178 Views)

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
NovayaEra
Posts: 13
Registered: ‎08-10-2011
Message 16 of 18 (174 Views)

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
Alexander.Rivilis
Posts: 1,406
Registered: ‎04-09-2008
Message 17 of 18 (167 Views)

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
NovayaEra
Posts: 13
Registered: ‎08-10-2011
Message 18 of 18 (149 Views)

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!! С наступающим Вас! :-)
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.