Author Topic: WblockCloneobjects Problem  (Read 5822 times)

0 Members and 1 Guest are viewing this topic.

ReneRam

  • Newt
  • Posts: 80
  • The great gig in the sky
WblockCloneobjects Problem
« on: March 11, 2008, 11:56:43 AM »
My question may look simple but it's driving me nuts for about a few days, and I really don't know where to look for the error.

What I'm trying to do is to open the DB of an external drawing and clone the objects in specific layers in my current drawing. If I work with just one entity I don't have any problem, but when I start iterating through many ents I get "eOutOfRange" ERROR.
Since it seems that I can't make a selection set on and external drawing I thought that iterating through the DB and selecting the ents by the layer name could solve, but I'm missing something. I tried opening and closing transactions in different points of the loop, but still I can't get what generates the error.
Here's a sample of my code 'till now, any help will be appreciated!


Code: [Select]

    Public Sub CloneEntsFromDWG()

        Dim ExtDwgLayName() As String = {"Walls", "Lighting"}       ' The Layers with the ents to clone
        Dim i As Integer = 0                                        ' counter

        ' Start Looping through layer names
        For i = 0 To 1
            ' Current Drawing is ThisDWG
            Dim ThisDWG As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim ThisDB As DatabaseServices.Database = ThisDWG.Database
            Dim ThisTransMan As DatabaseServices.TransactionManager = ThisDWG.TransactionManager
            Dim ThisTrans As DatabaseServices.Transaction = ThisTransMan.StartTransaction

            ' External Drawing is ExtDwg
            Dim ExtDwgDB As DatabaseServices.Database = New DatabaseServices.Database
            ExtDwgDB.ReadDwgFile("C:\Programmi\AutoCAD 2008\Sample\Blocks and Tables - Metric.dwg", IO.FileShare.Read, True, "")
            Dim ExtDwgTransMan As DatabaseServices.TransactionManager = ExtDwgDB.TransactionManager
            Dim ExtDwgTrans As DatabaseServices.Transaction = ExtDwgTransMan.StartTransaction
            Dim ExtDwgBlockT As DatabaseServices.BlockTable = ExtDwgDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
            Dim ExtDwgBlockTR As DatabaseServices.BlockTableRecord = ExtDwgTrans.GetObject(ExtDwgBlockT(BlockTableRecord.ModelSpace), OpenMode.ForRead)

            ' Open This Drawing BlockTable for Write
            Dim ThisDwgBlockT As DatabaseServices.BlockTable = ThisDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForWrite)
            Dim DBMap As New DatabaseServices.IdMapping
            Dim ObjIds As New DatabaseServices.ObjectIdCollection

            ' Loop through ents in External Drawing
            For Each ExtDwgEntId As ObjectId In ExtDwgBlockTR
                Dim ExtDwgEnt As Entity = ExtDwgTrans.GetObject(ExtDwgEntId, OpenMode.ForRead)
                ' check if Entity is in the selected layer
                If ExtDwgEnt.Layer = ExtDwgLayName(i) Then
                    ' populate object ID collection
                    ObjIds.Add(ExtDwgBlockTR.ObjectId)
                End If
            Next

            ' WblockCloneObjects
            ThisDB.WblockCloneObjects(ObjIds, ThisDwgBlockT.ObjectId, DBMap, _
                    DatabaseServices.DuplicateRecordCloning.Replace, False)     '<= eOutOfRange ERROR

            ' Commit, Dispose transactions
            ThisTrans.Commit() : ThisTrans.Dispose() : ThisTransMan.Dispose()
            ExtDwgTrans.Dispose() : ExtDwgTransMan.Dispose() : ExtDwgDB.Dispose()

        Next i


    End Sub



Thanks in advance
René
"A clever person solves a problem. A wise person avoids it." - Albert Einstein

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: WblockCloneobjects Problem
« Reply #1 on: March 11, 2008, 02:04:15 PM »
1. Get rid of your outer 'for' loop as it's unnecessary.

2. Change this:

Code: [Select]
If ExtDwgEnt.Layer = ExtDwgLayName(i) Then

to something like this:

Code: [Select]
If ExtDwgEnt.Layer = "Walls" or ExtDwgEnt.Layer = "Lighting" Then
' add it

3. This line:

Code: [Select]
ObjIds.Add(ExtDwgBlockTR.ObjectId)

is actually adding the ID of MODELSPACE and in your loop is doing it TWICE!
It should be:

Code: [Select]
ObjIds.Add(ExtDwgEntId)

That's all I can see from my quick glance.

Cheers,
Glenn.
Me

Fatty

  • Guest
Re: WblockCloneobjects Problem
« Reply #2 on: March 11, 2008, 05:05:36 PM »

ReneRam

  • Newt
  • Posts: 80
  • The great gig in the sky
Re: WblockCloneobjects Problem
« Reply #3 on: March 14, 2008, 07:30:27 PM »
I don't like crossposting, but after looking in many forums I came back here.

Following Fatty's advice I took a look to Kean's example in his blog and made my changes. I came out with the following code, it's just a simplified part part of a bigger program, but in this part is where I'm actually doing the cloning. As I said before, I need to import in my drawing ents from an external dwg, mainly ploys and hatches, filtering them by layer.
The following code doesn't raise any error, but after the execution I have imported only the empty layers, there must be something wrong in my "WblockCloneObjects".
When  I add the objectId in "myEntsIds.Add(SrcEntId)" I can see that I'm adding the polys and hatches Ids, but I'm still missing something.   :-(
At this point I'll forget about iteration through more layers, I've tested this part and it works, I get more layers!! :-)


Code: [Select]

Public Sub CloneTest()

Dim MyDocs As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
Dim myDB As Database = MyDocs.MdiActiveDocument.Database
Dim SrcDB As New DatabaseServices.Database(False, True)
SrcDB.ReadDwgFile("C:\Documents and Settings\rdramirez\Desktop\CloneTest.dwg", IO.FileShare.Read, True, "")

Dim SrcLayName As String = "002005016005"    'the external drawing layer name

Try

Dim myEntsIds As New ObjectIdCollection
Dim SrcTransMan As DatabaseServices.TransactionManager = SrcDB.TransactionManager

Using SrcTrans As DatabaseServices.Transaction = SrcTransMan.StartTransaction

Dim SrcBT As DatabaseServices.BlockTable = DirectCast(SrcTransMan.GetObject(SrcDB.BlockTableId, OpenMode.ForRead, False), BlockTable)

For Each SrcBTRId As ObjectId In SrcBT
Dim SrcBTR As BlockTableRecord = DirectCast(SrcTransMan.GetObject(SrcBTRId, OpenMode.ForRead, False), BlockTableRecord)
If SrcBTR.Name = "*Model_Space" Then
For Each SrcEntId As ObjectId In SrcBTR
Dim SrcEnt As Entity = SrcTrans.GetObject(SrcEntId, OpenMode.ForRead)
If SrcEnt.Layer = SrcLayName Then
myEntsIds.Add(SrcEntId)

End If
Next
SrcBTR.Dispose()
End If

Next
SrcBT.Dispose()

End Using

Dim myIdMapping As New DatabaseServices.IdMapping
'SrcDB.WblockCloneObjects(myEntsIds, myDB.BlockTableId, myIdMapping, DuplicateRecordCloning.Replace, False)
myDB.WblockCloneObjects(myEntsIds, myDB.BlockTableId, myIdMapping, DuplicateRecordCloning.Replace, False)


Catch ex As Exception
MsgBox(ex.Message)
End Try

SrcDB.Dispose()


End Sub



I tested this with blocks, layers and linetypes, and it works, but actually in these cases I'm not importing ents but just definitions, maybe my mistake is just hidden there, in not adding the real ents.  :grazy:

Thanks for any help
René
"A clever person solves a problem. A wise person avoids it." - Albert Einstein

ReneRam

  • Newt
  • Posts: 80
  • The great gig in the sky
Re: WblockCloneobjects Problem
« Reply #4 on: March 16, 2008, 09:32:05 AM »
Partially solved the issue!  :-)
The following code works, the only bad note is that hatches lose associativity, but it's understandable since they are cloned without the boundary.

I'm still working on it, but I'll post the code in case it can help others.

Code: [Select]

    Public Sub CloneTest()

        ' Connect to Source Drawing
        Dim SrcDB As DatabaseServices.Database = _
            New DatabaseServices.Database(False, True)
        Dim SrcTransMan As DatabaseServices.TransactionManager = _
            SrcDB.TransactionManager

        ' Connect to Current Drawing
        Dim myDWG As ApplicationServices.Document = _
            ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim myDB As DatabaseServices.Database = _
            myDWG.Database
        Dim myTransMan As DatabaseServices.TransactionManager = _
            myDWG.TransactionManager

        ' Read Source Drawing
        SrcDB.ReadDwgFile("C:\Documents and Settings\René\Documenti\GTA\CloneTest.dwg", _
            IO.FileShare.Read, True, "")

        ' Start Transactions
        Dim SrcTrans As DatabaseServices.Transaction = _
            SrcTransMan.StartTransaction
        Dim myTrans As DatabaseServices.Transaction = _
            myTransMan.StartTransaction

        ' Open Source BlockTable and "ModelSpace" BlockTableRecord ForRead
        Dim SrcBT As DatabaseServices.BlockTable = _
            SrcDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
        Dim SrcBTR As BlockTableRecord = _
            SrcTrans.GetObject(SrcBT(BlockTableRecord.ModelSpace), OpenMode.ForRead)

        ' Open Current Drawing BlockTable and "ModelSpace" BlockTableRecord ForWrite
        Dim myBT As DatabaseServices.BlockTable = _
            myDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForWrite)
        Dim myBTR As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

        Dim SrcLayName As String = "002005016005"

        ' Loop entities in the Source Drawing
        For Each SrcEntId As ObjectId In SrcBTR
            Dim SrcEnt As Entity = SrcTrans.GetObject(SrcEntId, OpenMode.ForRead)
            ' Check if the entity is in the current analized source layer
            If SrcEnt.Layer = SrcLayName Then
                Dim myMap As New DatabaseServices.IdMapping
                Dim myObjs As New DatabaseServices.ObjectIdCollection
                ' Add the source entity ObjectId to the ObjectIDCollection to clone
                myObjs.Add(SrcEnt.ObjectId)
                ' WblockClone the Source Entity
                myDB.WblockCloneObjects(myObjs, myBTR.ObjectId, myMap, _
                    DatabaseServices.DuplicateRecordCloning.Replace, False)
            End If
        Next ' End of Loop entities in the Source Drawing

        ' Commit, Close and Dispose Transactions
        myTrans.Commit() : myTrans.Dispose() : myTransMan.Dispose()
        SrcTrans.Dispose() : SrcTransMan.Dispose() : SrcDB.Dispose()

    End Sub


René
"A clever person solves a problem. A wise person avoids it." - Albert Einstein

Bryco

  • Water Moccasin
  • Posts: 1850
Re: WblockCloneobjects Problem
« Reply #5 on: March 16, 2008, 02:08:22 PM »
I see you are adding to the modelspace now.
I found (with very limited testing) that the code below works.
I presume the DuplicateRecordCloning.Ignore option takes care of any duplication and the code works as it meets timing issues involved with associativity

Code: [Select]
foreach (ObjectId EntId in btr)
{
    Entity Ent = tr.GetObject(EntId, OpenMode.ForRead) as Entity;
    if(Ent.GetType()==typeof(Autodesk.AutoCAD.DatabaseServices.Hatch))
    {
        Hatch h = (Hatch)Ent;
        ObjectIdCollection hatchIds = h.GetAssociatedObjectIds();
        foreach (ObjectId id in hatchIds)
        {
            myEntsIds.Add(id);
        }
    }

    if (Ent.Layer == LayName) myEntsIds.Add(EntId);
} //next

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: WblockCloneobjects Problem
« Reply #6 on: March 17, 2008, 05:32:54 PM »
I was thinking of using this for Civil 3D "Data Reference" objects.
They are like pointer objects to the original objects that define a design element.
Anyone see why this kind of code would not work on custom objects?
James Maeding

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: WblockCloneobjects Problem
« Reply #7 on: March 17, 2008, 07:44:00 PM »
Code: [Select]

        Dim SrcLayName As String = "002005016005"

        ' Loop entities in the Source Drawing
        For Each SrcEntId As ObjectId In SrcBTR
            Dim SrcEnt As Entity = SrcTrans.GetObject(SrcEntId, OpenMode.ForRead)
            ' Check if the entity is in the current analized source layer
            If SrcEnt.Layer = SrcLayName Then
                Dim myMap As New DatabaseServices.IdMapping
                Dim myObjs As New DatabaseServices.ObjectIdCollection
                ' Add the source entity ObjectId to the ObjectIDCollection to clone
                myObjs.Add(SrcEnt.ObjectId)
                ' WblockClone the Source Entity
                myDB.WblockCloneObjects(myObjs, myBTR.ObjectId, myMap, _
                    DatabaseServices.DuplicateRecordCloning.Replace, False)
            End If
        Next ' End of Loop entities in the Source Drawing

René

The above  code snippet tells me two (2) things:

1. You don't understand the 'WblockCloneObjects' function and especially it's arguments.
2. With respect to the preceding point 1 above, you don't understand your language's looping structures.

As your code is above, you are declaring an IdMapping and source clone ObjectIdCollection INSIDE every iteration of your foreach loop.
This means, that if you had, say, 1000 objects that matched your layer name criteria, then you would be instantiating 1000 IdMapping and ObjectIdCollection
objects, as well as making 1000 'WblockCloneObjects' function calls, just to clone one object found on each iteration of your loop.

My suggestion would be to move the declaration of the IdMapping and ObjectIdCollection to before your loop and then after the loop, check if they have anything in them,
then issue one WblockCloneObjects function call.
Me

ReneRam

  • Newt
  • Posts: 80
  • The great gig in the sky
Re: WblockCloneobjects Problem
« Reply #8 on: March 19, 2008, 09:58:07 AM »
 :oops: Hi Glenn,

According to my first message:

Quote
My question may look simple but it's driving me nuts for about a few days, and I really don't know where to look for the error.

What I'm trying to do is to open the DB of an external drawing and clone the objects in specific layers in my current drawing. If I work with just one entity I don't have any problem, but when I start iterating through many ents I get "eOutOfRange" ERROR.
Since it seems that I can't make a selection set on and external drawing I thought that iterating through the DB and selecting the ents by the layer name could solve, but I'm missing something. I tried opening and closing transactions in different points of the loop, but still I can't get what generates the error.
Here's a sample of my code 'till now, any help will be appreciated!

I was looking for help since I really didn't understand what I was doing.
Quote
1. You don't understand the 'WblockCloneObjects' function and especially it's arguments.
2. With respect to the preceding point 1 above, you don't understand your language's looping structures.

In my office I can spend only a few hours a day, and some at home when my kids sleep, developing; as the IT manager of my company I have to follow many things that are not related to developing. Actually I'm migrating some code I wrote in VBA for AutoCAD 2004 to VB.Net with the Managed ObjectArx in AutoCAD 2008. It's code I wrote just for our company and it works fine, this is my first experience with VB.Net.
I posted here looking for help because I didn't know how to go further. Since I haven't found an advanced manual that teaches developing with .Net in AutoCAD the only source I think can help me growing is a forum like this, where I post and get hints or suggestions on how to do something. I'm not looking for copy and paste code, since I'm not selling software, I just need help.
This is part of my program, at the moment, and as you can see I had already made what you suggested, but didn't post until it's finished. Ususally I test, debug and finally optimize my code. I still have to try Bryco's suggestion.

Code: [Select]
    Sub WblockLayerIN(ByVal SourceDrawing As String, ByVal LayerName As String)
        ' Connect to Source Drawing
        Dim SrcDB As DatabaseServices.Database = _
            New DatabaseServices.Database(False, True)
        Dim SrcTransMan As DatabaseServices.TransactionManager = _
            SrcDB.TransactionManager

        ' Connect to Current Drawing
        Dim myDWG As ApplicationServices.Document = _
            ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim myDB As DatabaseServices.Database = _
            myDWG.Database
        Dim myTransMan As DatabaseServices.TransactionManager = _
            myDWG.TransactionManager


        ' Read Source Drawing
        SrcDB.ReadDwgFile(SourceDrawing, IO.FileShare.Read, True, "")

        ' Start Transactions
        Dim SrcTrans As DatabaseServices.Transaction = _
            SrcTransMan.StartTransaction
        Dim myTrans As DatabaseServices.Transaction = _
            myTransMan.StartTransaction

        ' Open Source BlockTable and "ModelSpace" BlockTableRecord ForRead
        Dim SrcBT As DatabaseServices.BlockTable = _
            SrcDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
        Dim SrcBTR As BlockTableRecord = _
            SrcTrans.GetObject(SrcBT(BlockTableRecord.ModelSpace), OpenMode.ForRead)

        ' Open Current Drawing BlockTable and "ModelSpace" BlockTableRecord ForWrite
        Dim myBT As DatabaseServices.BlockTable = _
            myDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForWrite)
        Dim myBTR As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

        Dim myObjs As New DatabaseServices.ObjectIdCollection ' Colection that Stores the Entities ID

        ' Loop entities in the Source Drawing
        For Each SrcEntId As ObjectId In SrcBTR
            Dim SrcEnt As Entity = SrcTrans.GetObject(SrcEntId, OpenMode.ForRead)
            ' Check if the entity is in the current analized source layer
            If SrcEnt.Layer = LayerName Then
                ' Add the source entity ObjectId to the ObjectIDCollection to clone
                myObjs.Add(SrcEnt.ObjectId)
            End If
        Next ' End of Loop entities in the Source Drawing

        ' WblockClone the Source Entity
        Dim myMap As New DatabaseServices.IdMapping
        myDB.WblockCloneObjects(myObjs, myBTR.ObjectId, myMap, _
            DatabaseServices.DuplicateRecordCloning.Replace, False)

        ' Commit, Close and Dispose Transactions
        myTrans.Commit() : myTrans.Dispose() : myTransMan.Dispose()
        SrcTrans.Dispose() : SrcTransMan.Dispose() : SrcDB.Dispose()
    End Sub           ' Imports a Layer with all the Entities

When I'm finished writing the code I'll post it to share with others, but since I'm not a developer guru, it will be just contribution for other beginners.
Regards
René
"A clever person solves a problem. A wise person avoids it." - Albert Einstein

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: WblockCloneobjects Problem
« Reply #9 on: March 19, 2008, 11:57:12 AM »
OK René, now I understand you better.

The trick with WblockCloneObjects is that ALL of the entities you want cloned, MUST all have the same owner container.
So, for example, all entities in Modelspace have the same container, a BlockTableRecord, which is modelspace.

Also, looking at your code, I would break it into two separate transactions. Start a transaction on your source dbase and collect all the entities you need and commit it.
Then start a transaction on your destination dbase to clone the objects over.

One catch - do NOT dispose of your source dbase untill all the above has finished. Actually, I just noticed that you're not disposing
of your source dbase SrcDb at all (I really don't read VB code all that well as I don't want to) - you definately should, otherwise it will lead to other problems.

As a general .NET rule of thumb, if an object implements the IDisposable interface by supplying a method called Dispose() you should call it. However, having said that,
the general rule of thumb for AutoCAD .NET is, if you create it and it's got Dispose(), call it when you're done, otherwise the dbase owns it and you leave it alone.

Seeing as you create a NEW dbase and read a dwg file into, you are responsible for cleaning up after yourself.

Hope this helps.

Cheers,
Glenn.
Me

ReneRam

  • Newt
  • Posts: 80
  • The great gig in the sky
Re: WblockCloneobjects Problem
« Reply #10 on: March 19, 2008, 01:13:11 PM »
Hi Glenn,
the reason I had opened the transactions together was following my old VBA code were I had to documents op en at the same time and switched back and forth copying ents. One of the features of the program is to "bundle" different layers together in the current drawing and change the ents properties according to the newly created layer. Actually taking a closer look and thinking of breaking the code code in two parts:
  • reading
  • writing

has perfect sense at this point. About closing the transactions, it's done in the last two lines, that in VB (I will have to move to C#  :wink:) are six lines of code.

The last lines of the code:
Quote
        ' Commit, Close and Dispose Transactions
        myTrans.Commit() : myTrans.Dispose() : myTransMan.Dispose()
        SrcTrans.Dispose() : SrcTransMan.Dispose() : SrcDB.Dispose()

Thanks for your comment
René
"A clever person solves a problem. A wise person avoids it." - Albert Einstein

Glenn R

  • Water Moccasin
  • Posts: 1932
  • What idiot child of married cousins wrote this?!
Re: WblockCloneobjects Problem
« Reply #11 on: March 19, 2008, 01:27:52 PM »
 :-D Told you I didn't read VB.NET code that well...I now see where you're disposing of the newly created dbase in amongst all the transaction dispose calls.

I should clarify my last statement from my previous post:

If you 'new' it and add it to the dbase, then acad owns it, so don't Dispose it.
If you 'new' it and DO NOT add it to the dbase, then you destroy it by calling Dispose.

Cheers,
Glenn.
Me

ReneRam

  • Newt
  • Posts: 80
  • The great gig in the sky
Re: WblockCloneobjects Problem
« Reply #12 on: March 21, 2008, 05:38:26 AM »
 8-)

Just posting the last version of the sub, it imports, just for the ModelSpace, the contents of a layer in an external drawing, and thanks to Bryco's comment I don't lose associativity.

Code: [Select]
    Sub WblockLayerIN(ByVal SourceDrawing As String, ByVal LayerName As String)
        ' Connect to Source Drawing
        Dim SrcDB As DatabaseServices.Database = _
            New DatabaseServices.Database(False, True)
        Dim SrcTransMan As DatabaseServices.TransactionManager = _
            SrcDB.TransactionManager

        ' Connect to Current Drawing
        Dim myDWG As ApplicationServices.Document = _
            ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim myDB As DatabaseServices.Database = _
            myDWG.Database
        Dim myTransMan As DatabaseServices.TransactionManager = _
            myDWG.TransactionManager

        ' Read Source Drawing
        SrcDB.ReadDwgFile(SourceDrawing, IO.FileShare.Read, True, "")

        ' Start Transactions
        Dim SrcTrans As DatabaseServices.Transaction = _
            SrcTransMan.StartTransaction
        Dim myTrans As DatabaseServices.Transaction = _
            myTransMan.StartTransaction

        ' Open Source BlockTable and "ModelSpace" BlockTableRecord ForRead
        Dim SrcBT As DatabaseServices.BlockTable = _
            SrcDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForRead)
        Dim SrcBTR As BlockTableRecord = _
            SrcTrans.GetObject(SrcBT(BlockTableRecord.ModelSpace), OpenMode.ForRead)

        ' Open Current Drawing BlockTable and "ModelSpace" BlockTableRecord ForWrite
        Dim myBT As DatabaseServices.BlockTable = _
            myDB.BlockTableId.GetObject(DatabaseServices.OpenMode.ForWrite)
        Dim myBTR As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

        Dim myObjs As New DatabaseServices.ObjectIdCollection ' Colection that Stores the Entities ID

        ' Loop entities in the Source Drawing
        For Each SrcEntId As ObjectId In SrcBTR
            Dim SrcEnt As Entity = SrcTrans.GetObject(SrcEntId, OpenMode.ForRead)
            ' Check if the entity is in the current analized source layer
            If SrcEnt.Layer = LayerName Then
                ' If ntity is a hatch get associativ
                If SrcEnt.GetType.Name = "Hatch" Then
                    Dim myHatch As DatabaseServices.Hatch = DirectCast(SrcEnt, Hatch)
                    Dim myHatchIds As DatabaseServices.ObjectIdCollection = myHatch.GetAssociatedObjectIds
                    For i As Integer = 0 To myHatchIds.Count - 1
                        myObjs.Add(myHatchIds.Item(i))
                    Next
                End If
                ' Add the source entity ObjectId to the ObjectIDCollection to clone
                myObjs.Add(SrcEnt.ObjectId)
            End If
        Next ' End of Loop entities in the Source Drawing

        ' WblockClone the Source Entity
        Dim myMap As New DatabaseServices.IdMapping
        myDB.WblockCloneObjects(myObjs, myBTR.ObjectId, myMap, _
            DatabaseServices.DuplicateRecordCloning.Replace, False)

        ' Commit, Close and Dispose Transactions
        myTrans.Commit() : myTrans.Dispose() : myTransMan.Dispose()
        SrcTrans.Dispose() : SrcTransMan.Dispose() : SrcDB.Dispose()
    End Sub           ' Imports a Layer with all the Entities

I don't need it, but if I have a little time I'll try to implent the same thing in reverse, coming soon: WblockLayerOUT
"A clever person solves a problem. A wise person avoids it." - Albert Einstein

Bryco

  • Water Moccasin
  • Posts: 1850
Re: WblockCloneobjects Problem
« Reply #13 on: March 21, 2008, 05:57:29 AM »
Looking good Rene.