在 DWG 中插入 DXF/DWG 图纸
Contents
[
Hide
]如何在 DWG 中插入 DXF/DWG 图纸
问题: 如何在 DWG 中插入 DXF/DWG 图纸。
提示: 要做到这一点,首先创建一个具有所需值的 CadInsertObject,然后获取 CadBlockDictionary 中的所有块,创建一个新的 CadBlockEntity 块并将其添加到 CadBlockDictionary,向图纸的 BlockEntities 添加一个 CadBlockDictionary,为数组添加一个 CadInsertObject 到图形实体,按引用创建一个 CadBlockTableObject,然后将一个块添加到图纸中。
示例:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CadInsertObject newInsert = new CadInsertObject(); | |
newInsert.Name = "foreground"; | |
newInsert.ObjectHandle = newObjectID; | |
newInsert.LayerName = "0"; | |
newInsert.InsertionPoint.X = 200; | |
newInsert.InsertionPoint.Y = -1300; | |
CadBlockDictionary allBlocks = cadImage.BlockEntities; | |
CadBlockEntity newBlock = new CadBlockEntity(); | |
newBlock.XRefPathName.Value = "foreground.dwg"; | |
allBlocks.Add(newInsert.Name, newBlock); | |
cadImage.BlockEntities = allBlocks; | |
List entities = new List(cadImage.Entities); | |
entities.Add(newInsert); | |
cadImage.Entities = entities.ToArray(); | |
CadBlockTableObject blockTableObjectReference = null; | |
CadBlockEntity cadBlockEntity = null; | |
foreach (CadBlockTableObject tableObject in cadImage.BlocksTables) | |
{ | |
if (string.Equals(tableObject.HardPointerToLayout.Value, cadImage.Layouts["Model"].ObjectHandle)) | |
{ | |
blockTableObjectReference = tableObject; | |
break; | |
} | |
} | |
if (blockTableObjectReference != null && cadImage.BlockEntities.ContainsKey(blockTableObjectReference.BlockName)) | |
{ | |
cadBlockEntity = cadImage.BlockEntities[blockTableObjectReference.BlockName]; | |
} | |
List blockEntities = new List(cadBlockEntity.Entities); | |
blockEntities.Add(newInsert); | |
cadBlockEntity.Entities = blockEntities.ToArray(); | |
cadImage.Save(...) |