DXF/DWG-Zeichnung in DWG einfügen
Wie man eine DXF/DWG-Zeichnung in eine DWG einfügt
Problem: Wie man eine DXF/DWG-Zeichnung in eine DWG einfügt.
Tipps: Um dies zu tun, erstellen Sie zuerst ein CadInsertObject mit den erforderlichen Werten, dann rufen Sie alle Blöcke in einem CadBlockDictionary ab, erstellen Sie einen neuen CadBlockEntity-Block und fügen Sie ihn dem CadBlockDictionary hinzu, fügen Sie ein CadBlockDictionary zu den BlockEntities der Zeichnung hinzu, fügen Sie ein CadInsertObject zur Zeichnungseinheit für das Array hinzu, erstellen Sie ein CadBlockTableObject durch Referenz und fügen Sie dann einen Block zur Zeichnung hinzu.
Beispiel:
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(...) |