Loading CAD files as ISimNode children fails

I am trying to load multiple CAD files and group them, making it easier to transforming them together and easily find all subparts belonging to an assembly. My first idead was creating an empty ISimComponents and load the CAD files as their children like this:

ISimComponent container = app.World.CreateComponent("DefaultCADContainer");
bool worked = IoC.Get<ICADReader>().Import(location, settings, container.RootNode, cancellationToken);

While the debugger shows container.isValid and container.RootNode.isValid to be true, the importing still fails. Using app.World instead of a ISimNode imports the files just fine. Are there more requirements for the simcomponent to be used as a parent node like this?

The other thing I found are IGroups, but it appears that they can’t be used to transform/… all components together.

Thanks in advance!

Edit: Using app.World.RootNode also fails, so it seems to be a problem with only the overload function
bool Import(Uri path, CADSettings settings, ISimNode node, CADCancellationToken cancellationToken);

            //Component in 3D world
            ISimNode comp = _app.World.FindComponent("NewComponent") as ISimNode;
            
            //Your CAD path
            Uri cad_path = IoC.Get<IUrlHelper>().LocalPathToUrl(@"C:\\path\\to\\cad\\yourcad.STEP");
            
            //Use this to adjust the CAD import settings
            CADSettings cad_settings = new CADSettings();
            CADCancellationToken cad_cancellationtoken = new CADCancellationToken();
            
            bool is_import_success = IoC.Get<ICADReader>().Import(cad_path, cad_settings, comp, cad_cancellationtoken);
            if (is_import_success) {
                //Grouping is handled in the python command. Command name is GroupRootFeatures. 
                IPythonCommand pythonCommand = _app.CommandManager.FindPythonCommand("GroupRootFeatures");
                pythonCommand.Execute();
            }

Hi Popeye,

Thank you for the response! I finally got around to try the code out, but the problem with loading files this way persist. I turned your code snipped into a button action that checks if a Component with a fitting name exists and then either loads the cad file into _app.World or to the found component:

   public override void Execute()
   {
       //Component in 3D world
       ISimNode comp = _app.World.FindComponent("NewComponent") as ISimNode;

       //Your CAD path
       Uri cad_path = IoC.Get<IUrlHelper>().LocalPathToUrl(@"C:\Users\freu\Desktop\test.stp");

       //Use this to adjust the CAD import settings
       CADSettings cad_settings = new CADSettings()
       {
           NodeStructureTreeMode = NodeTreeStructure.Layout,
           TessellationLevelOfDetail = TessellationDetail.Medium,
           ImportMaterials = true,
           FeatureTreeMode = FeatureTreeStructure.Full,
           UpAxis = UpAxis.Z,
           DefaultUnit = DefaultUnit.Default,
       };

       CADCancellationToken cad_cancellationtoken = new CADCancellationToken();

       if (comp == null)
       {
           bool is_import_success = IoC.Get<ICADReader>().Import(cad_path, cad_settings, _app.World, cad_cancellationtoken);

       }
       else
       {
           bool is_import_success = IoC.Get<ICADReader>().Import(cad_path, cad_settings, comp, cad_cancellationtoken);
           if (is_import_success && comp != null)
           {
               //Grouping is handled in the python command. Command name is GroupRootFeatures. 
               IPythonCommand pythonCommand = _app.CommandManager.FindPythonCommand("GroupRootFeatures");
               pythonCommand.Execute();
           }
       }
   }

While loading without a match works fine, the moment I rename a component to “NewComponent” the import fails with “An exception occurred while reading the file.” in the Output window.
Are there some requirements for NewComponent that might not be fulfilled for my test case?