# Exporting the data from an array

**URL:** <https://tech-community.robotics.abb.com/t/exporting-the-data-from-an-array/11791>\
**Category:** Tutorials\
**Tags:** array-values, flexpendant, tcp, data, export\
**Created:** [February 13, 2025, 10:04am UTC](https://tech-community.robotics.abb.com/t/exporting-the-data-from-an-array/11791 "2025-02-13T10:04:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nihm20](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@nihm20](https://tech-community.robotics.abb.com/u/nihm20)\
**Post date:** [February 13, 2025, 10:04am UTC](https://tech-community.robotics.abb.com/t/exporting-the-data-from-an-array/11791/1 "2025-02-13T10:04:56Z")

</div>

Hello, I’m new to robot studio and the programming language rapid.

I have created a distance measurement for my robot’s tcp and have put the data in an array. The only way I know to access it is from the flexpendant.

But is there any way to export the data in my array? I would like to analyse it in a different program.

---

<div class="post-metadata">

**Author:** ![mandolas](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/mandolas/32/2496_2.png) [@mandolas](https://tech-community.robotics.abb.com/u/mandolas)\
**Post date:** [February 13, 2025, 10:51am UTC](https://tech-community.robotics.abb.com/t/exporting-the-data-from-an-array/11791/2 "2025-02-13T10:51:02Z")

</div>

Hi …  
You can export to a file.  
Look in the help for the Open function.  
With it you can create, write, add content…  
This is a good start.  
Here is a small example:

```auto
    ! FUNCTION TO RETURN THE PATH OF THE NEWLY CREATED FILE ##################################################### 1.0 ####
    ! The FileNew function creates a new file with a specific name in the specified directory or in the default directory, depending on the conditions. If the file already exists,
    ! the function does nothing and returns the complete file path. If file access errors occur, they are handled in the error handling block.
    ! This function is designed to create a new file in a specified directory or in the default directory (HOME:), if the file does not exist.
    ! The variables 'fileIodevL' (file handle), 'pathL' (directory path), and 'isDirectoryOrFileL' (checks whether it is a directory or file) are used for
    ! data manipulation.
    ! The function checks if the parameter 'directoryPathP' (directory path) is provided. If provided, it checks if it is an existing directory using the
    ! 'IsFile' function with the 'Directory' option. If it does not exist, it creates the directory and constructs the directory path (if provided) with a slash ("/") in the variable 'pathL'.
    ! It also checks if the file with the name 'fileNameP.conf' exists in the specified directory (pathL). If it does not exist, it creates it using the file handle 'Open'
    ! with the 'Append' option. After creating the file, it is immediately closed with 'Close' so that it can be manipulated by another function.
    ! The 'typeP' corresponds to the type of file to be saved. By default, saved files are of type '.data'.
    ! If the file was successfully created, the function returns the complete file path (pathL+fileNameP+typeL). Otherwise, it returns an empty string.
    ! There is an error handling block that specifically deals with the error 'ERR_FILEACC'. This error may occur if there is a file access issue. If this
    ! error occurs, the function will attempt to proceed to the next instruction using the 'TRYNEXT' command. This error usually occurs when attempting to open a non-existent file.
    !
    ! PARAMETERS:
    ! \string directoryPathP: If provided and it does not exist, creates the directory; otherwise, it just sets the path to it. If not provided, defaults to 'HOME:\'.
    ! string fileNameP: Name of the file to be saved.
    ! \string typeP: If provided, this type is used to save the file. By default, it saves as '.data'.
    !
    ! RETURN:
    ! Returns the file path.
    !
    ! USAGE EXAMPLE:
    ! MODULE ModPRG()
    ! VAR string directoryPathP;
    ! VAR string fileNameP;
    ! VAR string typeP;
    !
    ! PROC main()
    ! directoryPathP:="TEMP"
    ! fileNameP:="Parameter";
    ! typeP:=".sys";
    !
    ! TPErase;
    ! TPWrite FileNew(directoryPathP:=directoryPathP,fileNameP\typeP:=typeP); ! >> ~ "TEMP/Parameters.sys"
    ! TPWrite FileNew(fileNameP\typeP:=typeP); ! >> ~ "HOME/Parameters.sys"
    ! TPWrite FileNew(fileNameP); ! >> ~ "HOME/Parameters.data"
    ! ENDPROC
    ! ENDMODULE
    !
    ! LIMITATION:
    ! The input parameters "\string directoryPathP", "string fileNameP" and "\string typeP" are limited to 80 characters.
    !
    FUNC string FileNew(\string directoryPathP,string fileNameP\string typeP)
        ! ## ATTRIBUTES ##############################################################################
        VAR iodev fileIodevL;

        VAR string pathL:="";
        VAR string typeL:=".data";
        ! ## ATTRIBUTES ##############################################################################

        ! Checks for the existence of the DIRECTORY; if it does not exist, creates one in HOME:\ ...
        IF Present(directoryPathP) THEN
            MakeDir directoryPathP;

            pathL:=directoryPathP+"/";
        ENDIF

        IF Present(typeP) typeL:=typeP;

        ! Create file ...
        Open pathL\File:=fileNameP+typeL,fileIodevL\Append;

        ! ###### Writes your file ...
        ! If the file is open then insert a line at the end of the file ...
        Write fileIodevL,CDate()+"; "+CTime()+"; FILE;";
        Write fileIodevL,"----------; --------; ------------------;";
        Write fileIodevL,"... TEXT ...";
        Write fileIodevL," ";

        ! Close file
        Close fileIodevL;

        ! If the file was created, returns the path; otherwise, returns empty
        IF IsFile(pathL+fileNameP+typeL\RegFile) THEN
            RETURN pathL+fileNameP+typeL;
        ELSE
            RETURN "";
        ENDIF
    ERROR
        ! #############################################################################################
        ! POSSIBLE ERROR HANDLING
        ! #############################################################################################

        ! If an error is encountered, proceed to the next instruction ...
        IF ERRNO=ERR_FILEACC THEN
            TRYNEXT;
        ENDIF
    ENDFUNC

```

Good Work.

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [February 13, 2025, 12:47pm UTC](https://tech-community.robotics.abb.com/t/exporting-the-data-from-an-array/11791/3 "2025-02-13T12:47:56Z")

</div>

You want to analyze it in a different rapid program?

---

<div class="post-metadata">

**Author:** ![nihm20](https://avatars.discourse-cdn.com/v4/letter/n/3be4f8/32.png) [@nihm20](https://tech-community.robotics.abb.com/u/nihm20)\
**Post date:** [February 20, 2025, 1:45pm UTC](https://tech-community.robotics.abb.com/t/exporting-the-data-from-an-array/11791/4 "2025-02-20T13:45:40Z")

</div>

No I want to analyze the distance measurement in matlab
