Add to scene as single object

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);

// 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(model1); // 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; 
    // create a new block and add to it the entities resulting from file reading
    blockName = "fileBlock";
    var block = new Block(blockName){Units = readFile.Units};

// create a new BlockReference, this constructor automatically scales the inserted content based on model units
var blockReference = new BlockReference(0, 0, 0, blockName, model1.RootBlock.Units, model1.Blocks, 0);


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.

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request



Please sign in to leave a comment.