# Import CAD geometry not working

**URL:** <https://tech-community.robotics.abb.com/t/import-cad-geometry-not-working/9782>\
**Category:** Developer Tools\
**Tags:** visualstudio, geometry, robotstudio-sdk, sdk, import\
**Created:** [October 30, 2020, 12:51pm UTC](https://tech-community.robotics.abb.com/t/import-cad-geometry-not-working/9782 "2020-10-30T12:51:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustaffson](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@Gustaffson](https://tech-community.robotics.abb.com/u/Gustaffson)\
**Post date:** [October 30, 2020, 12:51pm UTC](https://tech-community.robotics.abb.com/t/import-cad-geometry-not-working/9782/1 "2020-10-30T12:51:33Z")

</div>

Hi everyone,

I have a question regarding the RobotStudio SDK. I am trying to import a CAD-file. I used the examplecode ([Importing CAD file](https://developercenter.robotstudio.com/api/robotstudio/articles/How-To/Geometry/ImportCADFilesExample.html)) adjusted for my folders etc.

One part in the code is obsolete according to VisualStudio. This is the part I am talking about:

```auto
            if (station.GraphicComponents.TryGetGraphicComponent(gc.Name, out gc))
            {
               station.Selection.Add(gc);
            }

```

The “station.Selection.Add(gc)” part is obsolete.

I can’t find the code to replace this and if I comment it out and I open the rslib created by the build nothing apears.

Does anyone have an example code that works for me, or guide me in the right direction.

With Kind regards,  
Nick

---

<div class="post-metadata">

**Author:** ![dnilsson](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/dnilsson/32/795_2.png) [@dnilsson](https://tech-community.robotics.abb.com/u/dnilsson)\
**Post date:** [November 2, 2020, 2:10pm UTC](https://tech-community.robotics.abb.com/t/import-cad-geometry-not-working/9782/2 "2020-11-02T14:10:44Z")

</div>

You are right,  
the command is obsolete please use ABB.Robotics.RobotStudio.Selection.SelectedObjects instead.

```auto
if (station.GraphicComponents.TryGetGraphicComponent(gc.Name, out gc))
   { 
      ABB.Robotics.RobotStudio.Selection.SelectedObjects.Add(gc);
   }

```

Best regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![Gustaffson](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@Gustaffson](https://tech-community.robotics.abb.com/u/Gustaffson)\
**Post date:** [November 9, 2020, 12:23pm UTC](https://tech-community.robotics.abb.com/t/import-cad-geometry-not-working/9782/3 "2020-11-09T12:23:13Z")

</div>

Hi Daniel,

Your sugestion works however the imported model still does not apear when I build the solution and open the rslib file that is generated. Is there something that I’m missing? When I disconect the smartcomponent from the libary in RS and edit the component, there is no import stated.  
This is the code added to the CodeBehind.cs:

private static void ImportCADFiles()  
{

Project.UndoContext.BeginUndoStep(“Import CAD Files”);  
try  
{  
Station station = Station.ActiveStation;

// The file to be loaded.  
// NOTE: Be sure to change this to an existing file name!  
String fileName = @“TestModel.step”; **(TestModel.step is written with quotation marks befor and after but they don’t show up here)**

// Check if the file exists.  
GraphicComponent gc = null;  
if (File.Exists(fileName))  
{  
// Load the CAD file.  
gc = Part.Load(fileName);

// Set the name of the GraphicComponent to the file name.  
gc.Name = Path.GetFileNameWithoutExtension(fileName);

// Add the GraphicComponent to the station.  
station.GraphicComponents.Add(gc);

// Select the GraphicComponent.  
if (station.GraphicComponents.TryGetGraphicComponent(gc.Name, out gc))  
{  
ABB.Robotics.RobotStudio.Selection.SelectedObjects.Add(gc);  
Logger.AddMessage(new LogMessage(“Body selected”));  
}  
}  
else  
// If file name does not exists, print a warning message.  
Logger.AddMessage(new LogMessage(“Could not load '” + fileName + “'!”));  
}  
catch  
{  
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);  
throw;  
}  
finally  
{  
Project.UndoContext.EndUndoStep();  
}

Is there something I need to add somewhere else in order to actually import the file in RS?

With kind regards,  
Nick
