RobotStudio event

Import CAD geometry not working

Hi everyone,

I have a question regarding the RobotStudio SDK. I am trying to import a CAD-file. I used the examplecode (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:
            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



Comments

  • dnilsson
    dnilsson
    edited November 2020
    You are right,
    the command is obsolete please use ABB.Robotics.RobotStudio.Selection.SelectedObjects instead.
    if (station.GraphicComponents.TryGetGraphicComponent(gc.Name, out gc))
       { 
          ABB.Robotics.RobotStudio.Selection.SelectedObjects.Add(gc);
       }

    Best regards,
    Daniel
  • Gustaffson
    edited November 2020
    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