Building a SmartComponent
SmartComponents created in Visual Studio can be built by executing the Build Solution command. However, there's an alternative method for those looking to automate and customize their build processes further.
The following example provides information on how a SmartComponent can be built using a single XML file. It also describes how a batch file can be used to simplify this process.
This can be useful when you want to:
- Automatically rebuild your libraries when, for example, their geometry-files have been updated.
- Add a custom build step, like signing an assembly, before building a SmartComponent with Code Behind.
- Build without the need for a Visual Studio project.
- Build a SmartComponent with Code Behind and the assembly has already been built at an earlier stage.
- Make a Post-build step in a Visual Studio project more manageable by factoring out logic to a separate batch file.
Automating the build using a batch file
Create a new SmartComponent project using the template in Visual Studio. Let's give it the default name "SmartComponent1".
With any text editor, create a batch file named build.bat in the same directory as the SmartComponent's .xml file. This batch file will contain the commands needed to build it.
The Library Compiler needs to be invoked from our batch script to process our XML file and yield a SmartComponent. To do so, add the following commands to the batch file:
"%ProgramFiles(X86)%\ABB\RobotStudio {version}\bin\LibraryCompiler.exe" SmartComponent1.xml
Important
Update the command with the correct information specific to your setup, including the RobotStudio version.
Execute the batch file from the command line or as an external command called from another part of your development tool-chain.
Building more than one SmartComponent from a single XML file
Create a new XML file in the project directory with the name BuildAll.xml and the following content:
<?xml version="1.0" encoding="utf-8"?> <LibraryCompiler xmlns="urn:abb-robotics-robotstudio-librarycompiler"> <!-- From one library XML file you can include other library XML files. They will be passed to the LibraryCompiler.exe.--> <Include source="SmartComponent1.xml"/> <Include source="SmartComponent1 - Copy.xml"/> </LibraryCompiler>
Make a copy of the file SmartComponent1.xml named SmartComponent1 - Copy.xml
Modify your build.bat to look like this:
"%ProgramFiles(X86)%\ABB\RobotStudio {version}\bin\LibraryCompiler.exe" BuildAll.xml
Important
Update the command with the correct information specific to your setup, including the RobotStudio version.
Tip
The Smart
Components walk-through contains both command line build and usage of batch Include element.
Example
Invoking the LibraryCompliler.exe from a batch file (build.bat).
"%ProgramFiles(X86)%\ABB\RobotStudio {version}\bin\LibraryCompiler.exe" SmartComponent1.xml
In one library file (BuildAll.xml), include two other library files.
<?xml version="1.0" encoding="utf-8"?>
<LibraryCompiler xmlns="urn:abb-robotics-robotstudio-librarycompiler">
<!-- From one library XML file you can include other library XML files.
They will be passed to the LibraryCompiler.exe.-->
<Include source="SmartComponent1/SmartComponent1.xml"/>
<Include source="SmartComponent2/SmartComponent2.xml"/>
</LibraryCompiler>
Compiling the code
Open a command prompt and set the current directory to the directory of the XML file. Invoke build.bat
.
You shall see an output similar to:
ABB Robotics LibraryCompiler 24.2.10789.0
Command line: "C:\Program Files (x86)\ABB\RobotStudio 2024\bin\LibraryCompiler.exe" SmartComponent1.xml
Compiling C:\Users\JohnDoe\source\Repos\SmartComponent1\SmartComponent1\SmartComponent1.xml
Added 'en' resources to SmartComponent1
Created C:\Users\JohnDoe\source\Repos\...\SmartComponent1.rslib
Embedding other assets
In many cases, it will be necessary to embed other files that are necessary for the correct execution of the smart component, such as external data files or even 3D models. In this case, the external assets can be embedded in the XML file in a similar way as the dynamic linked libraries.
Locate the necessary assets and put them in a directory that is easily accessed by the SmartComponent. Remember that the library compiler uses relative paths, the same directory as the component or a subdirectory are good choices.
In the SmartComponent's XML file, use the
<Asset source=""/>
XML element.<Assets> <Asset source="SmartComponent1.dll"/> <Asset source="model3d.dxf"/> <!-- 3D model --> <Asset source="data_points.txt"/> <!-- Data file --> </Assets>
Using assets from Code Behind
Once embedded, accessing these assets from your SmartComponent's code becomes a straightforward task. For instance, to retrieve and use the content of a text file (data_points.txt) embedded as an asset, you can utilize the following code:
if (component.Assets.TryGetAsset("data_points.txt", out var asset))
{
String text = Encoding.UTF8.GetString(asset.GetData());
}