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

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);
    model1.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, model1.RootBlock.Units, model1.Blocks, 0);

model1.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.

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

Comments

0 comments

Please sign in to leave a comment.