DXF の中に DXF/DWG 図面を挿入する
Contents
[
Hide
]DXF/DWG 図面を DXF の中に挿入する方法
問題: DXF の中に DXF/DWG 図面を挿入する方法。
ヒント: これを行うには、まず必要な値を持つ CadInsertObject を作成し、次に CadBlockDictionary 内のすべてのブロックを取得し、新しい CadBlockEntity ブロックを作成して CadBlockDictionary に追加し、CadBlockDictionary を図面の BlockEntities に追加し、配列用に図面のエンティティに CadInsertObject を追加します。
例:
This file contains 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
/ this part is not required but detects the first available free ID for handle as each object should have unique one | |
// assuming that we only make export, but not saving to dxf/dwg, you may assign any unique value | |
string newObjectID = "FFFFFF"; | |
if (cadImage.Header.HeaderProperties.ContainsKey(CadHeaderAttribute.HANDSEED)) | |
{ | |
newObjectID = ((CadStringParameter)cadImage.Header.HeaderProperties[CadHeaderAttribute.HANDSEED][0]).Value; | |
int nextAvailableID = int.Parse(newObjectID, System.Globalization.NumberStyles.HexNumber) + 1; | |
((CadStringParameter)cadImage.Header.HeaderProperties[CadHeaderAttribute.HANDSEED][0]).Value = nextAvailableID.ToString("X"); | |
} | |
CadInsertObject newInsert = new CadInsertObject(); | |
newInsert.Name = "foreground"; | |
newInsert.SoftOwner.Value = cadImage.Layouts["Model"].BlockTableRecordHandle; | |
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(); | |
cadImage.Save(...) |