The following code is a sample of the main steps to insert the contents of a file inside a Block and create a BlockReference that refers to it.
ReadSTEP readFile = new ReadSTEP(fileName);
readFile.DoWork();
// Merge the master collections loaded from the file with the Environment ones
// In case of name conflict, these utility methods preserve the existing items
readFile.FillAllCollectionsData(design1); // available from Eyeshot 2021, on previous versions use FillLayers, FillBlocks, etc..
string blockName;
if (!string.IsNullOrEmpty(readFile.Blocks.RootBlockName))
{
// use the root block if it exist
blockName = readFile.Blocks.RootBlockName;
}
else
{
// create a new block and add to it the entities resulting from file reading
blockName = "fileBlock";
var block = new Block(blockName) { Units = readFile.Units };
block.Entities.AddRange(readFile.Entities);
design1.Blocks.Add(block);
}
// create a new BlockReference, this constructor automatically scales the inserted content based on model units
var blockReference = new BlockReference(0, 0, 0, blockName, design1.RootBlock.Units, design1.Blocks, 0);
design1.Entities.Add(blockReference);
This is just an example, the code can be customized based on the file type and contents, if it supports root block and units, and based on how you want to handle name conflicts on collections items.
Comments
Please provide example code to read IGES file in millimeters.
Please sign in to leave a comment.