Understanding Dynamic Block Copy for IJCAD 2021 PRO

Asked 1 years ago, Updated 1 years ago, 474 views

I have created a customized command for IJCAD 2021 PRO in C#.
The application currently under development is considering copying a dynamic block drawing to another drawing.
However, if you actually copy it in the program, you will see customized information such as visibility in the dynamic block
It will be lost and become a normal block.
I used the WblockCloneObjects method for the copy process.
When I switched to the DeepCloneObjects method, the figure disappeared in the drawing and it didn't work out as expected.
Could you tell me how to copy custom information to another drawing while maintaining it?

public static void Main()
    {
        string filePath=@"C:\sample.dwg"; // Dynamic Block File

        Document document = Application.DocumentManager.MdiActiveDocument;
        using(Transaction transaction= document.Database.TransactionManager.StartTransaction())
        using(var blockTable=transaction.GetObject( document.Database.BlockTableId, OpenMode.ForRead) as BlockTable)
        using (var blockTableRecord=transaction.GetObject( document.Database.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord)
        using(var symbolBlock=new BlockTableRecord())
        using(var symbolDwgDatabase=newDatabase(false, true))
        {
            symbolBlock.Name = "testName";
            blockTable.UpgradeOpen();
            ObjectId symbolBlockId=blockTable.Add(symbolBlock);
            transaction.AddNewlyCreatedDBObject(symbolBlock, true);

            symbolDwgDatabase.ReadDwgFile(filePath, FileOpenMode.OpenForReadAndAllShare, false, string.Empty);
            symbolDwgDatabase.CloseInput(true);
            using(Transaction symbolDwgTransaction=symbolDwgDatabase.TransactionManager.StartTransaction())
            using(var symbolDwgBlockTable=symbolDwgTransaction.GetObject(symbolDwgDatabase.BlockTableId, OpenMode.ForRead) as BlockTable)
            using(var symbolDwgBlock=symbolDwgTransaction.GetObject(symbolDwgBlockTable["sampleBlock", OpenMode.ForRead) as BlockTableRecord)
            {
                var symbolDwgIds = new ObjectIdCollection();
                foreach (var objectId in symbolDwgBlock)
                {
                    symbolDwgIds.Add(objectId);
                }
                using(varicMap=newIdMapping())
                {
                    // DeepCloneObjects Does Not Reflect on Drawings
                    // symbolDwgDatabase.DeepCloneObjects (symbolDwgIds, symbolBlockId, icMap, false);
                    symbolDwgDatabase.WblockCloneObjects(symbolDwgIds, symbolBlockId,icMap, DuplicateRecordCloning.Replace, false);
                }
                symbolDwgTransaction.Commit();
            }

            using(var blockReference=new BlockReference(Point3d.Origin, symbolBlockId)
            {
                blockReference.UpgradeOpen();
                blockReference.Layer="0";
                blockTableRecord.AppendEntity (blockReference);
                transaction.AddNewlyCreatedDBObject(blockReference, true);
            }
            transaction.Commit();
        }
    }

c# .net ijcad

2022-09-30 21:59

1 Answers


Keep custom information in separate drawings for dynamic blocks
Could you tell me how to copy it?

If you want to copy a drawing to another drawing as a block, click
The entire drawing is defined as a single block, so
Custom information is maintained by dynamic blocks of components that the block refers to.

Therefore, after inserting the block of the copied drawing, either break it down with EXPLODE or

Each dynamic block defined in the drawing Each must be copied to a destination drawing.

When I switched to DeepCloneObjects method,
The figure disappeared in the drawing, so it didn't work out as expected.

The Database.DeepCloneObjects() method is the
API for deep clones in the same drawing database.
Some methods of copying blocks between different drawings include:
·Copy objects specified between drawings using Database.WblockCloneObjects() method
·Write the object specified by the Database.Wblock() method into a separate drawing and
 Insert using the Database.Insert() method


2022-09-30 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.