Parameters of the WblockCloneObjects Method

Parameters of the WblockCloneObjects Method

adam_luER5XJ
Contributor Contributor
313 Views
0 Replies
Message 1 of 1

Parameters of the WblockCloneObjects Method

adam_luER5XJ
Contributor
Contributor

First of all, thank you for taking the time to read my questions.

I'm currently using Database.WblockCloneObjects to copy objects from a source DWG file to a destination DWG file. I would like to know what aspects are affected by the cloning parameter and what the outcome will be after its effect.

According to the AutoCAD documentation: "The cloning value determines what happens if symbols or dictionary entries are cloned, and a duplicate is found to already exist in the destination database. Cloning must keep the same setting in multiple calls and can only be one of the following: Ignore, Replace, MangleName, UnmangleName."

Although the documentation explains the meaning of each parameter, I'm still having trouble understanding the usage scenarios for each of them.

 

  1. Will objects like Line, Text, Block Reference, Polyline, etc., that I see in AutoCAD be affected?
    For example, if I choose Ignore, could some objects from the source be skipped and not copied to the destination, resulting in missing parts of the source in the destination, such as missing text or lines? Or could it happen that if the destination and source have resources with the same name, like blocks or images, but with different content, the copy process might ignore the source's content and display the existing block or image from the destination instead?

  2. What items are included in symbols or dictionary entries?
    I tested copying 28 objects, and when I chose Replace or MangleName, the IdMapping contained over 900 pairs, whereas choosing Ignore resulted in only 63 pairs. I also noticed that text fonts are included, which I discovered by selecting MangleName, resulting in fonts being renamed following a specific naming rule.
    If the items included are extensive, could you provide some general guidelines on which classes contain these items, or does it actually include all settings?

  3. Regarding Ignore, Replace, MangleName, if I simply want to copy accurately and straightforwardly, should I always choose Ignore?

  4. How should I decide which parameter to use, or under what circumstances should I use each parameter? What is the most commonly used parameter based on your experience?

  5. After executing WblockCloneObjects, is there anything that needs to be handled or configured manually?
    I'm asking because I have previously used the Entity.Clone() method to copy objects, but the font information of the copied objects was lost, and it seemed to require some additional processing.

Thank you.

 

Just to avoid the possibility that the issue is due to incorrect usage on my part, here's my code:

 

 

[CommandMethod("CopyFromBToA")]
public void CopyFromBToA()
{
    string bDwgPath = @"D:\testAutoCAD\Test.dwg";
    Document aDoc = Application.DocumentManager.MdiActiveDocument;
    Editor ed = aDoc.Editor;
    Database bDb = new Database(false, true);

    try
    {
        bDb.ReadDwgFile(bDwgPath, FileOpenMode.OpenForReadAndWriteNoShare, true, null);

        using (Transaction tr = bDb.TransactionManager.StartTransaction())
        {
            BlockTable bBt = tr.GetObject(bDb.BlockTableId, OpenMode.ForRead) as BlockTable;
            BlockTableRecord bBtr = tr.GetObject(bBt[BlockTableRecord.ModelSpace], OpenMode.ForRead) as BlockTableRecord;

            ObjectIdCollection idsToCopy = new ObjectIdCollection();
            foreach (ObjectId id in bBtr)
            {
                idsToCopy.Add(id);
            }
            tr.Commit();

            Database aDb = aDoc.Database;
            IdMapping idMap = new IdMapping();
            bDb.WblockCloneObjects(idsToCopy, aDb.CurrentSpaceId, idMap, DuplicateRecordCloning.Ignore, false);

            // Do other process

            ed.Regen();
        }
    }
    catch (Autodesk.AutoCAD.Runtime.Exception ex)
    {
        ed.WriteMessage($"\nError: {ex.Message}");
    }
    finally
    {
        bDb.Dispose();
    }
}

 

 

 

0 Likes
314 Views
0 Replies
Replies (0)