I've just realised (thanks to you) that I was deepcloning each entity in my For Each Loop. That would explain why I had a bunch of viewport one on top of each other... DeepCloning the same collection again & again...
For Each id As ObjectId In acObjIdColl
' 'check if entity is a viewport
' If (id.ObjectClass.DxfName.ToUpper = "VIEWPORT") Then
' idcol.Add(id)
' Dim idmap As New IdMapping
' selectLayoutName.UpgradeOpen()
' acCurDb.DeepCloneObjects(idcol, selectLayoutName.BlockTableRecordId, idmap, False)
' Else
' Dim ent As Entity = DirectCast(acTrans.GetObject(id, OpenMode.ForWrite, False), Entity)
' Dim copiedEnt As Entity = DirectCast(ent.Clone(), Entity)
' selectedLayoutBtr.UpgradeOpen()
' selectedLayoutBtr.AppendEntity(copiedEnt)
' acTrans.AddNewlyCreatedDBObject(copiedEnt, True)
' End If
Moving the DeepCloning outside the For Each Loop seemed to have fix my issue...
For Each id As ObjectId In acObjIdColl
Dim obj As DBObject = acTrans.GetObject(id, OpenMode.ForRead)
Dim dbViewport As Viewport = TryCast(obj, Viewport)
If dbViewport IsNot Nothing Then
idcol.Add(id)
Else
Dim ent As Entity = DirectCast(acTrans.GetObject(id, OpenMode.ForWrite, False), Entity)
Dim copiedEnt As Entity = DirectCast(ent.Clone(), Entity)
selectedLayoutBtr.UpgradeOpen()
selectedLayoutBtr.AppendEntity(copiedEnt)
acTrans.AddNewlyCreatedDBObject(copiedEnt, True)
End If
Next
'go for the deepcloning on the ViewportCollection
Dim idmap As New IdMapping
selectLayoutName.UpgradeOpen()
acCurDb.DeepCloneObjects(idcol, selectLayoutName.BlockTableRecordId, idmap, False)
Once again, thanks a lot Gile!!